From fdc2ab9421c6a38c6bbd9b621c4da4f2c147a773 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sun, 6 Nov 2022 17:43:00 +0100 Subject: msdf font renderen --- web/pw-visualizer/assets/shaders/frag/msdf.glsl | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 web/pw-visualizer/assets/shaders/frag/msdf.glsl (limited to 'web/pw-visualizer/assets/shaders') diff --git a/web/pw-visualizer/assets/shaders/frag/msdf.glsl b/web/pw-visualizer/assets/shaders/frag/msdf.glsl new file mode 100644 index 0000000..5d2325b --- /dev/null +++ b/web/pw-visualizer/assets/shaders/frag/msdf.glsl @@ -0,0 +1,29 @@ +#extension GL_OES_standard_derivatives : enable +#ifdef GL_ES +precision mediump float; +#endif + +varying vec2 v_texCoord; +uniform sampler2D msdf; +uniform vec4 u_bgColor; +uniform vec4 u_fgColor; + +uniform float u_distanceRange; +uniform float u_glyphSize; +uniform vec2 u_resolution; +uniform vec4 u_viewbox; + +float median(float r, float g, float b) { + return max(min(r, g), min(max(r, g), b)); +} + +void main() { + float scale = u_distanceRange / u_glyphSize * u_resolution.y / u_viewbox.w; + + vec3 msd = texture2D(msdf, v_texCoord).rgb; + float sd = median(msd.r, msd.g, msd.b); + float screenPxRange = max(u_distanceRange, scale); + float screenPxDistance = screenPxRange*(sd - 0.5); + float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0); + gl_FragColor = vec4(u_fgColor.rgb, u_fgColor.a * opacity); +} \ No newline at end of file -- cgit v1.2.3