Created
December 28, 2019 10:08
-
-
Save scheibel/8380b796e8e4ffde6552437f75b3d232 to your computer and use it in GitHub Desktop.
Stripped-down distance field rendering fragment shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision mediump float; | |
layout(location = 0) out vec4 fragColor; | |
uniform sampler2D u_glyphs; | |
uniform vec4 u_color; | |
uniform float u_aaStepScale; | |
uniform int u_aaSampling; | |
varying vec2 v_uv; | |
const int channel = 0; | |
float aastep(float t, float value) | |
{ | |
float afwidth = fwidth(value) * u_aaStepScale; | |
return smoothstep(t - afwidth, t + afwidth, value); | |
} | |
float tex(float t, vec2 uv) | |
{ | |
return aastep(t, texture(u_glyphs, uv)[channel]); | |
} | |
void main(void) | |
{ | |
float a = tex(0.5, v_uv); | |
if(a <= 0.0) { | |
discard; | |
} | |
fragColor = vec4(u_color.rgb, u_color.a * a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment