builtin-billboard.effect 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. p2: &p2
  23. <<: *p1
  24. tintColor: { value: [0.5, 0.5, 0.5, 0.5], editor: { type: color } }
  25. techniques:
  26. - name: add
  27. passes:
  28. - vert: vert:vs_main
  29. frag: tinted-fs:add
  30. rasterizerState: *r1
  31. depthStencilState: *d1
  32. blendState: *b1
  33. properties: *p2
  34. - vert: vert:vs_main
  35. frag: tinted-fs:add
  36. phase: deferred-forward
  37. rasterizerState: *r1
  38. depthStencilState: *d1
  39. blendState: *b1
  40. propertyIndex: 0
  41. - name: alpha-blend
  42. passes:
  43. - vert: vert:vs_main
  44. frag: tinted-fs:add
  45. rasterizerState: *r1
  46. depthStencilState: *d1
  47. blendState: *b2
  48. properties: *p2
  49. - vert: vert:vs_main
  50. frag: tinted-fs:add
  51. phase: deferred-forward
  52. rasterizerState: *r1
  53. depthStencilState: *d1
  54. blendState: *b1
  55. propertyIndex: 0
  56. - name: add-multiply
  57. passes:
  58. - vert: vert:vs_main
  59. frag: tinted-fs:multiply
  60. rasterizerState: *r1
  61. depthStencilState: *d1
  62. blendState: *b2
  63. properties: *p2
  64. - vert: vert:vs_main
  65. frag: tinted-fs:multiply
  66. phase: deferred-forward
  67. rasterizerState: *r1
  68. depthStencilState: *d1
  69. blendState: *b2
  70. propertyIndex: 0
  71. - name: add-smooth
  72. passes:
  73. - vert: vert:vs_main
  74. frag: no-tint-fs:addSmooth
  75. rasterizerState: *r1
  76. depthStencilState: *d1
  77. blendState: *b2
  78. properties: *p1
  79. - vert: vert:vs_main
  80. frag: no-tint-fs:addSmooth
  81. phase: deferred-forward
  82. rasterizerState: *r1
  83. depthStencilState: *d1
  84. blendState: *b2
  85. propertyIndex: 0
  86. - name: premultiply-blend
  87. passes:
  88. - vert: vert:vs_main
  89. frag: no-tint-fs:premultiplied
  90. rasterizerState: *r1
  91. depthStencilState: *d1
  92. blendState: *b2
  93. properties: *p1
  94. - vert: vert:vs_main
  95. frag: no-tint-fs:premultiplied
  96. phase: deferred-forward
  97. rasterizerState: *r1
  98. depthStencilState: *d1
  99. blendState: *b2
  100. propertyIndex: 0
  101. }%
  102. // TODO: soft particle
  103. CCProgram vert %{
  104. precision mediump float;
  105. #include <builtin/internal/particle-common>
  106. #pragma define CC_RENDER_MODE RENDER_MODE_BILLBOARD
  107. in vec3 a_position; // center position
  108. in vec2 a_texCoord; // texcoord
  109. in vec4 a_color;
  110. uniform builtin {
  111. vec4 cc_size_rotation;
  112. };
  113. vec4 vs_main() {
  114. vec4 pos = vec4(a_position, 1);
  115. pos = cc_matWorld * pos;
  116. vec2 vertOffset = a_texCoord.xy - 0.5;
  117. computeVertPos(pos, vertOffset, quaternionFromEuler(vec3(0., 0., cc_size_rotation.z)), vec3(cc_size_rotation.xy, 0.), cc_matViewInv);
  118. pos = cc_matViewProj * pos;
  119. uv = a_texCoord.xy;
  120. color = a_color;
  121. return pos;
  122. }
  123. }%
  124. CCProgram tinted-fs %{
  125. precision mediump float;
  126. #include <legacy/output>
  127. #include <builtin/internal/embedded-alpha>
  128. in vec2 uv;
  129. in vec4 color;
  130. uniform sampler2D mainTexture;
  131. uniform FragConstants {
  132. vec4 tintColor;
  133. };
  134. vec4 add () {
  135. vec4 col = 2.0 * color * tintColor * CCSampleWithAlphaSeparated(mainTexture, uv);
  136. return CCFragOutput(col);
  137. }
  138. vec4 multiply () {
  139. vec4 col;
  140. vec4 texColor = CCSampleWithAlphaSeparated(mainTexture, uv);
  141. col.rgb = tintColor.rgb * texColor.rgb * color.rgb * vec3(2.0);
  142. col.a = (1.0 - texColor.a) * (tintColor.a * color.a * 2.0);
  143. return CCFragOutput(col);
  144. }
  145. }%
  146. CCProgram no-tint-fs %{
  147. precision mediump float;
  148. #include <legacy/output>
  149. #include <builtin/internal/embedded-alpha>
  150. in vec2 uv;
  151. in vec4 color;
  152. uniform sampler2D mainTexture;
  153. vec4 addSmooth () {
  154. vec4 col = color * CCSampleWithAlphaSeparated(mainTexture, uv);
  155. col.rgb *= col.a;
  156. return CCFragOutput(col);
  157. }
  158. vec4 premultiplied () {
  159. vec4 col = color * CCSampleWithAlphaSeparated(mainTexture, uv) * color.a;
  160. return CCFragOutput(col);
  161. }
  162. }%