aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkLightingShader.cpp
diff options
context:
space:
mode:
authorGravatar dvonbeck <dvonbeck@google.com>2016-08-02 14:46:34 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-02 14:46:34 -0700
commit9d65bb4795d14990daf08fba5a3de9404df4b913 (patch)
tree2061a0f91a10f0b17efdeacaf8c648aed9975c5c /src/core/SkLightingShader.cpp
parent38d909ec2875f79952de08f36adfaac5680d2c53 (diff)
Fixed ambient lighting calculations on SkLightingShader
Diffstat (limited to 'src/core/SkLightingShader.cpp')
-rw-r--r--src/core/SkLightingShader.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp
index b478ee7eca..e35ede3a17 100644
--- a/src/core/SkLightingShader.cpp
+++ b/src/core/SkLightingShader.cpp
@@ -180,9 +180,8 @@ public:
lightDirUniName);
// diffuse light
fragBuilder->codeAppendf("vec3 result = %s*diffuseColor.rgb*NdotL;", lightColorUniName);
- // ambient light (multiplied by input color's alpha because we're working in premul'd
- // space)
- fragBuilder->codeAppendf("result += diffuseColor.a * %s;", ambientColorUniName);
+ // ambient light
+ fragBuilder->codeAppendf("result += %s * diffuseColor.rgb;", ambientColorUniName);
// Clamping to alpha (equivalent to an unpremul'd clamp to 1.0)
fragBuilder->codeAppendf("%s = vec4(clamp(result.rgb, 0.0, diffuseColor.a), "
@@ -379,18 +378,18 @@ void SkLightingShaderImpl::LightingShaderContext::shadeSpan(int x, int y,
for (int l = 0; l < lightShader.fLights->numLights(); ++l) {
const SkLights::Light& light = lightShader.fLights->light(l);
- if (SkLights::Light::kAmbient_LightType == light.type()) {
- accum += light.color().makeScale(255.0f);
- } else {
- SkScalar NdotL = normals[i].dot(light.dir());
- if (NdotL < 0.0f) {
- NdotL = 0.0f;
- }
+ SkScalar illuminanceScalingFactor = 1.0f;
- accum.fX += light.color().fX * SkColorGetR(diffColor) * NdotL;
- accum.fY += light.color().fY * SkColorGetG(diffColor) * NdotL;
- accum.fZ += light.color().fZ * SkColorGetB(diffColor) * NdotL;
+ if (SkLights::Light::kDirectional_LightType == light.type()) {
+ illuminanceScalingFactor = normals[i].dot(light.dir());
+ if (illuminanceScalingFactor < 0.0f) {
+ illuminanceScalingFactor = 0.0f;
+ }
}
+
+ accum.fX += light.color().fX * SkColorGetR(diffColor) * illuminanceScalingFactor;
+ accum.fY += light.color().fY * SkColorGetG(diffColor) * illuminanceScalingFactor;
+ accum.fZ += light.color().fZ * SkColorGetB(diffColor) * illuminanceScalingFactor;
}
// convert() premultiplies the accumulate color with alpha