Added Z scale when X and Y scale to spot lights and point lights
Z scale is set as the average of X scale and Y scale.
BUG=skia:
R=senorblanco@google.com, senorblanco@chromium.org
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/198013002
git-svn-id: http://skia.googlecode.com/svn/trunk@13798 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/expectations/gm/ignored-tests.txt b/expectations/gm/ignored-tests.txt
index d9db6bc..f087824 100644
--- a/expectations/gm/ignored-tests.txt
+++ b/expectations/gm/ignored-tests.txt
@@ -51,3 +51,7 @@
# This change removes an API that this GM was testing. If/when it lands and sticks,
# I will likely just delete the GM.
canvas-layer-state
+
+# sugoi: https://codereview.chromium.org/198013002/
+# This adds proper Z scaling (with tests) for point lights and spot lights
+imagefiltersscaled
diff --git a/gm/imagefiltersscaled.cpp b/gm/imagefiltersscaled.cpp
index 809e7ea..5dca30b 100644
--- a/gm/imagefiltersscaled.cpp
+++ b/gm/imagefiltersscaled.cpp
@@ -12,6 +12,7 @@
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
#include "SkGradientShader.h"
+#include "SkLightingImageFilter.h"
#include "SkMorphologyImageFilter.h"
#include "SkOffsetImageFilter.h"
#include "SkPerlinNoiseShader.h"
@@ -35,7 +36,7 @@
}
virtual SkISize onISize() {
- return make_isize(1140, 500);
+ return make_isize(1428, 500);
}
void make_checkerboard() {
@@ -91,6 +92,15 @@
SkAutoTUnref<SkShader> noise(SkPerlinNoiseShader::CreateFractalNoise(
SkDoubleToScalar(0.1), SkDoubleToScalar(0.05), 1, 0));
+ SkPoint3 pointLocation(0, 0, SkIntToScalar(10));
+ SkPoint3 spotLocation(SkIntToScalar(-10), SkIntToScalar(-10), SkIntToScalar(20));
+ SkPoint3 spotTarget(SkIntToScalar(40), SkIntToScalar(40), 0);
+ SkScalar spotExponent = SK_Scalar1;
+ SkScalar cutoffAngle = SkIntToScalar(15);
+ SkScalar kd = SkIntToScalar(2);
+ SkScalar surfaceScale = SkIntToScalar(1);
+ SkColor white(0xFFFFFFFF);
+
SkImageFilter* filters[] = {
SkBlurImageFilter::Create(SkIntToScalar(4), SkIntToScalar(4)),
SkDropShadowImageFilter::Create(SkIntToScalar(5), SkIntToScalar(10), SkIntToScalar(3),
@@ -105,6 +115,9 @@
SkOffsetImageFilter::Create(SkIntToScalar(32), 0),
SkResizeImageFilter::Create(RESIZE_FACTOR, RESIZE_FACTOR, SkPaint::kNone_FilterLevel),
SkRectShaderImageFilter::Create(noise),
+ SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
+ SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
+ cutoffAngle, white, surfaceScale, kd),
};
SkVector scales[] = {
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index f4d0ea2..ec33c29 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -641,7 +641,10 @@
virtual SkLight* transform(const SkMatrix& matrix) const {
SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY);
matrix.mapPoints(&location2, 1);
- SkPoint3 location(location2.fX, location2.fY, fLocation.fZ);
+ // Use X scale and Y scale on Z and average the result
+ SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ);
+ matrix.mapVectors(&locationZ, 1);
+ SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX, locationZ.fY));
return new SkPointLight(location, color());
}
@@ -682,11 +685,18 @@
virtual SkLight* transform(const SkMatrix& matrix) const {
SkPoint location2 = SkPoint::Make(fLocation.fX, fLocation.fY);
matrix.mapPoints(&location2, 1);
- SkPoint3 location(location2.fX, location2.fY, fLocation.fZ);
+ // Use X scale and Y scale on Z and average the result
+ SkPoint locationZ = SkPoint::Make(fLocation.fZ, fLocation.fZ);
+ matrix.mapVectors(&locationZ, 1);
+ SkPoint3 location(location2.fX, location2.fY, SkScalarAve(locationZ.fX, locationZ.fY));
SkPoint target2 = SkPoint::Make(fTarget.fX, fTarget.fY);
matrix.mapPoints(&target2, 1);
- SkPoint3 target(target2.fX, target2.fY, fTarget.fZ);
- return new SkSpotLight(location, target, fSpecularExponent, fCosOuterConeAngle, fCosInnerConeAngle, fConeScale, fS, color());
+ SkPoint targetZ = SkPoint::Make(fTarget.fZ, fTarget.fZ);
+ matrix.mapVectors(&targetZ, 1);
+ SkPoint3 target(target2.fX, target2.fY, SkScalarAve(targetZ.fX, targetZ.fY));
+ SkPoint3 s = target - location;
+ s.normalize();
+ return new SkSpotLight(location, target, fSpecularExponent, fCosOuterConeAngle, fCosInnerConeAngle, fConeScale, s, color());
}
SkPoint3 surfaceToLight(int x, int y, int z, SkScalar surfaceScale) const {