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

Unified Diff: src/effects/SkGaussianEdgeShader.cpp

Issue 2256713002: Add alternative spot shadow to Android shadow sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments; fix scale 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 | « samplecode/SampleAndroidShadows.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkGaussianEdgeShader.cpp
diff --git a/src/effects/SkGaussianEdgeShader.cpp b/src/effects/SkGaussianEdgeShader.cpp
index e519598f1bba8ca5088f8001ec4aa90d72820482..1990fbf67b5674baeb8ddc0f172e8fe561d80072 100644
--- a/src/effects/SkGaussianEdgeShader.cpp
+++ b/src/effects/SkGaussianEdgeShader.cpp
@@ -11,6 +11,10 @@
/** \class SkGaussianEdgeShaderImpl
This subclass of shader applies a Gaussian to shadow edge
+
+ The radius of the Gaussian blur is specified by the g and b values of the color,
+ where g is the integer component and b is the fractional component. The r value
+ represents the max final alpha.
*/
class SkGaussianEdgeShaderImpl : public SkShader {
public:
@@ -65,20 +69,13 @@ public:
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- fragBuilder->codeAppendf("vec4 output = %s;", args.fInputColor);
- // outside the outer edge
- fragBuilder->codeAppendf("if (%s.z <= 0) {", fragBuilder->distanceVectorName());
- fragBuilder->codeAppend("output *= 0.0;");
- // inside the stroke
- fragBuilder->codeAppendf("} else if (%s.w > 0) {", fragBuilder->distanceVectorName());
- fragBuilder->codeAppendf("float factor = %s.w/(%s.z + %s.w);",
- fragBuilder->distanceVectorName(),
- fragBuilder->distanceVectorName(),
+ fragBuilder->codeAppendf("vec4 color = %s;", args.fInputColor);
+ fragBuilder->codeAppend("float radius = color.g*255.0 + color.b;");
+
+ fragBuilder->codeAppendf("float factor = 1.0 - clamp(%s.z/radius, 0.0, 1.0);",
fragBuilder->distanceVectorName());
fragBuilder->codeAppend("factor = exp(-factor * factor * 4.0) - 0.018;");
- fragBuilder->codeAppend("output *= factor;");
- fragBuilder->codeAppend("}");
- fragBuilder->codeAppendf("%s = output;", args.fOutputColor);
+ fragBuilder->codeAppendf("%s = factor*vec4(0.0, 0.0, 0.0, color.r);", args.fOutputColor);
}
static void GenKey(const GrProcessor& proc, const GrGLSLCaps&,
« no previous file with comments | « samplecode/SampleAndroidShadows.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698