OLD | NEW |
1 /* | 1 /* |
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" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 // fuse all ambient lights into a single one | 158 // fuse all ambient lights into a single one |
159 fAmbientColor.set(0.0f, 0.0f, 0.0f); | 159 fAmbientColor.set(0.0f, 0.0f, 0.0f); |
160 for (int i = 0; i < lights->numLights(); ++i) { | 160 for (int i = 0; i < lights->numLights(); ++i) { |
161 if (SkLights::Light::kAmbient_LightType == lights->light(i).type())
{ | 161 if (SkLights::Light::kAmbient_LightType == lights->light(i).type())
{ |
162 fAmbientColor += lights->light(i).color(); | 162 fAmbientColor += lights->light(i).color(); |
163 } else { | 163 } else { |
164 // TODO: handle more than one of these | 164 // TODO: handle more than one of these |
165 fLightColor = lights->light(i).color(); | 165 fLightColor = lights->light(i).color(); |
166 fLightDir = lights->light(i).dir(); | 166 fLightDir = lights->light(i).dir(); |
| 167 // get the handle to the shadow map if there is one |
167 } | 168 } |
168 } | 169 } |
169 | 170 |
170 this->registerChildProcessor(std::move(normalFP)); | 171 this->registerChildProcessor(std::move(normalFP)); |
171 this->initClassID<LightingFP>(); | 172 this->initClassID<LightingFP>(); |
172 } | 173 } |
173 | 174 |
174 class GLSLLightingFP : public GrGLSLFragmentProcessor { | 175 class GLSLLightingFP : public GrGLSLFragmentProcessor { |
175 public: | 176 public: |
176 GLSLLightingFP() { | 177 GLSLLightingFP() { |
(...skipping 26 matching lines...) Expand all Loading... |
203 fragBuilder->codeAppend("vec4 diffuseColor = "); | 204 fragBuilder->codeAppend("vec4 diffuseColor = "); |
204 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.f
TexSamplers[0], | 205 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, args.f
TexSamplers[0], |
205 args.fCoords[0].c_str(), | 206 args.fCoords[0].c_str(), |
206 args.fCoords[0].getType()); | 207 args.fCoords[0].getType()); |
207 fragBuilder->codeAppend(";"); | 208 fragBuilder->codeAppend(";"); |
208 | 209 |
209 SkString dstNormalName("dstNormal"); | 210 SkString dstNormalName("dstNormal"); |
210 this->emitChild(0, nullptr, &dstNormalName, args); | 211 this->emitChild(0, nullptr, &dstNormalName, args); |
211 | 212 |
212 fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_st
r()); | 213 fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_st
r()); |
| 214 |
| 215 // TODO: make this a loop and modulate the contribution from each li
ght |
| 216 // based on the shadow map |
213 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0,
1.0);", | 217 fragBuilder->codeAppendf("float NdotL = clamp(dot(normal, %s), 0.0,
1.0);", |
214 lightDirUniName); | 218 lightDirUniName); |
215 // diffuse light | 219 // diffuse light |
216 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;",
lightColorUniName); | 220 fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;",
lightColorUniName); |
217 // ambient light | 221 // ambient light |
218 fragBuilder->codeAppendf("result += %s;", ambientColorUniName); | 222 fragBuilder->codeAppendf("result += %s;", ambientColorUniName); |
219 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a
rgs.fOutputColor); | 223 fragBuilder->codeAppendf("%s = vec4(result.rgb, diffuseColor.a);", a
rgs.fOutputColor); |
220 } | 224 } |
221 | 225 |
222 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, | 226 static void GenKey(const GrProcessor& proc, const GrGLSLCaps&, |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 invNormRotation, diffLocalM, normLocalM, std::move(normalSource)); | 652 invNormRotation, diffLocalM, normLocalM, std::move(normalSource)); |
649 } | 653 } |
650 | 654 |
651 /////////////////////////////////////////////////////////////////////////////// | 655 /////////////////////////////////////////////////////////////////////////////// |
652 | 656 |
653 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) | 657 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingShader) |
654 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) | 658 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingShaderImpl) |
655 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 659 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
656 | 660 |
657 /////////////////////////////////////////////////////////////////////////////// | 661 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |