Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tim Sylvester <tim@wetdogweather.com> Co-authored-by: mwilsnd <mwilsnd@gmail.com>
59 lines
1.5 KiB
GLSL
59 lines
1.5 KiB
GLSL
layout (std140) uniform LineUBO {
|
|
highp mat4 u_matrix;
|
|
highp vec2 u_units_to_pixels;
|
|
mediump float u_ratio;
|
|
lowp float u_device_pixel_ratio;
|
|
};
|
|
|
|
layout (std140) uniform LinePropertiesUBO {
|
|
highp vec4 u_color;
|
|
lowp float u_blur;
|
|
lowp float u_opacity;
|
|
mediump float u_gapwidth;
|
|
lowp float u_offset;
|
|
mediump float u_width;
|
|
|
|
highp float pad1;
|
|
highp vec2 pad2;
|
|
};
|
|
|
|
layout (std140) uniform LineInterpolationUBO {
|
|
lowp float u_color_t;
|
|
lowp float u_blur_t;
|
|
lowp float u_opacity_t;
|
|
lowp float u_gapwidth_t;
|
|
lowp float u_offset_t;
|
|
lowp float u_width_t;
|
|
|
|
highp vec2 pad3;
|
|
};
|
|
|
|
in vec2 v_width2;
|
|
in vec2 v_normal;
|
|
in float v_gamma_scale;
|
|
|
|
#pragma mapbox: define highp vec4 color
|
|
#pragma mapbox: define lowp float blur
|
|
#pragma mapbox: define lowp float opacity
|
|
|
|
void main() {
|
|
#pragma mapbox: initialize highp vec4 color
|
|
#pragma mapbox: initialize lowp float blur
|
|
#pragma mapbox: initialize lowp float opacity
|
|
|
|
// Calculate the distance of the pixel from the line in pixels.
|
|
float dist = length(v_normal) * v_width2.s;
|
|
|
|
// Calculate the antialiasing fade factor. This is either when fading in
|
|
// the line in case of an offset line (v_width2.t) or when fading out
|
|
// (v_width2.s)
|
|
float blur2 = (blur + 1.0 / u_device_pixel_ratio) * v_gamma_scale;
|
|
float alpha = clamp(min(dist - (v_width2.t - blur2), v_width2.s - dist) / blur2, 0.0, 1.0);
|
|
|
|
fragColor = color * (alpha * opacity);
|
|
|
|
#ifdef OVERDRAW_INSPECTOR
|
|
fragColor = vec4(1.0);
|
|
#endif
|
|
}
|