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

Unified Diff: src/core/SkShadowShader.cpp

Issue 2298603004: added point light attenuations to raster (Closed)
Patch Set: added i back to light direction calculation 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 09d0bcaf5080c2822b3abd9dc4e7cb17bb1efaac..b4835dabe7eae4873446da641f6ebd2701cf3df6 100644
--- a/src/core/SkShadowShader.cpp
+++ b/src/core/SkShadowShader.cpp
@@ -719,8 +719,9 @@ void SkShadowShaderImpl::ShadowShaderContext::shadeSpan(int x, int y,
for (int l = 0; l < lightShader.fLights->numLights(); ++l) {
const SkLights::Light& light = lightShader.fLights->light(l);
+ int pvDepth = SkColorGetB(povDepthColor); // depth stored in blue channel
+
if (light.type() == SkLights::Light::kDirectional_LightType) {
- int pvDepth = SkColorGetB(povDepthColor); // depth stored in blue channel
int xOffset = SkScalarRoundToInt(light.dir().fX * pvDepth);
int yOffset = SkScalarRoundToInt(light.dir().fY * pvDepth);
@@ -765,8 +766,26 @@ void SkShadowShaderImpl::ShadowShaderContext::shadeSpan(int x, int y,
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();
+ // right now we only expect directional and point light types.
+ SkASSERT(light.type() == SkLights::Light::kPoint_LightType);
+
+ int height = lightShader.fDiffuseHeight;
+
+ SkVector3 fragToLight = SkVector3::Make(light.pos().fX - x - i,
+ light.pos().fY - (height - y),
+ light.pos().fZ - pvDepth);
+
+ SkScalar dist = fragToLight.length();
+ SkScalar normalizedZ = fragToLight.fZ / dist;
+
+ SkScalar distAttenuation = light.intensity() / (1.0f + dist * dist);
+
+ // assume object normals are pointing straight up
+ totalLight.fX += normalizedZ * light.color().fX * distAttenuation;
+ totalLight.fY += normalizedZ * light.color().fY * distAttenuation;
+ totalLight.fZ += normalizedZ * light.color().fZ * distAttenuation;
}
}
« 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