Index: src/gpu/effects/GrDistanceFieldGeoProc.cpp |
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
index e75466106541d61bb78066f06bf899785ff22ec3..afe5c89f7e31151e2e14b0a1085a29478fa6b21d 100644 |
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp |
@@ -361,6 +361,7 @@ public: |
bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask) == |
kUniformScale_DistanceFieldEffectMask; |
bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag); |
+ bool srgbOutput = SkToBool(dfTexEffect.getFlags() & kSRGB_DistanceFieldEffectFlag); |
if (isUniformScale) { |
// For uniform scale, we adjust for the effect of the transformation on the distance |
// by using the length of the gradient of the t coordinate in the y direction. |
@@ -401,7 +402,15 @@ public: |
// this gives us a smooth step across approximately one fragment |
fragBuilder->codeAppend("afwidth = " SK_DistanceFieldAAFactor "*length(grad);"); |
} |
- fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distance);"); |
+ // The smoothstep falloff compensates for the non-linear sRGB response curve. If we are |
+ // doing gamma-correct rendering (to an sRGB or F16 buffer), then we actually want distance |
+ // mapped linearly to coverage, so use a linear step: |
+ if (srgbOutput) { |
+ fragBuilder->codeAppend( |
+ "float val = clamp(distance + afwidth / (2.0 * afwidth), 0.0, 1.0);"); |
+ } else { |
+ fragBuilder->codeAppend("float val = smoothstep(-afwidth, afwidth, distance);"); |
+ } |
fragBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); |
} |