bgfx/tools/texturev/fs_texture_msdf.sc

26 lines
645 B
Python
Raw Normal View History

2017-11-30 08:06:14 +03:00
$input v_texcoord0, v_color0
/*
2023-01-14 21:05:12 +03:00
* Copyright 2011-2023 Branimir Karadzic. All rights reserved.
2022-01-15 22:59:06 +03:00
* License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
2017-11-30 08:06:14 +03:00
*/
#include "common.sh"
SAMPLER2D(s_texColor, 0);
float median(vec3 _val)
{
return max(min(_val.x, _val.y), min(max(_val.x, _val.y), _val.z) );
}
void main() {
vec4 bgColor = vec4(0.0, 0.0, 0.0, 0.0);
vec4 fgColor = vec4(1.0, 1.0, 1.0, 1.0);
vec3 sample = texture2DLod(s_texColor, v_texcoord0.xy, u_textureLod).xyz;
float sigDist = median(sample) - 0.5;
float opacity = clamp(sigDist/fwidth(sigDist) + 0.5, 0.0, 1.0);
gl_FragColor = mix(bgColor, fgColor, opacity);
}