Files
MapLibreParticleLab/shaders/collision_circle.fragment.glsl
mwilsnd 642903fdb4 Merge branch 'topic/drawable-fixes' into topic/drawable (#1560)
Co-authored-by: Stefan Karschti <stefan.karschti@gmail.com>
Co-authored-by: Alex Cristici <alex.cristici@gmail.com>
Co-authored-by: Tim Sylvester <tim@wetdogweather.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-31 15:36:19 +02:00

35 lines
919 B
GLSL

uniform float u_overscale_factor;
in float v_placed;
in float v_notUsed;
in float v_radius;
in highp vec2 v_extrude;
in vec2 v_extrude_scale;
void main() {
float alpha = 0.5;
// Red = collision, hide label
vec4 color = vec4(1.0, 0.0, 0.0, 1.0) * alpha;
// Blue = no collision, label is showing
if (v_placed > 0.5) {
color = vec4(0.0, 0.0, 1.0, 0.5) * alpha;
}
if (v_notUsed > 0.5) {
// This box not used, fade it out
color *= .2;
}
float extrude_scale_length = length(v_extrude_scale);
float extrude_length = length(v_extrude) * extrude_scale_length;
float stroke_width = 15.0 * extrude_scale_length / u_overscale_factor;
float radius = v_radius * extrude_scale_length;
float distance_to_edge = abs(extrude_length - radius);
float opacity_t = smoothstep(-stroke_width, 0.0, -distance_to_edge);
fragColor = opacity_t * color;
}