fs_texture_sdf.sc 507 B

1234567891011121314151617181920
  1. $input v_texcoord0, v_color0
  2. /*
  3. * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
  4. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  5. */
  6. #include "common.sh"
  7. SAMPLER2D(s_texColor, 0);
  8. void main()
  9. {
  10. vec4 bgColor = vec4(0.0, 0.0, 0.0, 0.0);
  11. vec4 fgColor = vec4(1.0, 1.0, 1.0, 1.0);
  12. float sigDist = texture2DLod(s_texColor, v_texcoord0.xy, u_textureLod).x;
  13. float opacity = clamp(sigDist/fwidth(sigDist) + 0.5, 0.0, 1.0);
  14. gl_FragColor = mix(bgColor, fgColor, opacity);
  15. }