effect-texture_move.effect 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Copyright (c) 2017-2018 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. noiseTexture: { value: black }
  10. mainTexture: { value: grey }
  11. textureMoveSpeed: { value: [0, 0] }
  12. tilingOffset: { value: [1, 1, 0, 0] }
  13. noiseStrength: { value: [1, 1] }
  14. noiseMoveSpeed: { value: [0, 0] }
  15. mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
  16. colorScale: { value: [1, 1, 1], target: colorScaleAndCutoff.xyz }
  17. alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  18. color: { target: mainColor, editor: { visible: false } } # backward compability
  19. migrations: &migs
  20. properties:
  21. mainColor: { formerlySerializedAs: color }
  22. - name: transparent
  23. passes:
  24. - vert: unlit-vs:vert
  25. frag: unlit-fs:frag
  26. depthStencilState: &d1
  27. depthTest: true
  28. depthWrite: false
  29. blendState:
  30. targets:
  31. - blend: true
  32. blendSrc: src_alpha
  33. blendDst: one_minus_src_alpha
  34. blendDstAlpha: one_minus_src_alpha
  35. properties: *props
  36. migrations: *migs
  37. - name: add
  38. passes:
  39. - vert: unlit-vs:vert
  40. frag: unlit-fs:frag
  41. rasterizerState: &r1 { cullMode: none }
  42. depthStencilState: *d1
  43. blendState:
  44. targets:
  45. - blend: true
  46. blendSrc: src_alpha
  47. blendDst: one
  48. blendSrcAlpha: src_alpha
  49. blendDstAlpha: one
  50. properties: *props
  51. migrations: *migs
  52. - name: alpha-blend
  53. passes:
  54. - vert: unlit-vs:vert
  55. frag: unlit-fs:frag
  56. rasterizerState: *r1
  57. depthStencilState: *d1
  58. blendState:
  59. targets:
  60. - blend: true
  61. blendSrc: src_alpha
  62. blendDst: one_minus_src_alpha
  63. blendSrcAlpha: src_alpha
  64. blendDstAlpha: one_minus_src_alpha
  65. properties: *props
  66. migrations: *migs
  67. }%
  68. CCProgram unlit-vs %{
  69. precision highp float;
  70. #include <input>
  71. #include <cc-global>
  72. #include <cc-local-batch>
  73. #if USE_VERTEX_COLOR
  74. in vec4 a_color;
  75. out vec4 v_color;
  76. #endif
  77. #if USE_TEXTURE
  78. in vec2 a_texCoord;
  79. out vec2 v_uv;
  80. out vec2 screen_uv;
  81. uniform TexCoords {
  82. vec4 tilingOffset;
  83. };
  84. #endif
  85. vec4 vert () {
  86. vec4 position;
  87. CCVertInput(position);
  88. mat4 matWorld;
  89. CCGetWorldMatrix(matWorld);
  90. #if USE_TEXTURE
  91. vec2 uv = a_texCoord;
  92. #if FLIP_UV
  93. uv.y = 1.0 - v_uv.y;
  94. #endif
  95. v_uv = uv * tilingOffset.xy + tilingOffset.zw;
  96. #endif
  97. #if USE_VERTEX_COLOR
  98. v_color = a_color;
  99. #endif
  100. vec4 outPos = cc_matProj * (cc_matView * matWorld) * position;
  101. screen_uv.x = (outPos.x / outPos.z + 1.0) * 0.5;
  102. screen_uv.y = 1.0 - (outPos.y / outPos.z + 1.0) * 0.5;
  103. return outPos;
  104. }
  105. }%
  106. CCProgram unlit-fs %{
  107. precision mediump float;
  108. #include <output>
  109. #if USE_ALPHA_TEST
  110. #pragma define ALPHA_TEST_CHANNEL options([a, r, g, b])
  111. #endif
  112. #if USE_TEXTURE
  113. in vec2 v_uv;
  114. uniform sampler2D mainTexture;
  115. #if USE_TEXTURE_MOVE
  116. uniform ConstTextureMove{
  117. vec2 textureMoveSpeed;
  118. };
  119. #endif
  120. #endif
  121. #if USE_NOISE_TEXTURE
  122. uniform sampler2D noiseTexture;
  123. uniform ConstNoiseTexture{
  124. vec2 noiseStrength;
  125. };
  126. #if USE_NOISE_MOVE
  127. uniform ConstNoiseMove{
  128. vec2 noiseMoveSpeed;
  129. };
  130. #endif
  131. #endif
  132. uniform Constant {
  133. vec4 mainColor;
  134. vec4 colorScaleAndCutoff;
  135. };
  136. #if USE_VERTEX_COLOR
  137. in vec4 v_color;
  138. #endif
  139. vec4 frag () {
  140. vec4 o = mainColor;
  141. o.rgb *= colorScaleAndCutoff.xyz;
  142. #if USE_VERTEX_COLOR
  143. o *= v_color;
  144. #endif
  145. #if USE_TEXTURE
  146. vec2 uv = v_uv;
  147. #if USE_TEXTURE_MOVE
  148. uv.x = uv.x + cc_time.x * textureMoveSpeed.x;
  149. uv.y = uv.y + cc_time.x * textureMoveSpeed.y;
  150. #endif
  151. #if USE_NOISE_TEXTURE
  152. vec2 noise_uv = v_uv;
  153. #if USE_NOISE_MOVE
  154. vec2 speed = vec2(cc_time.x * noiseMoveSpeed.x ,cc_time.x * noiseMoveSpeed.y);
  155. noise_uv.xy = v_uv.xy + speed.xy;
  156. #endif
  157. vec4 offset = texture(noiseTexture,noise_uv);
  158. uv.x = uv.x + (offset.x - 0.5) * noiseStrength.x;
  159. uv.y = uv.y + (offset.y - 0.5) * noiseStrength.y;
  160. #endif
  161. o *= texture(mainTexture, uv);
  162. #endif
  163. #if USE_ALPHA_TEST
  164. if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
  165. #endif
  166. return CCFragOutput(o);
  167. }
  168. }%