25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
889 B

  1. #ifdef OPENGL_ES
  2. #extension GL_OES_standard_derivatives : enable
  3. #ifdef GL_FRAGMENT_PRECISION_HIGH
  4. precision highp float;
  5. #else
  6. precision mediump float;
  7. #endif
  8. #endif
  9. ///////////////////////////////////////////////////////////
  10. // Uniforms
  11. uniform sampler2D u_texture;
  12. #ifdef DISTANCE_FIELD
  13. uniform vec2 u_cutoff;
  14. #endif
  15. ///////////////////////////////////////////////////////////
  16. // Varyings
  17. varying vec2 v_texCoord;
  18. varying vec4 v_color;
  19. void main()
  20. {
  21. #ifdef DISTANCE_FIELD
  22. gl_FragColor = v_color;
  23. float distance = texture2D(u_texture, v_texCoord).a;
  24. float smoothing = fwidth(distance);
  25. float alpha = smoothstep(0.5 - smoothing * u_cutoff.x, 0.5 + smoothing * u_cutoff.y, distance);
  26. gl_FragColor.a = alpha * v_color.a;
  27. #else
  28. gl_FragColor = v_color;
  29. gl_FragColor.a = texture2D(u_texture, v_texCoord).a * v_color.a;
  30. #endif
  31. }