I have a distance field font that I would like to render with a vertical gradient. The problem I'm having is I can't work out if there's an easy way for me to get the y coordinate relative to the glyph I'm rendering from the fonts texture atlas.
I'm using LibGDX. I can use v_texCoord.y to get the position relative to the texture. Is there an easy way I can get the y position relative to the texture region that I'm rendering for the current character? Once I've got that I can just use mix(...) to create the gradient in the fragment shader.
Vertex Shader
attribute vec4 a_position;
attribute vec2 a_texCoord0;
attribute vec4 a_color;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoord;
void main()
{
gl_Position = u_projTrans * a_position;
v_texCoord = a_texCoord0;
v_color = a_color;
}
Fragment Shader
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
uniform float u_boldness;
uniform float u_smoothing;
varying vec4 v_color;
varying vec2 v_texCoord;
void main()
{
float distance = texture2D(u_texture, v_texCoord).a;
float alpha = smoothstep(0.5 - u_boldness - u_smoothing, 0.5 - u_boldness + u_smoothing, distance);
gl_FragColor = vec4(v_color.rgb * alpha, alpha * v_color.a);
}