ccShader_Label_outline.frag 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * LICENSE ???
  3. */
  4. const char* ccLabelOutline_frag = R"(
  5. #ifdef GL_ES
  6. precision lowp float;
  7. #endif
  8. varying vec4 v_fragmentColor;
  9. varying vec2 v_texCoord;
  10. uniform vec4 u_effectColor;
  11. uniform vec4 u_textColor;
  12. #ifdef GL_ES
  13. uniform lowp int u_effectType; // 0: None (Draw text), 1: Outline, 2: Shadow
  14. #else
  15. uniform int u_effectType;
  16. #endif
  17. void main()
  18. {
  19. vec4 sample = texture2D(CC_Texture0, v_texCoord);
  20. // fontAlpha == 1 means the area of solid text (without edge)
  21. // fontAlpha == 0 means the area outside text, including outline area
  22. // fontAlpha == (0, 1) means the edge of text
  23. float fontAlpha = sample.a;
  24. // outlineAlpha == 1 means the area of 'solid text' and 'solid outline'
  25. // outlineAlpha == 0 means the transparent area outside text and outline
  26. // outlineAlpha == (0, 1) means the edge of outline
  27. float outlineAlpha = sample.r;
  28. if (u_effectType == 0) // draw text
  29. {
  30. gl_FragColor = v_fragmentColor * vec4(u_textColor.rgb, u_textColor.a * fontAlpha);
  31. }
  32. else if (u_effectType == 1) // draw outline
  33. {
  34. // multipy (1.0 - fontAlpha) to make the inner edge of outline smoother and make the text itself transparent.
  35. gl_FragColor = v_fragmentColor * vec4(u_effectColor.rgb, u_effectColor.a * outlineAlpha * (1.0 - fontAlpha));
  36. }
  37. else // draw shadow
  38. {
  39. gl_FragColor = v_fragmentColor * vec4(u_effectColor.rgb, u_effectColor.a * outlineAlpha);
  40. }
  41. }
  42. )";