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

Unified Diff: src/core/SkShadowShader.cpp

Issue 2297693002: made raster shadows variance shadows (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 4 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 | « no previous file | 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 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();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698