aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/lighting.cpp62
-rw-r--r--src/effects/SkLightingImageFilter.cpp18
2 files changed, 60 insertions, 20 deletions
diff --git a/gm/lighting.cpp b/gm/lighting.cpp
index af102d7d03..0ce9599bc1 100644
--- a/gm/lighting.cpp
+++ b/gm/lighting.cpp
@@ -10,7 +10,7 @@
#include "SkOffsetImageFilter.h"
#include "SkPoint3.h"
-#define WIDTH 330
+#define WIDTH 550
#define HEIGHT 660
namespace skiagm {
@@ -69,8 +69,10 @@ protected:
SkIntToScalar(-10),
SkIntToScalar(20));
SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
- SkScalar spotExponent = SK_Scalar1;
- SkScalar cutoffAngle = SkIntToScalar(15);
+ SkScalar spotExponent1 = SK_Scalar1;
+ SkScalar spotExponent0 = SkIntToScalar(0);
+ SkScalar cutoffAngleSmall = SkIntToScalar(15);
+ SkScalar cutoffAngleNone = SkIntToScalar(180);
SkScalar kd = SkIntToScalar(2);
SkScalar ks = SkIntToScalar(1);
SkScalar shininess = SkIntToScalar(8);
@@ -104,8 +106,8 @@ protected:
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation,
spotTarget,
- spotExponent,
- cutoffAngle,
+ spotExponent1,
+ cutoffAngleSmall,
white,
surfaceScale,
kd,
@@ -113,6 +115,28 @@ protected:
cr))->unref();
drawClippedBitmap(canvas, paint, 220, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation,
+ spotTarget,
+ spotExponent1,
+ cutoffAngleNone,
+ white,
+ surfaceScale,
+ kd,
+ input,
+ cr))->unref();
+ drawClippedBitmap(canvas, paint, 330, y);
+
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation,
+ spotTarget,
+ spotExponent0,
+ cutoffAngleNone,
+ white,
+ surfaceScale,
+ kd,
+ input,
+ cr))->unref();
+ drawClippedBitmap(canvas, paint, 440, y);
+
y += 110;
paint.setImageFilter(SkLightingImageFilter::CreatePointLitSpecular(pointLocation,
@@ -135,8 +159,8 @@ protected:
paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation,
spotTarget,
- spotExponent,
- cutoffAngle,
+ spotExponent1,
+ cutoffAngleSmall,
white,
surfaceScale,
ks,
@@ -145,6 +169,30 @@ protected:
cr))->unref();
drawClippedBitmap(canvas, paint, 220, y);
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation,
+ spotTarget,
+ spotExponent1,
+ cutoffAngleNone,
+ white,
+ surfaceScale,
+ ks,
+ shininess,
+ input,
+ cr))->unref();
+ drawClippedBitmap(canvas, paint, 330, y);
+
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(spotLocation,
+ spotTarget,
+ spotExponent0,
+ cutoffAngleNone,
+ white,
+ surfaceScale,
+ ks,
+ shininess,
+ input,
+ cr))->unref();
+ drawClippedBitmap(canvas, paint, 440, y);
+
y += 110;
}
}
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 199bb4d684..f0f2c66d6f 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -682,7 +682,7 @@ class GrGLLight;
class SkImageFilterLight : public SkRefCnt {
public:
-
+
enum LightType {
kDistant_LightType,
@@ -819,8 +819,8 @@ public:
// 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 = SkPoint3::Make(location2.fX,
- location2.fY,
+ SkPoint3 location = SkPoint3::Make(location2.fX,
+ location2.fY,
SkScalarAve(locationZ.fX, locationZ.fY));
return new SkPointLight(location, color());
}
@@ -854,7 +854,7 @@ public:
: INHERITED(color),
fLocation(location),
fTarget(target),
- fSpecularExponent(SkScalarPin(specularExponent, kSpecularExponentMin, kSpecularExponentMax))
+ fSpecularExponent(specularExponent)
{
fS = target - location;
fast_normalize(&fS);
@@ -984,9 +984,6 @@ protected:
}
private:
- static const SkScalar kSpecularExponentMin;
- static const SkScalar kSpecularExponentMax;
-
SkPoint3 fLocation;
SkPoint3 fTarget;
SkScalar fSpecularExponent;
@@ -998,11 +995,6 @@ private:
typedef SkImageFilterLight INHERITED;
};
-// According to the spec, the specular term should be in the range [1, 128] :
-// http://www.w3.org/TR/SVG/filters.html#feSpecularLightingSpecularExponentAttribute
-const SkScalar SkSpotLight::kSpecularExponentMin = 1.0f;
-const SkScalar SkSpotLight::kSpecularExponentMax = 128.0f;
-
///////////////////////////////////////////////////////////////////////////////
void SkImageFilterLight::flattenLight(SkWriteBuffer& buffer) const {
@@ -1993,7 +1985,7 @@ void GrGLSpotLight::emitLightColor(GrGLFPBuilder* builder,
lightColorBody.appendf("\t\treturn %s * scale * (cosAngle - %s) * %s;\n",
color, cosOuter, coneScale);
lightColorBody.appendf("\t}\n");
- lightColorBody.appendf("\treturn %s;\n", color);
+ lightColorBody.appendf("\treturn %s * scale;\n", color);
GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
fsBuilder->emitFunction(kVec3f_GrSLType,
"lightColor",