Mult-effect.effect 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. texture1: { value: white}
  21. texture2: { value: white}
  22. texture3: { value: white}
  23. texture4: { value: white}
  24. texture5: { value: white}
  25. texture6: { value: white}
  26. texture7: { value: white}
  27. }%
  28. CCProgram sprite-vs %{
  29. precision highp float;
  30. #include <builtin/uniforms/cc-global>
  31. #if USE_LOCAL
  32. #include <builtin/uniforms/cc-local>
  33. #endif
  34. #if SAMPLE_FROM_RT
  35. #include <common/common-define>
  36. #endif
  37. in vec3 a_position;
  38. in vec2 a_texCoord;
  39. in vec4 a_color;
  40. out lowp vec4 color;
  41. out mediump vec3 uv0;
  42. vec4 vert () {
  43. vec4 pos = vec4(a_position, 1);
  44. #if USE_LOCAL
  45. pos = cc_matWorld * pos;
  46. #endif
  47. #if USE_PIXEL_ALIGNMENT
  48. pos = cc_matView * pos;
  49. pos.xyz = floor(pos.xyz);
  50. pos = cc_matProj * pos;
  51. #else
  52. pos = cc_matViewProj * pos;
  53. #endif
  54. uv0.y = a_texCoord.y;
  55. uv0.z = mod(a_texCoord.x,10.0);
  56. //uv0.z = fract(a_texCoord.x*0.1);
  57. //uv0.z = floor(uv0.z*10.0+0.1);
  58. uv0.x = (a_texCoord.x-uv0.z)*0.000001;
  59. #if SAMPLE_FROM_RT
  60. CC_HANDLE_RT_SAMPLE_FLIP(uv0.xy);
  61. #endif
  62. color = a_color;
  63. return pos;
  64. }
  65. }%
  66. CCProgram sprite-fs %{
  67. precision mediump float;
  68. #include <builtin/internal/embedded-alpha>
  69. #include <builtin/internal/alpha-test>
  70. in lowp vec4 color;
  71. #if USE_TEXTURE
  72. in mediump vec3 uv0;
  73. #pragma builtin(local)
  74. layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
  75. uniform sampler2D texture1;
  76. uniform sampler2D texture2;
  77. uniform sampler2D texture3;
  78. uniform sampler2D texture4;
  79. uniform sampler2D texture5;
  80. uniform sampler2D texture6;
  81. uniform sampler2D texture7;
  82. #endif
  83. vec4 frag () {
  84. vec4 o = vec4(1, 1, 1, 1);
  85. #if USE_TEXTURE
  86. if(uv0.z == 0.0)
  87. o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0.xy);
  88. else if(uv0.z == 1.0)
  89. o *= CCSampleWithAlphaSeparated(texture1, uv0.xy);
  90. else if(uv0.z == 2.0)
  91. o *= CCSampleWithAlphaSeparated(texture2, uv0.xy);
  92. else if(uv0.z == 3.0)
  93. o *= CCSampleWithAlphaSeparated(texture3, uv0.xy);
  94. else if(uv0.z == 4.0)
  95. o *= CCSampleWithAlphaSeparated(texture4, uv0.xy);
  96. else if(uv0.z == 5.0)
  97. o *= CCSampleWithAlphaSeparated(texture5, uv0.xy);
  98. else if(uv0.z == 6.0)
  99. o *= CCSampleWithAlphaSeparated(texture6, uv0.xy);
  100. else
  101. o *= CCSampleWithAlphaSeparated(texture7, uv0.xy);
  102. #if IS_GRAY
  103. float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
  104. o.r = o.g = o.b = gray;
  105. #endif
  106. #endif
  107. o *= color;
  108. ALPHA_TEST(o);
  109. return o;
  110. }
  111. }%