mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 08:15:38 +07:00
label supports sdf
This commit is contained in:
@@ -1,14 +1,24 @@
|
||||
uniform sampler2D u_texture;
|
||||
uniform lowp float u_smoothing;
|
||||
uniform lowp float u_outline_distance;// Between 0 and 0.5, 0 = thick outline, 0.5 = no outline
|
||||
uniform lowp float u_shadow_smoothing;// Between 0 and 0.5
|
||||
uniform lowp vec2 u_shadow_offset; // Between 0 and spread / texture_size
|
||||
uniform lowp vec4 u_shadow_color;
|
||||
uniform lowp vec4 u_outline_color;
|
||||
|
||||
varying vec2 v_st0;
|
||||
varying vec4 v_color;
|
||||
|
||||
const float smoothing = 1.0 / 16.0;
|
||||
|
||||
void main() {
|
||||
vec2 st = vec2(v_st0.s, 1.0 - v_st0.t);
|
||||
gl_FragColor = texture2D(u_texture, st) * v_color;
|
||||
float distance = texture2D(u_texture, st).a;
|
||||
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
|
||||
gl_FragColor = vec4(v_color.rgb, v_color.a * alpha);
|
||||
lowp vec2 st = vec2(v_st0.s, 1.0 - v_st0.t);
|
||||
lowp float distance = texture2D(u_texture, st).a;
|
||||
lowp float outline_factor = smoothstep(0.5 - u_smoothing, 0.5 + u_smoothing, distance);
|
||||
lowp vec4 color = mix(u_outline_color, v_color, outline_factor);
|
||||
lowp float alpha = smoothstep(u_outline_distance - u_smoothing, u_outline_distance + u_smoothing, distance);
|
||||
lowp vec4 text = vec4(color.rgb, color.a * alpha);
|
||||
lowp float shadow_distance = texture2D(u_texture, st - u_shadow_offset).a;
|
||||
lowp float shadow_alpha = smoothstep(0.5 - u_shadow_smoothing, 0.5 + u_shadow_smoothing, shadow_distance);
|
||||
lowp vec4 shadow = vec4(u_shadow_color.rgb, u_shadow_color.a * shadow_alpha);
|
||||
|
||||
gl_FragColor = mix(shadow, text, text.a);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user