aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2016-08-17 07:59:41 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-17 07:59:41 -0700
commit6c177a1a49fcfe8bfd5f3ffda3ee50bbe2679463 (patch)
tree754f6f73648a838ed21c50441a0ba22996d11f5e /src/gpu
parent86b6eabeae80c3db69226cd1693d7f1c4591d88e (diff)
Add alternative ambient shadow method to Android shadow sample
TBR=bsalomon@google.com BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2249973003 Review-Url: https://codereview.chromium.org/2249973003
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrOvalRenderer.cpp21
-rw-r--r--src/gpu/batches/GrAnalyticRectBatch.cpp2
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp2
3 files changed, 18 insertions, 7 deletions
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 89e35a1d70..77ed6c9854 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -69,6 +69,12 @@ inline bool circle_stays_circle(const SkMatrix& m) {
* p is the position in the normalized space.
* outerRad is the outerRadius in device space.
* innerRad is the innerRadius in normalized space (ignored if not stroking).
+ * If fUsesDistanceVectorField is set in fragment processors in the same program, then
+ * an additional vertex attribute is available via args.fFragBuilder->distanceVectorName():
+ * vec4f : (v.xy, outerDistance, innerDistance)
+ * v is a normalized vector pointing to the outer edge
+ * outerDistance is the distance to the outer edge, < 0 if we are outside of the shape
+ * if stroking, innerDistance is the distance to the inner edge, < 0 if outside
*/
class CircleGeometryProcessor : public GrGeometryProcessor {
@@ -129,20 +135,25 @@ public:
args.fTransformsOut);
fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
- fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn());
- fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0.0, 1.0);");
+ fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 - d);", v.fsIn());
+ fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdge, 0.0, 1.0);");
if (cgp.fStroke) {
- fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.w), 0.0, 1.0);",
+ fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d - %s.w);",
v.fsIn(), v.fsIn());
+ fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInnerEdge, 0.0, 1.0);");
fragBuilder->codeAppend("edgeAlpha *= innerAlpha;");
+ } else {
+ fragBuilder->codeAppend("float distanceToInnerEdge = 0.0;");
}
if (args.fDistanceVectorName) {
fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center of the circle
- fragBuilder->codeAppendf(" %s = vec3(1.0, 0.0, distanceToEdge);", // no normalize
+ fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOuterEdge, "
+ "distanceToInnerEdge);", // no normalize
args.fDistanceVectorName);
fragBuilder->codeAppend ("} else {");
- fragBuilder->codeAppendf(" %s = vec3(normalize(%s.xy), distanceToEdge);",
+ fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distanceToOuterEdge, "
+ "distanceToInnerEdge);",
args.fDistanceVectorName, v.fsIn());
fragBuilder->codeAppend ("}");
}
diff --git a/src/gpu/batches/GrAnalyticRectBatch.cpp b/src/gpu/batches/GrAnalyticRectBatch.cpp
index b41aa7f719..b13ea77a66 100644
--- a/src/gpu/batches/GrAnalyticRectBatch.cpp
+++ b/src/gpu/batches/GrAnalyticRectBatch.cpp
@@ -183,7 +183,7 @@ public:
fragBuilder->codeAppend( "}");
fragBuilder->codeAppend( "float dvSign = sign(dot(offset, dvAxis));");
- fragBuilder->codeAppendf("%s = vec3(dvSign * dvAxis, dvLength);",
+ fragBuilder->codeAppendf("%s = vec4(dvSign * dvAxis, dvLength, 0.0);",
args.fDistanceVectorName);
}
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 37c20deeb9..a6bff8a85a 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -92,7 +92,7 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
distanceVectorName = fFS.distanceVectorName();
fFS.codeAppend( "// Normalized vector to the closest geometric edge (in device space)\n");
fFS.codeAppend( "// Distance to the edge encoded in the z-component\n");
- fFS.codeAppendf("vec3 %s;", distanceVectorName);
+ fFS.codeAppendf("vec4 %s;", distanceVectorName);
}
// Enclose custom code in a block to avoid namespace conflicts