3dText.effect 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. CCEffect %{
  2. techniques:
  3. - passes:
  4. - vert: sprite-vs:vert
  5. frag: sprite-fs:frag
  6. depthStencilState:
  7. depthTest: false
  8. depthWrite: false
  9. blendState:
  10. targets:
  11. - blend: true
  12. blendSrc: src_alpha
  13. blendDst: one_minus_src_alpha
  14. blendDstAlpha: one_minus_src_alpha
  15. rasterizerState:
  16. cullMode: none
  17. properties:
  18. alphaThreshold: { value: 0.5 }
  19. }%
  20. CCProgram sprite-vs %{
  21. precision highp float;
  22. #include <builtin/uniforms/cc-global>
  23. #if USE_LOCAL
  24. #include <builtin/uniforms/cc-local>
  25. #endif
  26. #if SAMPLE_FROM_RT
  27. #include <common/common-define>
  28. #endif
  29. in vec3 a_position;
  30. in vec2 a_texCoord;
  31. in vec4 a_color;
  32. out vec4 color;
  33. out vec2 uv0;
  34. vec4 vert () {
  35. vec4 pos = vec4(a_position, 1);
  36. #if USE_LOCAL
  37. pos = cc_matWorld * pos;
  38. #endif
  39. #if USE_PIXEL_ALIGNMENT
  40. pos = cc_matView * pos;
  41. pos.xyz = floor(pos.xyz);
  42. pos = cc_matProj * pos;
  43. #else
  44. pos = cc_matViewProj * pos;
  45. #endif
  46. uv0 = a_texCoord;
  47. #if SAMPLE_FROM_RT
  48. CC_HANDLE_RT_SAMPLE_FLIP(uv0);
  49. #endif
  50. color = a_color;
  51. return pos;
  52. }
  53. }%
  54. CCProgram sprite-fs %{
  55. precision highp float;
  56. #include <builtin/internal/embedded-alpha>
  57. #include <builtin/internal/alpha-test>
  58. in vec4 color;
  59. #if USE_TEXTURE
  60. in vec2 uv0;
  61. #pragma builtin(local)
  62. layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
  63. #endif
  64. vec4 frag () {
  65. vec4 o = vec4(1, 1, 1, 1);
  66. #if USE_TEXTURE
  67. o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
  68. #if IS_GRAY
  69. float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
  70. o.r = o.g = o.b = gray;
  71. #endif
  72. #endif
  73. o *= color;
  74. ALPHA_TEST(o);
  75. return o;
  76. }
  77. }%