text2d.fragment.fx 918 B

1234567891011121314151617181920212223242526272829303132333435
  1. //#extension GL_OES_standard_derivatives : enable
  2. varying vec4 vColor;
  3. varying vec2 vUV;
  4. // Samplers
  5. uniform sampler2D diffuseSampler;
  6. void main(void) {
  7. #ifdef SignedDistanceField
  8. float dist = texture2D(diffuseSampler, vUV).r;
  9. if (dist < 0.5) {
  10. discard;
  11. }
  12. // Another way using derivative, commented right now because I don't know if it worth doing it
  13. //float edgeDistance = 0.5;
  14. //float edgeWidth = 0.7 * length(vec2(dFdx(dist), dFdy(dist)));
  15. //float opacity = dist * smoothstep(edgeDistance - edgeWidth, edgeDistance + edgeWidth, dist);
  16. //float opacity = smoothstep(0.25, 0.75, dist);
  17. gl_FragColor = vec4(vColor.xyz*dist, vColor.a);
  18. #else
  19. vec4 color = texture2D(diffuseSampler, vUV);
  20. if (color.a == 0.0) {
  21. discard;
  22. }
  23. #ifdef FontTexture
  24. gl_FragColor = vec4(color.xxx*vColor.xyz*vColor.a, color.x*vColor.a);
  25. #else
  26. gl_FragColor = color*vColor;
  27. #endif
  28. #endif
  29. }