bgfx/examples/common/font/fs_font_distance_field.sc
Josh Jensen c103383f6f
Add SDF font outlines, drop shadows, and image glyphs (#2325)
* Implement SDF font outlines, drop shadows, and image glyphs

* Update 11-fontsdf to showcase the SDF outlines, drop shadows, and image glyphs

Co-authored-by: Josh Jensen <josh@everrush.com>
2020-12-13 17:02:36 -08:00

28 lines
656 B
Python

$input v_color0, v_texcoord0
#include "../../common/common.sh"
SAMPLERCUBE(s_texColor, 0);
uniform vec4 u_params;
#define u_distanceMultiplier u_params.y
void main()
{
vec4 color = textureCube(s_texColor, v_texcoord0.xyz);
int index = int(v_texcoord0.w*4.0 + 0.5);
float rgba[4];
rgba[0] = color.z;
rgba[1] = color.y;
rgba[2] = color.x;
rgba[3] = color.w;
float distance = rgba[index];
float smoothing = 16.0 * length(fwidth(v_texcoord0.xyz)) / sqrt(2.0) * u_distanceMultiplier;
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
vec4 sdfColor = vec4(v_color0.xyz, alpha * v_color0.w);
gl_FragColor = sdfColor;
}