Add small offset to t in GrLinearGradientLayout.

This works around a varying interpolation issue when a hard stop occurs
a along a row or column of pixel centers.

Bug: chromium:938592
Change-Id: I4c239b2831c3e901cbbfa43f0a60a3d7fb0fef75
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/200939
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-03-13 16:44:25 -04:00 committed by Skia Commit-Bot
parent dddd3374b6
commit 1a15723397
2 changed files with 11 additions and 3 deletions

View File

@ -25,8 +25,9 @@ public:
auto gradientMatrix = _outer.gradientMatrix();
(void)gradientMatrix;
SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf("half t = half(%s.x);\n%s = half4(t, 1.0, 0.0, 0.0);\n",
sk_TransformedCoords2D_0.c_str(), args.fOutputColor);
fragBuilder->codeAppendf(
"half t = half(%s.x) + 1.0000000000000001e-05;\n%s = half4(t, 1.0, 0.0, 0.0);\n",
sk_TransformedCoords2D_0.c_str(), args.fOutputColor);
}
private:

View File

@ -12,7 +12,14 @@ in half4x4 gradientMatrix;
}
void main() {
half t = half(sk_TransformedCoords2D[0].x);
// We add a tiny delta to t. When gradient stops are set up so that a hard stop in a vertically
// or horizontally oriented gradient falls exactly at a column or row of pixel centers we can
// we can get slightly different interpolated t values along the column/row. By adding the delta
// we will consistently get the color to the "right" of the stop. Of course if the hard stop
// falls at X.5 - delta then we still could get inconsistent results, but that is much less
// likely. crbug.com/938592
// If/when we add filtering of the gradient this can be removed.
half t = half(sk_TransformedCoords2D[0].x) + 0.00001;
sk_OutColor = half4(t, 1, 0, 0); // y = 1 for always valid
}