aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2015-07-17 07:22:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-17 07:22:30 -0700
commit992c7612394a26e36ba355f6d8d3801d8d8f1260 (patch)
tree93e224f5f682ba3e356556ebc42b21a6e093700b /src
parent84984efeb64787b88c5f8bd6929cfe2d58a3ba06 (diff)
Reland of Add fast normalize for SkLightingImageFilter. (patchset #1 id:1 of https://codereview.chromium.org/1244523002/)
Reason for revert: Florin will rebaseline the images. Original issue's description: > Revert of Add fast normalize for SkLightingImageFilter. (patchset #2 id:20001 of https://codereview.chromium.org/1240023002/) > > Reason for revert: > Speculative revert -- DEPS roll block on linux_blink_rel > > https://storage.googleapis.com/chromium-layout-test-archives/linux_blink_rel/71483/layout-test-results/results.html > > Original issue's description: > > Add fast normalize for SkLightingImageFilter. > > > > The normalize routine in SkPoint3 is very robust. However, for simple > > lighting cases we prefer speed over robustness. This fixes a perf > > regression in smoothness.tough_filters_cases. > > > > BUG=chromium:510562 > > > > Committed: https://skia.googlesource.com/skia/+/dfa0ecf169db87f7afddd93bc1c500de481a62c7 > > TBR=reed@google.com,senorblanco@google.com,senorblanco@chromium.org,jvanverth@google.com > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=chromium:510562 > > Committed: https://skia.googlesource.com/skia/+/ac66a8122b27c388cc74b3913d9a9be351a44e54 TBR=reed@google.com,senorblanco@google.com,senorblanco@chromium.org,reed@chromium.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=chromium:510562 Review URL: https://codereview.chromium.org/1241583007
Diffstat (limited to 'src')
-rw-r--r--src/effects/SkLightingImageFilter.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index ae49462b5e..b82f6ad916 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -60,6 +60,15 @@ inline void shiftMatrixLeft(int m[9]) {
m[7] = m[8];
}
+static inline void fast_normalize(SkPoint3* vector) {
+ // add a tiny bit so we don't have to worry about divide-by-zero
+ SkScalar magSq = vector->dot(*vector) + SK_ScalarNearlyZero;
+ SkScalar scale = sk_float_rsqrt(magSq);
+ vector->fX *= scale;
+ vector->fY *= scale;
+ vector->fZ *= scale;
+}
+
class DiffuseLightingType {
public:
DiffuseLightingType(SkScalar kd)
@@ -90,7 +99,7 @@ public:
const SkPoint3& lightColor) const {
SkPoint3 halfDir(surfaceTolight);
halfDir.fZ += SK_Scalar1; // eye position is always (0, 0, 1)
- halfDir.normalize();
+ fast_normalize(&halfDir);
SkScalar colorScale = SkScalarMul(fKS,
SkScalarPow(normal.dot(halfDir), fShininess));
colorScale = SkScalarClampMax(colorScale, SK_Scalar1);
@@ -113,7 +122,7 @@ inline SkPoint3 pointToNormal(SkScalar x, SkScalar y, SkScalar surfaceScale) {
SkPoint3 vector = SkPoint3::Make(SkScalarMul(-x, surfaceScale),
SkScalarMul(-y, surfaceScale),
SK_Scalar1);
- vector.normalize();
+ fast_normalize(&vector);
return vector;
}
@@ -800,7 +809,7 @@ public:
fLocation.fY - SkIntToScalar(y),
fLocation.fZ - SkScalarMul(SkIntToScalar(z),
surfaceScale));
- direction.normalize();
+ fast_normalize(&direction);
return direction;
};
const SkPoint3& lightColor(const SkPoint3&) const { return this->color(); }
@@ -866,7 +875,7 @@ public:
fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSpecularExponentMax))
{
fS = target - location;
- fS.normalize();
+ fast_normalize(&fS);
fCosOuterConeAngle = SkScalarCos(SkDegreesToRadians(cutoffAngle));
const SkScalar antiAliasThreshold = 0.016f;
fCosInnerConeAngle = fCosOuterConeAngle + antiAliasThreshold;
@@ -888,7 +897,7 @@ public:
SkPoint3 target = SkPoint3::Make(target2.fX, target2.fY,
SkScalarAve(targetZ.fX, targetZ.fY));
SkPoint3 s = target - location;
- s.normalize();
+ fast_normalize(&s);
return new SkSpotLight(location,
target,
fSpecularExponent,
@@ -904,7 +913,7 @@ public:
fLocation.fY - SkIntToScalar(y),
fLocation.fZ - SkScalarMul(SkIntToScalar(z),
surfaceScale));
- direction.normalize();
+ fast_normalize(&direction);
return direction;
};
SkPoint3 lightColor(const SkPoint3& surfaceToLight) const {