Skip to content

Instantly share code, notes, and snippets.

@scheibel
Created December 28, 2019 10:08
Show Gist options
  • Save scheibel/8380b796e8e4ffde6552437f75b3d232 to your computer and use it in GitHub Desktop.
Save scheibel/8380b796e8e4ffde6552437f75b3d232 to your computer and use it in GitHub Desktop.
Stripped-down distance field rendering fragment shader
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