sdf.fs 651 B

12345678910111213141516171819202122232425
  1. #version 100
  2. precision mediump float;
  3. // Input vertex attributes (from vertex shader)
  4. varying vec2 fragTexCoord;
  5. varying vec4 fragColor;
  6. // Input uniform values
  7. uniform sampler2D texture0;
  8. uniform vec4 colDiffuse;
  9. // NOTE: Add here your custom variables
  10. const float smoothing = 1.0/16.0;
  11. void main()
  12. {
  13. // Texel color fetching from texture sampler
  14. // NOTE: Calculate alpha using signed distance field (SDF)
  15. float distance = texture2D(texture0, fragTexCoord).a;
  16. float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
  17. // Calculate final fragment color
  18. gl_FragColor = vec4(fragColor.rgb, fragColor.a*alpha);
  19. }