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

Unified Diff: src/core/SkShadowShader.cpp

Issue 2297693002: made raster shadows variance shadows (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: made req changes 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..09d0bcaf5080c2822b3abd9dc4e7cb17bb1efaac 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,34 @@ 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;
}
- 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) {
+ if (lightShader.fShadowParams.fType ==
+ SkShadowParams::ShadowType::kVariance_ShadowType) {
+ int variance = SkMaxScalar(shDepthsq - shDepth * shDepth,
+ lightShader.fShadowParams.fMinVariance);
+ int d = pvDepth - shDepth;
+
+ lightProb = (SkScalar) variance / ((SkScalar) (variance + d * d));
+
+ SkScalar bias = lightShader.fShadowParams.fBiasingConstant;
+
+ lightProb = SkMaxScalar((lightProb - bias) / (1.0f - bias), 0.0f);
+ } else {
+ lightProb = 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