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

Unified Diff: src/core/SkShadowShader.cpp

Issue 2323383002: made point lights linear attenuation; also fixed point light depth bug (Closed)
Patch Set: added comments! 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
« no previous file with comments | « src/core/SkRadialShadowMapShader.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkShadowShader.cpp
diff --git a/src/core/SkShadowShader.cpp b/src/core/SkShadowShader.cpp
index 59152bfc37061cab4cbb3a18cfd7d6e00bf63e52..c3ede8081ed3ae92d25cc084aaff5ab02d6d4b64 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,9 @@ public:
fragBuilder->codeAppendf("lightProbability = step(r, depth);");
- fragBuilder->codeAppendf("if (%s.b != 0 || depth == 0) {"
+ // 2 is the maximum depth. If this is reached, probably we have
+ // not intersected anything. So values after this should be unshadowed.
+ fragBuilder->codeAppendf("if (%s.b != 0 || depth == 2) {"
"lightProbability = 1.0; }",
povDepth.c_str());
} else {
@@ -431,7 +432,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 +819,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;
« no previous file with comments | « src/core/SkRadialShadowMapShader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698