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

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

Issue 2146073003: Creating framework for drawShadowedPicture (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Fixed 'const sk_sp<SkLights>', also fixed some crumbs from merging 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 /*
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 class SkLightingShaderImpl : public SkShader { 42 class SkLightingShaderImpl : public SkShader {
43 public: 43 public:
44 /** Create a new lighting shader that uses the provided normal map and 44 /** Create a new lighting shader that uses the provided normal map and
45 lights to light the diffuse bitmap. 45 lights to light the diffuse bitmap.
46 @param diffuseShader the shader that provides the diffuse colors 46 @param diffuseShader the shader that provides the diffuse colors
47 @param normalSource the source of normals for lighting computation 47 @param normalSource the source of normals for lighting computation
48 @param lights the lights applied to the geometry 48 @param lights the lights applied to the geometry
49 */ 49 */
50 SkLightingShaderImpl(sk_sp<SkShader> diffuseShader, 50 SkLightingShaderImpl(sk_sp<SkShader> diffuseShader,
51 sk_sp<SkNormalSource> normalSource, 51 sk_sp<SkNormalSource> normalSource,
52 const sk_sp<SkLights> lights) 52 sk_sp<SkLights> lights)
53 : fDiffuseShader(std::move(diffuseShader)) 53 : fDiffuseShader(std::move(diffuseShader))
54 , fNormalSource(std::move(normalSource)) 54 , fNormalSource(std::move(normalSource))
55 , fLights(std::move(lights)) {} 55 , fLights(std::move(lights)) {}
56 56
57 bool isOpaque() const override; 57 bool isOpaque() const override;
58 58
59 #if SK_SUPPORT_GPU 59 #if SK_SUPPORT_GPU
60 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*, 60 sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*,
61 const SkMatrix& viewM, 61 const SkMatrix& viewM,
62 const SkMatrix* localMatrix, 62 const SkMatrix* localMatrix,
(...skipping 64 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
jvanverth1 2016/07/14 17:27:09 Add a TODO: to this comment or remove it.
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

Powered by Google App Engine
This is Rietveld 408576698