WebGL / Support DPR > 1 in linestring shader

A u_pixelRatio uniform was added to be used in the shaders. this is necessary
since we're relying on the builtin gl_FragCoord vector, which will be scaled
relative to the u_sizePx uniform in case of a device pixel ratio != 1.

Also added tests for computed uniform values, instead of just testing
that they were indeed set.
This commit is contained in:
Olivier Guyot
2022-06-07 21:43:01 +02:00
parent 9e35acaa0a
commit f603ce7456
3 changed files with 63 additions and 1 deletions

View File

@@ -100,6 +100,7 @@ class WebGLLayer extends Layer {
}`,
lineStringFragmentShader: `
precision mediump float;
uniform float u_pixelRatio;
varying vec2 v_segmentStart;
varying vec2 v_segmentEnd;
varying float v_angleStart;
@@ -118,8 +119,9 @@ class WebGLLayer extends Layer {
float lineWidth = 1.5;
void main(void) {
vec2 v_currentPoint = gl_FragCoord.xy / u_pixelRatio;
gl_FragColor = vec4(v_color.rgb * 0.75, 1.0);
gl_FragColor *= segmentDistanceField(gl_FragCoord.xy, v_segmentStart, v_segmentEnd, lineWidth);
gl_FragColor *= segmentDistanceField(v_currentPoint, v_segmentStart, v_segmentEnd, lineWidth);
}`,
pointVertexShader: `
precision mediump float;