Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Side by Side Diff: src/core/SkLightingShader.cpp

Issue 2127233002: Added the framework for having canvas/recorder/picture record depth_set's. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
jvanverth1 2016/07/07 18:43:02 The changes in this file seem unrelated to the des
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapProcShader.h" 8 #include "SkBitmapProcShader.h"
9 #include "SkBitmapProcState.h" 9 #include "SkBitmapProcState.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
11 #include "SkEmptyShader.h" 11 #include "SkEmptyShader.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 // fuse all ambient lights into a single one 128 // fuse all ambient lights into a single one
129 fAmbientColor.set(0.0f, 0.0f, 0.0f); 129 fAmbientColor.set(0.0f, 0.0f, 0.0f);
130 for (int i = 0; i < lights->numLights(); ++i) { 130 for (int i = 0; i < lights->numLights(); ++i) {
131 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) { 131 if (SkLights::Light::kAmbient_LightType == lights->light(i).type()) {
132 fAmbientColor += lights->light(i).color(); 132 fAmbientColor += lights->light(i).color();
133 } else { 133 } else {
134 // TODO: handle more than one of these 134 // TODO: handle more than one of these
135 fLightColor = lights->light(i).color(); 135 fLightColor = lights->light(i).color();
136 fLightDir = lights->light(i).dir(); 136 fLightDir = lights->light(i).dir();
137 // get the handle to the shadow map if there is one
137 } 138 }
138 } 139 }
139 140
140 this->registerChildProcessor(std::move(normalFP)); 141 this->registerChildProcessor(std::move(normalFP));
141 this->initClassID<LightingFP>(); 142 this->initClassID<LightingFP>();
142 } 143 }
143 144
144 class GLSLLightingFP : public GrGLSLFragmentProcessor { 145 class GLSLLightingFP : public GrGLSLFragmentProcessor {
145 public: 146 public:
146 GLSLLightingFP() { 147 GLSLLightingFP() {
(...skipping 22 matching lines...) Expand all
169 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag , 170 fAmbientColorUni = uniformHandler->addUniform(kFragment_GrShaderFlag ,
170 kVec3f_GrSLType, kDefa ult_GrSLPrecision, 171 kVec3f_GrSLType, kDefa ult_GrSLPrecision,
171 "AmbientColor", &ambie ntColorUniName); 172 "AmbientColor", &ambie ntColorUniName);
172 173
173 fragBuilder->codeAppendf("vec4 diffuseColor = %s;", args.fInputColor ); 174 fragBuilder->codeAppendf("vec4 diffuseColor = %s;", args.fInputColor );
174 175
175 SkString dstNormalName("dstNormal"); 176 SkString dstNormalName("dstNormal");
176 this->emitChild(0, nullptr, &dstNormalName, args); 177 this->emitChild(0, nullptr, &dstNormalName, args);
177 178
178 fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_st r()); 179 fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_st r());
180
181 // TODO: make this a loop and modulate the contribution from each li ght
182 // based on the shadow map
179 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0, 1.0);", 183 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0, 1.0);",
180 lightDirUniName); 184 lightDirUniName);
181 // diffuse light 185 // diffuse light
182 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightColorUniName); 186 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightColorUniName);
183 // ambient light 187 // ambient light
184 fragBuilder->codeAppendf("result += %s;", ambientColorUniName); 188 fragBuilder->codeAppendf("result += %s;", ambientColorUniName);
185 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a rgs.fOutputColor); 189 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a rgs.fOutputColor);
186 } 190 }
187 191
188 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, 192 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 std::move(lights)); 505 std::move(lights));
502 } 506 }
503 507
504 /////////////////////////////////////////////////////////////////////////////// 508 ///////////////////////////////////////////////////////////////////////////////
505 509
506 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) 510 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader)
507 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) 511 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl)
508 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 512 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
509 513
510 /////////////////////////////////////////////////////////////////////////////// 514 ///////////////////////////////////////////////////////////////////////////////
OLDNEW
« src/core/SkCanvas.cpp ('K') | « src/core/SkCanvas.cpp ('k') | src/core/SkRecordDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698