bgfx/examples/common/font/fs_font_distance_field_subpixel.sc

29 lines
770 B
Python
Raw Normal View History

2013-04-22 16:42:11 -04:00
$input v_color0, v_texcoord0
#include "../../common/common.sh"
2015-07-29 02:16:23 -04:00
SAMPLERCUBE(s_texColor, 0);
2013-04-22 16:42:11 -04:00
void main()
{
2013-06-04 02:16:02 -04:00
int index = int(v_texcoord0.w*4.0 + 0.5);
vec3 dx3 = dFdx(v_texcoord0.xyz);
vec3 dy3 = dFdy(v_texcoord0.xyz);
vec3 decal = 0.166667 * dx3;
vec3 sampleLeft = v_texcoord0.xyz - decal;
vec3 sampleRight = v_texcoord0.xyz + decal;
2013-04-22 16:42:11 -04:00
2015-07-29 02:16:23 -04:00
float left_dist = textureCube(s_texColor, sampleLeft).zyxw[index];
float right_dist = textureCube(s_texColor, sampleRight).zyxw[index];
2013-04-22 16:42:11 -04:00
2013-06-04 02:16:02 -04:00
float dist = 0.5 * (left_dist + right_dist);
2013-04-22 16:42:11 -04:00
2013-06-04 02:16:02 -04:00
float dx = length(dx3);
float dy = length(dy3);
float w = 16.0*0.5*(dx+dy);
2013-04-22 16:42:11 -04:00
2013-06-04 02:16:02 -04:00
vec3 sub_color = smoothstep(0.5 - w, 0.5 + w, vec3(left_dist, dist, right_dist));
gl_FragColor.xyz = sub_color*v_color0.w;
gl_FragColor.w = dist*v_color0.w;
2013-04-22 16:42:11 -04:00
}