Mult-effect.effect 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 vec3 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. float id = mod(a_texCoord.x,10.0);
  49. uv0.x = (a_texCoord.x - id)*0.000001;
  50. uv0.y = a_texCoord.y;
  51. uv0.z = id;
  52. #if SAMPLE_FROM_RT
  53. CC_HANDLE_RT_SAMPLE_FLIP(uv0.xy);
  54. #endif
  55. color = a_color;
  56. return pos;
  57. }
  58. }%
  59. CCProgram sprite-fs %{
  60. precision highp float;
  61. #include <builtin/internal/embedded-alpha>
  62. #include <builtin/internal/alpha-test>
  63. in vec4 color;
  64. #if USE_TEXTURE
  65. in vec3 uv0;
  66. uniform sampler2D texture0;
  67. uniform sampler2D texture1;
  68. uniform sampler2D texture2;
  69. uniform sampler2D texture3;
  70. uniform sampler2D texture4;
  71. uniform sampler2D texture5;
  72. uniform sampler2D texture6;
  73. uniform sampler2D texture7;
  74. #endif
  75. vec4 frag () {
  76. vec4 o = vec4(1, 1, 1, 1);
  77. #if USE_TEXTURE
  78. if(uv0.z<0.5)
  79. o *= CCSampleWithAlphaSeparated(texture0, uv0.xy);
  80. else if(uv0.z<1.5)
  81. o *= CCSampleWithAlphaSeparated(texture1, uv0.xy);
  82. else if(uv0.z<2.5)
  83. o *= CCSampleWithAlphaSeparated(texture2, uv0.xy);
  84. else if(uv0.z<3.5)
  85. o *= CCSampleWithAlphaSeparated(texture3, uv0.xy);
  86. else if(uv0.z<4.5)
  87. o *= CCSampleWithAlphaSeparated(texture4, uv0.xy);
  88. else if(uv0.z<5.5)
  89. o *= CCSampleWithAlphaSeparated(texture5, uv0.xy);
  90. else if(uv0.z<6.5)
  91. o *= CCSampleWithAlphaSeparated(texture6, uv0.xy);
  92. else
  93. o *= CCSampleWithAlphaSeparated(texture7, uv0.xy);
  94. #if IS_GRAY
  95. float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
  96. o.r = o.g = o.b = gray;
  97. #endif
  98. #endif
  99. o *= color;
  100. ALPHA_TEST(o);
  101. return o;
  102. }
  103. }%