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

Unified Diff: src/core/SkShadowShader.cpp

Issue 2323383002: made point lights linear attenuation; also fixed point light depth bug (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/core/SkShadowShader.cpp
diff --git a/src/core/SkShadowShader.cpp b/src/core/SkShadowShader.cpp
index 59152bfc37061cab4cbb3a18cfd7d6e00bf63e52..15ac35e9771b9f117afacaaf07c90098221ca203 100644
--- a/src/core/SkShadowShader.cpp
+++ b/src/core/SkShadowShader.cpp
@@ -290,9 +290,8 @@ public:
if (shadowFP.fIsPointLight[i]) {
fragBuilder->codeAppendf("vec3 fragToLight%d = %s - worldCor;",
i, lightDirOrPosUniName[i]);
- fragBuilder->codeAppendf("float distsq%d = dot(fragToLight%d, "
- "fragToLight%d);",
- i, i, i);
+ fragBuilder->codeAppendf("float dist%d = length(fragToLight%d);",
+ i, i);
fragBuilder->codeAppendf("%s = vec2(-fragToLight%d) * povDepth.b;",
offset.c_str(), i);
fragBuilder->codeAppendf("fragToLight%d = normalize(fragToLight%d);",
@@ -383,7 +382,7 @@ public:
fragBuilder->codeAppendf("lightProbability = step(r, depth);");
- fragBuilder->codeAppendf("if (%s.b != 0 || depth == 0) {"
+ fragBuilder->codeAppendf("if (%s.b != 0 || depth == 2) {"
jvanverth1 2016/09/09 18:18:33 Again, why 2?
vjiaoblack 2016/09/09 18:24:36 Done.
"lightProbability = 1.0; }",
povDepth.c_str());
} else {
@@ -431,7 +430,7 @@ public:
if (shadowFP.isPointLight(i)) {
fragBuilder->codeAppendf("totalLightColor += max(fragToLight%d.z, 0) * %s /"
- "(1 + distsq%d) * lightProbability;",
+ "(1 + dist%d) * lightProbability;",
i, lightColorUniName[i], i);
} else {
fragBuilder->codeAppendf("totalLightColor += %s.z * %s * lightProbability;",
@@ -818,7 +817,7 @@ void SkShadowShaderImpl::ShadowShaderContext::shadeSpan(int x, int y,
SkScalar dist = fragToLight.length();
SkScalar normalizedZ = fragToLight.fZ / dist;
- SkScalar distAttenuation = light.intensity() / (1.0f + dist * dist);
+ SkScalar distAttenuation = light.intensity() / (1.0f + dist);
// assume object normals are pointing straight up
totalLight.fX += normalizedZ * light.color().fX * distAttenuation;
« src/core/SkRadialShadowMapShader.cpp ('K') | « src/core/SkRadialShadowMapShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698