Files
MapLibreParticleLab/shaders/drawable.symbol_sdf.fragment.glsl
Alex Cristici f582327191 UBO consolidation (#3089)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-01-08 17:41:29 +02:00

77 lines
2.4 KiB
GLSL

#define SDF_PX 8.0
layout (std140) uniform SymbolTilePropsUBO {
bool u_is_text;
bool u_is_halo;
highp float u_gamma_scale;
lowp float tileprops_pad1;
};
layout (std140) uniform SymbolEvaluatedPropsUBO {
highp vec4 u_text_fill_color;
highp vec4 u_text_halo_color;
highp float u_text_opacity;
highp float u_text_halo_width;
highp float u_text_halo_blur;
lowp float props_pad1;
highp vec4 u_icon_fill_color;
highp vec4 u_icon_halo_color;
highp float u_icon_opacity;
highp float u_icon_halo_width;
highp float u_icon_halo_blur;
lowp float props_pad2;
};
uniform sampler2D u_texture;
in vec2 v_data0;
in vec3 v_data1;
#pragma mapbox: define highp vec4 fill_color
#pragma mapbox: define highp vec4 halo_color
#pragma mapbox: define lowp float opacity
#pragma mapbox: define lowp float halo_width
#pragma mapbox: define lowp float halo_blur
void main() {
highp vec4 u_fill_color = u_is_text ? u_text_fill_color : u_icon_fill_color;
highp vec4 u_halo_color = u_is_text ? u_text_halo_color : u_icon_halo_color;
highp float u_opacity = u_is_text ? u_text_opacity : u_icon_opacity;
highp float u_halo_width = u_is_text ? u_text_halo_width : u_icon_halo_width;
highp float u_halo_blur = u_is_text ? u_text_halo_blur : u_icon_halo_blur;
#pragma mapbox: initialize highp vec4 fill_color
#pragma mapbox: initialize highp vec4 halo_color
#pragma mapbox: initialize lowp float opacity
#pragma mapbox: initialize lowp float halo_width
#pragma mapbox: initialize lowp float halo_blur
float EDGE_GAMMA = 0.105 / DEVICE_PIXEL_RATIO;
vec2 tex = v_data0.xy;
float gamma_scale = v_data1.x;
float size = v_data1.y;
float fade_opacity = v_data1[2];
float fontScale = u_is_text ? size / 24.0 : size;
lowp vec4 color = fill_color;
highp float gamma = EDGE_GAMMA / (fontScale * u_gamma_scale);
lowp float buff = (256.0 - 64.0) / 256.0;
if (u_is_halo) {
color = halo_color;
gamma = (halo_blur * 1.19 / SDF_PX + EDGE_GAMMA) / (fontScale * u_gamma_scale);
buff = (6.0 - halo_width / fontScale) / SDF_PX;
}
lowp float dist = texture(u_texture, tex).a;
highp float gamma_scaled = gamma * gamma_scale;
highp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist);
fragColor = color * (alpha * opacity * fade_opacity);
#ifdef OVERDRAW_INSPECTOR
fragColor = vec4(1.0);
#endif
}