loading.effect 1.8 KB

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