In multicolor XCAA, cap the slope to a reasonable amount to prevent line segments from shooting way up or down

This commit is contained in:
Patrick Walton 2017-12-19 13:47:57 -08:00
parent ddd1c89294
commit 097e909d07
2 changed files with 15 additions and 11 deletions

View File

@ -145,7 +145,7 @@ vec2 computeMCAASnappedPosition(vec2 position,
vec4 localTransformST, vec4 localTransformST,
vec4 globalTransformST, vec4 globalTransformST,
ivec2 framebufferSize, ivec2 framebufferSize,
float tanTheta) { float slope) {
position = hintPosition(position, hints); position = hintPosition(position, hints);
position = transformVertexPositionST(position, localTransformST); position = transformVertexPositionST(position, localTransformST);
position = transformVertexPositionST(position, globalTransformST); position = transformVertexPositionST(position, globalTransformST);
@ -157,10 +157,7 @@ vec2 computeMCAASnappedPosition(vec2 position,
else else
xNudge = 1.0 - xNudge; xNudge = 1.0 - xNudge;
position.x += xNudge; return position + vec2(xNudge, xNudge * slope);
position.y += xNudge * tanTheta;
return position;
} }
bool computeMCAAQuadPosition(out vec2 outPosition, bool computeMCAAQuadPosition(out vec2 outPosition,

View File

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
#define MAX_SLOPE 10.0
precision highp float; precision highp float;
uniform vec4 uTransformST; uniform vec4 uTransformST;
@ -44,8 +46,13 @@ void main() {
vec4 color = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions); vec4 color = fetchFloat4Data(uPathColors, pathID, uPathColorsDimensions);
vec2 topVector = trPosition - tlPosition, bottomVector = brPosition - blPosition; vec2 topVector = trPosition - tlPosition, bottomVector = brPosition - blPosition;
float topTanTheta = topVector.y / topVector.x;
float bottomTanTheta = bottomVector.y / bottomVector.x; float topSlope = topVector.y / topVector.x;
float bottomSlope = bottomVector.y / bottomVector.x;
if (abs(topSlope) > MAX_SLOPE)
topSlope = sign(topSlope) * MAX_SLOPE;
if (abs(bottomSlope) > MAX_SLOPE)
bottomSlope = sign(bottomSlope) * MAX_SLOPE;
// Transform the points, and compute the position of this vertex. // Transform the points, and compute the position of this vertex.
tlPosition = computeMCAASnappedPosition(tlPosition, tlPosition = computeMCAASnappedPosition(tlPosition,
@ -53,13 +60,13 @@ void main() {
transformST, transformST,
uTransformST, uTransformST,
uFramebufferSize, uFramebufferSize,
topTanTheta); topSlope);
trPosition = computeMCAASnappedPosition(trPosition, trPosition = computeMCAASnappedPosition(trPosition,
uHints, uHints,
transformST, transformST,
uTransformST, uTransformST,
uFramebufferSize, uFramebufferSize,
topTanTheta); topSlope);
tcPosition = computeMCAAPosition(tcPosition, tcPosition = computeMCAAPosition(tcPosition,
uHints, uHints,
transformST, transformST,
@ -70,13 +77,13 @@ void main() {
transformST, transformST,
uTransformST, uTransformST,
uFramebufferSize, uFramebufferSize,
bottomTanTheta); bottomSlope);
brPosition = computeMCAASnappedPosition(brPosition, brPosition = computeMCAASnappedPosition(brPosition,
uHints, uHints,
transformST, transformST,
uTransformST, uTransformST,
uFramebufferSize, uFramebufferSize,
bottomTanTheta); bottomSlope);
bcPosition = computeMCAAPosition(bcPosition, bcPosition = computeMCAAPosition(bcPosition,
uHints, uHints,
transformST, transformST,