sequence-anim.effect 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: unlit-vs:vert
  7. frag: unlit-fs:frag
  8. properties: &props
  9. mainTexture: { value: grey }
  10. tilingOffset: { value: [1, 1, 0, 0] }
  11. mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
  12. colorScale: { value: [1, 1, 1], target: colorScaleAndCutoff.xyz }
  13. alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  14. dimensions: { value: [2, 2], target: seqAnimParams.xy }
  15. frames: { value: 4, target: seqAnimParams.z }
  16. speedOrProgress: { value: 10, target: seqAnimParams.w }
  17. migrations: &migs
  18. properties:
  19. dimensions: { formerlySerializedAs: constants.xy }
  20. frames: { formerlySerializedAs: constants.z }
  21. speedOrProgress: { formerlySerializedAs: constants.w }
  22. mainTexture: { formerlySerializedAs: seqTexture }
  23. mainColor: { formerlySerializedAs: weight }
  24. - name: transparent
  25. passes:
  26. - vert: unlit-vs:vert
  27. frag: unlit-fs:frag
  28. depthStencilState: &d1
  29. depthTest: true
  30. depthWrite: false
  31. blendState:
  32. targets:
  33. - blend: true
  34. blendSrc: src_alpha
  35. blendDst: one_minus_src_alpha
  36. blendDstAlpha: one_minus_src_alpha
  37. properties: *props
  38. migrations: *migs
  39. - name: add
  40. passes:
  41. - vert: unlit-vs:vert
  42. frag: unlit-fs:frag
  43. rasterizerState: &r1 { cullMode: none }
  44. depthStencilState: *d1
  45. blendState:
  46. targets:
  47. - blend: true
  48. blendSrc: src_alpha
  49. blendDst: one
  50. blendSrcAlpha: src_alpha
  51. blendDstAlpha: one
  52. properties: *props
  53. migrations: *migs
  54. - name: alpha-blend
  55. passes:
  56. - vert: unlit-vs:vert
  57. frag: unlit-fs:frag
  58. rasterizerState: *r1
  59. depthStencilState: *d1
  60. blendState:
  61. targets:
  62. - blend: true
  63. blendSrc: src_alpha
  64. blendDst: one_minus_src_alpha
  65. blendSrcAlpha: src_alpha
  66. blendDstAlpha: one_minus_src_alpha
  67. properties: *props
  68. migrations: *migs
  69. }%
  70. CCProgram unlit-vs %{
  71. precision highp float;
  72. #include <legacy/input>
  73. #include <builtin/uniforms/cc-global>
  74. #include <legacy/decode-base>
  75. #include <legacy/local-batch>
  76. #if USE_VERTEX_COLOR
  77. in lowp vec4 a_color;
  78. out lowp vec4 v_color;
  79. #endif
  80. #if USE_TEXTURE
  81. out vec2 v_uv;
  82. uniform TexCoords {
  83. vec4 tilingOffset;
  84. };
  85. #if USE_SEQUENCE_ANIM
  86. uniform SeqAnimConstants {
  87. vec4 seqAnimParams;
  88. };
  89. #endif
  90. #endif
  91. vec4 vert () {
  92. vec4 position;
  93. CCVertInput(position);
  94. mat4 matWorld;
  95. CCGetWorldMatrix(matWorld);
  96. #if USE_TEXTURE
  97. v_uv = a_texCoord;
  98. #if FLIP_UV
  99. v_uv.y = 1.0 - v_uv.y;
  100. #endif
  101. v_uv = v_uv * tilingOffset.xy + tilingOffset.zw;
  102. #if USE_SEQUENCE_ANIM
  103. #if MANUAL_PLAYBACK
  104. float seqAnimCurFrame = clamp(seqAnimParams.w, 0.0, 0.999) * seqAnimParams.z;
  105. #else
  106. float seqAnimCurFrame = mod(cc_time.x, seqAnimParams.z / seqAnimParams.w) * seqAnimParams.w; // iOS precision issue
  107. #endif
  108. vec2 seqAnimOffset = floor(vec2(mod(seqAnimCurFrame, seqAnimParams.x), seqAnimCurFrame / seqAnimParams.x));
  109. v_uv = (v_uv + seqAnimOffset) / seqAnimParams.xy;
  110. #endif
  111. #endif
  112. #if USE_VERTEX_COLOR
  113. v_color = a_color;
  114. #endif
  115. return cc_matProj * (cc_matView * matWorld) * position;
  116. }
  117. }%
  118. CCProgram unlit-fs %{
  119. precision highp float;
  120. #include <legacy/output>
  121. #if USE_ALPHA_TEST
  122. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
  123. #endif
  124. #if USE_TEXTURE
  125. in vec2 v_uv;
  126. uniform sampler2D mainTexture;
  127. #endif
  128. uniform Constant {
  129. vec4 mainColor;
  130. vec4 colorScaleAndCutoff;
  131. };
  132. #if USE_VERTEX_COLOR
  133. in lowp vec4 v_color;
  134. #endif
  135. vec4 frag () {
  136. vec4 o = mainColor;
  137. o.rgb *= colorScaleAndCutoff.xyz;
  138. #if USE_VERTEX_COLOR
  139. o *= v_color;
  140. #endif
  141. #if USE_TEXTURE
  142. o *= texture(mainTexture, v_uv);
  143. #endif
  144. #if USE_ALPHA_TEST
  145. if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
  146. #endif
  147. return CCFragOutput(o);
  148. }
  149. }%