Chromium Code Reviews| Index: src/core/SkShadowShader.cpp |
| diff --git a/src/core/SkShadowShader.cpp b/src/core/SkShadowShader.cpp |
| index 6ca82fb65d8431509e635324af81aa1e5167055f..f4c566b80bf52fc8d6c5f08635cded74fbff8cab 100644 |
| --- a/src/core/SkShadowShader.cpp |
| +++ b/src/core/SkShadowShader.cpp |
| @@ -729,6 +729,7 @@ void SkShadowShaderImpl::ShadowShaderContext::shadeSpan(int x, int y, |
| int shY = SkClampMax(y + yOffset, light.getShadowMap()->height() - 1); |
| int shDepth = 0; |
| + int shDepthsq = 0; |
| // pixmaps that point to things have nonzero heights |
| if (fShadowMapPixels[l].height() > 0) { |
| @@ -736,17 +737,32 @@ void SkShadowShaderImpl::ShadowShaderContext::shadeSpan(int x, int y, |
| SkColor shColor(pix); |
| shDepth = SkColorGetB(shColor); |
| + shDepthsq = SkColorGetG(shColor) * 256; |
| } else { |
| // Make lights w/o a shadow map receive the full light contribution |
| shDepth = pvDepth; |
|
robertphillips
2016/08/30 16:48:37
It seems like you don't have to compute the square
vjiaoblack
2016/08/30 17:01:26
Ah right. I guess it'll fail the next if case
|
| + shDepthsq = shDepth * shDepth; |
| } |
|
robertphillips
2016/08/30 16:48:37
I expect a "if (blurAlgorithm == SkShadowParams::k
vjiaoblack
2016/08/30 17:01:26
That doesn't need to be here.
If the shadow map i
robertphillips
2016/08/30 17:04:39
The variance path is far more expensive than the n
|
| - if (pvDepth >= shDepth) { |
| - // assume object normals are pointing straight up |
| - totalLight.fX += light.dir().fZ * light.color().fX; |
| - totalLight.fY += light.dir().fZ * light.color().fY; |
| - totalLight.fZ += light.dir().fZ * light.color().fZ; |
| + SkScalar lightProb = 1.0f; |
| + if (pvDepth < shDepth) { |
| + int variance = SkTMax(shDepthsq - shDepth * shDepth, |
| + lightShader.fShadowParams.fMinVariance); |
| + int d = pvDepth - shDepth; |
| + |
| + lightProb = (SkScalar) variance / ((SkScalar) (variance + d * d)); |
| + |
|
robertphillips
2016/08/30 16:48:37
This formula is a bit hard to parse with the given
vjiaoblack
2016/08/30 17:01:26
Done.
|
| + lightProb = SkMaxScalar((lightProb - |
| + lightShader.fShadowParams.fBiasingConstant) / |
| + (1.0f - |
| + lightShader.fShadowParams.fBiasingConstant), |
| + 0.0f); |
| } |
| + |
| + // assume object normals are pointing straight up |
| + totalLight.fX += light.dir().fZ * light.color().fX * lightProb; |
| + totalLight.fY += light.dir().fZ * light.color().fY * lightProb; |
| + totalLight.fZ += light.dir().fZ * light.color().fZ * lightProb; |
| } else { |
| totalLight += light.color(); |
| } |