Fix rounding problems
Fragment shader does not know about the projection matrix, thus it has to take the pixel ratio into account.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
//! COMMON
|
||||
varying float v_round;
|
||||
varying vec4 v_roundVertex;
|
||||
varying vec2 v_roundVertex;
|
||||
varying float v_halfWidth;
|
||||
|
||||
|
||||
@@ -26,20 +26,15 @@ void main(void) {
|
||||
v_round = 0.0;
|
||||
float direction = a_direction / abs(a_direction);
|
||||
vec4 projPos = u_projectionMatrix * vec4(a_position, 0., 1.);
|
||||
v_roundVertex = projPos.xy;
|
||||
if (mod(a_direction, 3.0) == 0.0 || mod(a_direction, 17.0) == 0.0) {
|
||||
vec2 dirVect = a_nextPos - a_position;
|
||||
vec2 normal = normalize(vec2(-dirVect.y, dirVect.x));
|
||||
offset = v_halfWidth * normal * direction;
|
||||
if (mod(a_direction, 2.0) == 0.0) {
|
||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
||||
}
|
||||
} else if (mod(a_direction, 5.0) == 0.0 || mod(a_direction, 13.0) == 0.0) {
|
||||
vec2 dirVect = a_lastPos - a_position;
|
||||
vec2 normal = normalize(vec2(dirVect.y, -dirVect.x));
|
||||
offset = v_halfWidth * normal * direction;
|
||||
if (mod(a_direction, 2.0) == 0.0) {
|
||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
||||
}
|
||||
} else if (mod(a_direction, 19.0) == 0.0 || mod(a_direction, 23.0) == 0.0) {
|
||||
vec2 dirVect = a_nextPos - a_position;
|
||||
vec2 tmpNormal = normalize(vec2(-dirVect.y, dirVect.x));
|
||||
@@ -50,7 +45,6 @@ void main(void) {
|
||||
offset = normal * direction * miterLength;
|
||||
if (mod(a_direction, 2.0) == 0.0) {
|
||||
v_round = 1.0;
|
||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
||||
} else if (miterLength > u_miterLimit) {
|
||||
offset = tmpNormal * direction * v_halfWidth;
|
||||
}
|
||||
@@ -106,7 +100,6 @@ void main(void) {
|
||||
offset = normal * length;
|
||||
if (mod(a_direction, 2.0) == 0.0) {
|
||||
v_round = 1.0;
|
||||
v_roundVertex = projPos + u_offsetScaleMatrix * vec4(0., 0., 0., 0.);
|
||||
}
|
||||
}
|
||||
if (!degenerate) {
|
||||
@@ -121,11 +114,13 @@ void main(void) {
|
||||
uniform float u_opacity;
|
||||
uniform vec4 u_color;
|
||||
uniform vec2 u_size;
|
||||
uniform float u_pixelRatio;
|
||||
|
||||
void main(void) {
|
||||
if (v_round > 0.0) {
|
||||
vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x, (v_roundVertex.y + 1.0) / 2.0 * u_size.y);
|
||||
if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth) {
|
||||
vec2 windowCoords = vec2((v_roundVertex.x + 1.0) / 2.0 * u_size.x * u_pixelRatio,
|
||||
(v_roundVertex.y + 1.0) / 2.0 * u_size.y * u_pixelRatio);
|
||||
if (length(windowCoords - gl_FragCoord.xy) > v_halfWidth * u_pixelRatio) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user