aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar vjiaoblack <vjiaoblack@google.com>2016-09-09 11:58:19 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-09 11:58:19 -0700
commit95315f0d6f77aef3700f604346f4e2558390e6f8 (patch)
treea5fe84b19881de369ba56ccf6296d2a24ec92487 /src/core
parent57f744e3030fec4d1a2b3e9119011904b149a4da (diff)
made point lights linear attenuation; also fixed point light depth bug
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkRadialShadowMapShader.cpp4
-rw-r--r--src/core/SkShadowShader.cpp13
2 files changed, 10 insertions, 7 deletions
diff --git a/src/core/SkRadialShadowMapShader.cpp b/src/core/SkRadialShadowMapShader.cpp
index 24b54a5e2b..29773a63b5 100644
--- a/src/core/SkRadialShadowMapShader.cpp
+++ b/src/core/SkRadialShadowMapShader.cpp
@@ -142,7 +142,9 @@ public:
// Modify the input texture coordinates to index into our 1D output
fragBuilder->codeAppend("float distHere;");
- fragBuilder->codeAppend("float closestDistHere = 0;");
+
+ // we use a max shadow distance of 2 times the max of width/height
+ fragBuilder->codeAppend("float closestDistHere = 2;");
fragBuilder->codeAppend("vec2 coords = vMatrixCoord_0_0_Stage0;");
fragBuilder->codeAppend("coords.y = 0;");
fragBuilder->codeAppend("vec2 destCoords = vec2(0,0);");
diff --git a/src/core/SkShadowShader.cpp b/src/core/SkShadowShader.cpp
index 59152bfc37..c3ede8081e 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;