3dexperiments/assets/shaders/font.fs
2019-12-30 16:50:25 +02:00

30 lines
757 B
GLSL

precision mediump float;
varying vec2 uv;
uniform vec3 uColor;
uniform sampler2D texture0;
uniform float uWidth;
uniform float uEdge;
uniform float uOutlineWidth;
uniform float uOutlineEdge;
uniform vec2 uOutlineOffset;
uniform vec3 uOutlineColor;
void main() {
float distance = 1.0 - texture2D(texture0, uv).a;
float alpha = 1.0 - smoothstep(uWidth, uWidth + uEdge, distance);
float distanceOutline = 1.0 - texture2D(texture0, uv + uOutlineOffset).a;
float alphaOutline = 1.0 - smoothstep(uOutlineWidth, uOutlineWidth + uOutlineEdge, distanceOutline);
float overallAlpha = alpha + (1.0 - alpha) * alphaOutline;
vec3 overallColor = mix(uOutlineColor, uColor, alpha / overallAlpha);
gl_FragColor = vec4(overallColor, overallAlpha);
}