diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-11-06 17:43:00 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-11-06 18:07:16 +0100 |
commit | fdc2ab9421c6a38c6bbd9b621c4da4f2c147a773 (patch) | |
tree | 50466d9b751f1e1eb3ee8a47479a4d28b5050aa6 /web/pw-visualizer/assets/shaders/frag/msdf.glsl | |
parent | d3845eb85fc8f75562a6e121c5e437763ffeea63 (diff) | |
download | planetwars.dev-fdc2ab9421c6a38c6bbd9b621c4da4f2c147a773.tar.xz planetwars.dev-fdc2ab9421c6a38c6bbd9b621c4da4f2c147a773.zip |
msdf font renderen
Diffstat (limited to 'web/pw-visualizer/assets/shaders/frag/msdf.glsl')
-rw-r--r-- | web/pw-visualizer/assets/shaders/frag/msdf.glsl | 29 |
1 files changed, 29 insertions, 0 deletions
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 |