Snap coordinates for shader nearest-neighbor decal filtering

Bug: skia:10403
Change-Id: I875b1a4bb7cacbe6721a69aa8ed02118b989729d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/297596
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Michael Ludwig 2020-06-18 17:52:49 -04:00 committed by Skia Commit-Bot
parent 22d9d0b996
commit 4e68ec693f

View File

@ -671,17 +671,20 @@ GrGLSLFragmentProcessor* GrTextureEffect::onCreateGLSLInstance() const {
}
// Do hard-edge shader transition to border color for kClampToBorderNearest at the
// subset boundaries.
// subset boundaries. Snap the input coordinates to nearest neighbor (with an
// epsilon) before comparing to the subset rect to avoid GPU interpolation errors
if (m[0] == ShaderMode::kClampToBorderNearest) {
fb->codeAppendf(
"if (inCoord.x < %s.x || inCoord.x > %s.z) {"
"float snappedX = floor(inCoord.x + 0.001) + 0.5;"
"if (snappedX < %s.x || snappedX > %s.z) {"
" textureColor = %s;"
"}",
subsetName, subsetName, borderName);
}
if (m[1] == ShaderMode::kClampToBorderNearest) {
fb->codeAppendf(
"if (inCoord.y < %s.y || inCoord.y > %s.w) {"
"float snappedY = floor(inCoord.y + 0.001) + 0.5;"
"if (snappedY < %s.y || snappedY > %s.w) {"
" textureColor = %s;"
"}",
subsetName, subsetName, borderName);