aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-03-21 23:13:45 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-26 21:58:44 +0000
commitb709f27bc0161117101aff4adfda32d38fd8e17b (patch)
tree4f97b228297a201fe4b035f9148c88f4e7e9fd62 /src
parentfb4487b06a1535a0fa413af25d14632d91a5a2e4 (diff)
ccpr: Use Manhattan distance for curve AA
Manhattan distance has the nice property that every pixel crossed anywhere by the curve gets a fractional coverage value, whereas pixels not touched by the curve will have zero coverage. This arguably looks better on its own merits, but it also helps the curves blend more seamlessly with their adjoining edges, which are already using Manhattan distance. Bug: skia: Change-Id: I31cf28171d0b74512c74dca1088e50f0f442b924 Reviewed-on: https://skia-review.googlesource.com/115781 Commit-Queue: Chris Dalton <csmartdalton@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/gpu/ccpr/GrCCCubicShader.cpp5
-rw-r--r--src/gpu/ccpr/GrCCQuadraticShader.cpp3
2 files changed, 5 insertions, 3 deletions
diff --git a/src/gpu/ccpr/GrCCCubicShader.cpp b/src/gpu/ccpr/GrCCCubicShader.cpp
index edff5ff563..d0228d59ad 100644
--- a/src/gpu/ccpr/GrCCCubicShader.cpp
+++ b/src/gpu/ccpr/GrCCCubicShader.cpp
@@ -105,8 +105,9 @@ void GrCCCubicShader::onEmitFragmentCode(GrGLSLFPFragmentBuilder* f,
const char* outputCoverage) const {
f->codeAppendf("float k = %s.x, l = %s.y, m = %s.z;", fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn());
f->codeAppend ("float f = k*k*k - l*m;");
- f->codeAppendf("float2 grad_f = %s * float2(k, 1);", fGradMatrix.fsIn());
- f->codeAppendf("%s = clamp(0.5 - f * inversesqrt(dot(grad_f, grad_f)), 0, 1);", outputCoverage);
+ f->codeAppendf("float2 grad = %s * float2(k, 1);", fGradMatrix.fsIn());
+ f->codeAppend ("float fwidth = abs(grad.x) + abs(grad.y);");
+ f->codeAppendf("%s = clamp(0.5 - f/fwidth, 0, 1);", outputCoverage);
f->codeAppendf("half d = min(%s.w, 0);", fKLMD.fsIn()); // Flat edge opposite the curve.
// Wind is the sign of both L and/or M. Take the sign of whichever has the larger magnitude.
diff --git a/src/gpu/ccpr/GrCCQuadraticShader.cpp b/src/gpu/ccpr/GrCCQuadraticShader.cpp
index 287e63e8bf..236c407ade 100644
--- a/src/gpu/ccpr/GrCCQuadraticShader.cpp
+++ b/src/gpu/ccpr/GrCCQuadraticShader.cpp
@@ -73,7 +73,8 @@ void GrCCQuadraticShader::onEmitFragmentCode(GrGLSLFPFragmentBuilder* f,
f->codeAppendf("float x = %s.x, y = %s.y;", fCoord.fsIn(), fCoord.fsIn());
f->codeAppend ("float f = x*x - y;");
f->codeAppendf("float2 grad = %s.zw;", fCoord.fsIn());
- f->codeAppendf("%s = clamp(0.5 - f * inversesqrt(dot(grad, grad)), 0, 1);", outputCoverage);
+ f->codeAppend ("float fwidth = abs(grad.x) + abs(grad.y);");
+ f->codeAppendf("%s = clamp(0.5 - f/fwidth, 0, 1);", outputCoverage);
f->codeAppendf("half d = min(%s.x, 0);", fCoverages.fsIn()); // Flat edge opposite the curve.
f->codeAppendf("half wind = %s.y;", fCoverages.fsIn());