diff options
author | jvanverth <jvanverth@google.com> | 2015-01-27 08:19:33 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-27 08:19:33 -0800 |
commit | fdf7ccc2012dd06305cc3a0fbc788a483fce7b6a (patch) | |
tree | 0e16ef3d2ed6f3f68e7088f31cf14f81fc2aa048 /src | |
parent | 776c0cd9550f16019da6773370dcce70db0c6a09 (diff) |
Use highp for distance field texture coordinates.
Addresses issues with wavy text (probably due to low-precision aliasing)
BUG=429080
Review URL: https://codereview.chromium.org/879603003
Diffstat (limited to 'src')
-rwxr-xr-x | src/gpu/GrDistanceFieldTextContext.cpp | 6 | ||||
-rwxr-xr-x | src/gpu/effects/GrDistanceFieldTextureEffect.cpp | 57 |
2 files changed, 40 insertions, 23 deletions
diff --git a/src/gpu/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp index 425c56c892..820223ddc4 100755 --- a/src/gpu/GrDistanceFieldTextContext.cpp +++ b/src/gpu/GrDistanceFieldTextContext.cpp @@ -33,9 +33,9 @@ SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, static const int kSmallDFFontSize = 32; static const int kSmallDFFontLimit = 32; -static const int kMediumDFFontSize = 78; -static const int kMediumDFFontLimit = 78; -static const int kLargeDFFontSize = 192; +static const int kMediumDFFontSize = 64; +static const int kMediumDFFontLimit = 64; +static const int kLargeDFFontSize = 128; static const int kVerticesPerGlyph = 4; static const int kIndicesPerGlyph = 6; diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp index 28220a72ec..41bd42fab8 100755 --- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp +++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp @@ -73,19 +73,25 @@ public: kVec2f_GrSLType, kDefault_GrSLPrecision, "TextureSize", &textureSizeUniName); - fsBuilder->codeAppend("\tvec4 texColor = "); + // Use highp to work around aliasing issues + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); + fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn()); + + fsBuilder->codeAppend("\tfloat texColor = "); fsBuilder->appendTextureLookup(args.fSamplers[0], - v.fsIn(), + "uv", kVec2f_GrSLType); - fsBuilder->codeAppend(";\n"); + fsBuilder->codeAppend(".r;\n"); fsBuilder->codeAppend("\tfloat distance = " - SK_DistanceFieldMultiplier "*(texColor.r - " SK_DistanceFieldThreshold ");"); + SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); // we adjust for the effect of the transformation on the distance by using // the length of the gradient of the texture coordinates. We use st coordinates // to ensure we're mapping 1:1 from texel space to pixel space. - fsBuilder->codeAppendf("\tvec2 uv = %s;\n", v.fsIn()); - fsBuilder->codeAppendf("\tvec2 st = uv*%s;\n", textureSizeUniName); + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); + fsBuilder->codeAppendf("vec2 st = uv*%s;\n", textureSizeUniName); fsBuilder->codeAppend("\tfloat afwidth;\n"); if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { // this gives us a smooth step across approximately one fragment @@ -367,18 +373,24 @@ public: kVec2f_GrSLType, kDefault_GrSLPrecision, "TextureSize", &textureSizeUniName); - fsBuilder->codeAppend("vec4 texColor = "); + // Use highp to work around aliasing issues + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); + fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); + + fsBuilder->codeAppend("float texColor = "); fsBuilder->appendTextureLookup(args.fSamplers[0], - v.fsIn(), + "uv", kVec2f_GrSLType); - fsBuilder->codeAppend(";"); + fsBuilder->codeAppend(".r;"); fsBuilder->codeAppend("float distance = " - SK_DistanceFieldMultiplier "*(texColor.r - " SK_DistanceFieldThreshold ");"); + SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");"); // we adjust for the effect of the transformation on the distance by using // the length of the gradient of the texture coordinates. We use st coordinates // to ensure we're mapping 1:1 from texel space to pixel space. - fsBuilder->codeAppendf("vec2 uv = %s;", v.fsIn()); + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); fsBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName); fsBuilder->codeAppend("float afwidth;"); if (dfTexEffect.getFlags() & kSimilarity_DistanceFieldEffectFlag) { @@ -613,8 +625,13 @@ public: GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature)); // create LCD offset adjusted by inverse of transform - fsBuilder->codeAppendf("\tvec2 uv = %s;\n", v.fsIn()); - fsBuilder->codeAppendf("\tvec2 st = uv*%s.xy;\n", textureSizeUniName); + // Use highp to work around aliasing issues + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); + fsBuilder->codeAppendf("vec2 uv = %s;\n", v.fsIn()); + fsBuilder->codeAppend(GrGLShaderVar::PrecisionString(kHigh_GrSLPrecision, + pb->ctxInfo().standard())); + fsBuilder->codeAppendf("vec2 st = uv*%s.xy;\n", textureSizeUniName); bool isUniformScale = !!(dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask); if (isUniformScale) { fsBuilder->codeAppend("\tfloat dx = dFdx(st.x);\n"); @@ -689,22 +706,22 @@ public: "TextColor", &textColorUniName); fsBuilder->codeAppendf("\tuv = vec2(val.x, %s.x);\n", textColorUniName); - fsBuilder->codeAppend("\tvec4 gammaColor = "); + fsBuilder->codeAppend("float gammaColor = "); fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType); - fsBuilder->codeAppend(";\n"); - fsBuilder->codeAppend("\tval.x = gammaColor.r;\n"); + fsBuilder->codeAppend(".r;\n"); + fsBuilder->codeAppend("\tval.x = gammaColor;\n"); fsBuilder->codeAppendf("\tuv = vec2(val.y, %s.y);\n", textColorUniName); fsBuilder->codeAppend("\tgammaColor = "); fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType); - fsBuilder->codeAppend(";\n"); - fsBuilder->codeAppend("\tval.y = gammaColor.r;\n"); + fsBuilder->codeAppend(".r;\n"); + fsBuilder->codeAppend("\tval.y = gammaColor;\n"); fsBuilder->codeAppendf("\tuv = vec2(val.z, %s.z);\n", textColorUniName); fsBuilder->codeAppend("\tgammaColor = "); fsBuilder->appendTextureLookup(args.fSamplers[1], "uv", kVec2f_GrSLType); - fsBuilder->codeAppend(";\n"); - fsBuilder->codeAppend("\tval.z = gammaColor.r;\n"); + fsBuilder->codeAppend(".r;\n"); + fsBuilder->codeAppend("\tval.z = gammaColor;\n"); fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); } |