ccShader_Label_df_glow.frag 732 B

1234567891011121314151617181920212223242526
  1. const char* ccLabelDistanceFieldGlow_frag = R"(
  2. #ifdef GL_ES
  3. precision lowp float;
  4. #endif
  5. varying vec4 v_fragmentColor;
  6. varying vec2 v_texCoord;
  7. uniform vec4 u_effectColor;
  8. uniform vec4 u_textColor;
  9. void main()
  10. {
  11. float dist = texture2D(CC_Texture0, v_texCoord).a;
  12. //TODO: Implementation 'fwidth' for glsl 1.0
  13. //float width = fwidth(dist);
  14. //assign width for constant will lead to a little bit fuzzy,it's temporary measure.
  15. float width = 0.04;
  16. float alpha = smoothstep(0.5-width, 0.5+width, dist);
  17. //glow
  18. float mu = smoothstep(0.5, 1.0, sqrt(dist));
  19. vec4 color = u_effectColor*(1.0-alpha) + u_textColor*alpha;
  20. gl_FragColor = v_fragmentColor * vec4(color.rgb, max(alpha,mu)*color.a);
  21. }
  22. )";