From 0e3c55431b463b5575983c0c875909e08a3562bf Mon Sep 17 00:00:00 2001 From: brianosman Date: Wed, 13 Apr 2016 13:56:21 -0700 Subject: Tweak distance field path renderer behavior in gamma-correct mode to match recent changes to text rendering. Uses linear coverage falloff. Produces results that are perceptually more similar to L32 (raster and gpu). Smoothstep + sRGB was too soft. Plumb the gamma-correctness via DrawPathArgs, which also paves the way for other path rendering implementations to easily make decisions about rendering technique based on that flag. Fix a few typos and formatting issues from my most recent change. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1889453002 Review URL: https://codereview.chromium.org/1889453002 --- src/gpu/effects/GrDistanceFieldGeoProc.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/gpu/effects/GrDistanceFieldGeoProc.cpp') diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 5dd70cd0b8..e87021e978 100644 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -362,6 +362,8 @@ public: bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask) == kUniformScale_DistanceFieldEffectMask; bool isSimilarity = SkToBool(dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag); + bool isGammaCorrect = + SkToBool(dfTexEffect.getFlags() & kGammaCorrect_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. @@ -402,7 +404,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 (isGammaCorrect) { + 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); } -- cgit v1.2.3