builtin-particle-trail.effect 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. CCEffect %{
  2. temporaries:
  3. b1: &b1
  4. targets:
  5. - blend: true
  6. blendSrc: src_alpha
  7. blendDst: one
  8. blendSrcAlpha: src_alpha
  9. blendDstAlpha: one
  10. b2: &b2
  11. targets:
  12. - blend: true
  13. blendSrc: one
  14. blendDst: one_minus_src_alpha
  15. blendSrcAlpha: one
  16. blendDstAlpha: one_minus_src_alpha
  17. d1: &d1 { depthTest: true, depthWrite: false }
  18. r1: &r1 { cullMode: none }
  19. p1: &p1
  20. mainTexture: { value: grey }
  21. mainTiling_Offset: { value: [1, 1, 0, 0] }
  22. frameTile_velLenScale: { value: [1, 1, 0, 0] }
  23. p2: &p2
  24. <<: *p1
  25. tintColor: { value: [0.5, 0.5, 0.5, 0.5], editor: { type: color } }
  26. techniques:
  27. - name: add
  28. passes:
  29. - vert: builtin/internal/particle-trail:vs_main
  30. frag: tinted-fs:add
  31. rasterizerState: *r1
  32. depthStencilState: *d1
  33. blendState: *b1
  34. properties: *p2
  35. - vert: builtin/internal/particle-trail:vs_main
  36. frag: tinted-fs:add
  37. phase: deferred-forward
  38. rasterizerState: *r1
  39. depthStencilState: *d1
  40. blendState: *b1
  41. propertyIndex: 0
  42. - name: alpha-blend
  43. passes:
  44. - vert: builtin/internal/particle-trail:vs_main
  45. frag: tinted-fs:add
  46. rasterizerState: *r1
  47. depthStencilState: *d1
  48. blendState: *b2
  49. properties: *p2
  50. - vert: builtin/internal/particle-trail:vs_main
  51. frag: tinted-fs:add
  52. phase: deferred-forward
  53. rasterizerState: *r1
  54. depthStencilState: *d1
  55. blendState: *b2
  56. propertyIndex: 0
  57. - name: add-multiply
  58. passes:
  59. - vert: builtin/internal/particle-trail:vs_main
  60. frag: tinted-fs:multiply
  61. rasterizerState: *r1
  62. depthStencilState: *d1
  63. blendState: *b2
  64. properties: *p2
  65. - vert: builtin/internal/particle-trail:vs_main
  66. frag: tinted-fs:multiply
  67. phase: deferred-forward
  68. rasterizerState: *r1
  69. depthStencilState: *d1
  70. blendState: *b2
  71. propertyIndex: 0
  72. - name: add-smooth
  73. passes:
  74. - vert: builtin/internal/particle-trail:vs_main
  75. frag: no-tint-fs:addSmooth
  76. rasterizerState: *r1
  77. depthStencilState: *d1
  78. blendState: *b2
  79. properties: *p1
  80. - vert: builtin/internal/particle-trail:vs_main
  81. frag: no-tint-fs:addSmooth
  82. phase: deferred-forward
  83. rasterizerState: *r1
  84. depthStencilState: *d1
  85. blendState: *b2
  86. propertyIndex: 0
  87. - name: premultiply-blend
  88. passes:
  89. - vert: builtin/internal/particle-trail:vs_main
  90. frag: no-tint-fs:premultiplied
  91. rasterizerState: *r1
  92. depthStencilState: *d1
  93. blendState: *b2
  94. properties: *p1
  95. - vert: builtin/internal/particle-trail:vs_main
  96. frag: no-tint-fs:premultiplied
  97. phase: deferred-forward
  98. rasterizerState: *r1
  99. depthStencilState: *d1
  100. blendState: *b2
  101. propertyIndex: 0
  102. }%
  103. // TODO: soft particle
  104. CCProgram tinted-fs %{
  105. precision mediump float;
  106. #include <legacy/output>
  107. #include <builtin/internal/embedded-alpha>
  108. in vec2 uv;
  109. in vec4 color;
  110. #if CC_DRAW_WIRE_FRAME
  111. in vec3 vBarycentric;
  112. #endif
  113. uniform sampler2D mainTexture;
  114. uniform FragConstants {
  115. vec4 tintColor;
  116. };
  117. vec4 add () {
  118. vec4 col = 2.0 * color * tintColor * CCSampleWithAlphaSeparated(mainTexture, uv);
  119. #if CC_DRAW_WIRE_FRAME
  120. if (any(lessThan(vBarycentric, vec3(0.02)))) {
  121. col = vec4(0., 1., 1., 1.);
  122. }
  123. #endif
  124. return CCFragOutput(col);
  125. }
  126. vec4 multiply () {
  127. vec4 col;
  128. vec4 texColor = CCSampleWithAlphaSeparated(mainTexture, uv);
  129. col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);
  130. col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);
  131. #if CC_DRAW_WIRE_FRAME
  132. if (any(lessThan(vBarycentric, vec3(0.02)))) {
  133. col = vec4(0., 1., 1., col.a);
  134. }
  135. #endif
  136. return CCFragOutput(col);
  137. }
  138. }%
  139. CCProgram no-tint-fs %{
  140. precision mediump float;
  141. #include <legacy/output>
  142. #include <builtin/internal/embedded-alpha>
  143. in vec2 uv;
  144. in vec4 color;
  145. uniform sampler2D mainTexture;
  146. vec4 addSmooth () {
  147. vec4 col = color * CCSampleWithAlphaSeparated(mainTexture, uv);
  148. col.rgb *= col.a;
  149. return CCFragOutput(col);
  150. }
  151. vec4 premultiplied () {
  152. vec4 col = color * CCSampleWithAlphaSeparated(mainTexture, uv) * color.a;
  153. return CCFragOutput(col);
  154. }
  155. }%