builtin-particle-gpu.effect 4.0 KB

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