builtin-geometry-renderer.effect 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. CCEffect %{
  2. techniques:
  3. - passes:
  4. - vert: line-vs:vert
  5. frag: line-fs:front
  6. priority: max - 10
  7. primitive: LINE_LIST
  8. depthStencilState: &disable_depth
  9. depthTest: false
  10. depthWrite: false
  11. blendState: &enable_blend
  12. targets:
  13. - blend: true
  14. blendSrc: src_alpha
  15. blendDst: one_minus_src_alpha
  16. blendDstAlpha: one_minus_src_alpha
  17. - passes:
  18. - vert: line-vs:vert
  19. frag: line-fs:front
  20. priority: max - 10
  21. primitive: LINE_LIST
  22. depthStencilState:
  23. depthTest: true
  24. depthWrite: false
  25. blendState: *enable_blend
  26. - vert: line-vs:vert
  27. frag: line-fs:back
  28. priority: max - 10
  29. primitive: LINE_LIST
  30. depthStencilState:
  31. depthTest: true
  32. depthWrite: false
  33. depthFunc: greater
  34. blendState: *enable_blend
  35. - passes:
  36. - vert: dashed-line-vs:vert
  37. frag: dashed-line-fs:front
  38. priority: max - 10
  39. primitive: LINE_LIST
  40. depthStencilState: &disable_depth
  41. depthTest: false
  42. depthWrite: false
  43. blendState: &enable_blend
  44. targets:
  45. - blend: true
  46. blendSrc: src_alpha
  47. blendDst: one_minus_src_alpha
  48. blendDstAlpha: one_minus_src_alpha
  49. - passes:
  50. - vert: dashed-line-vs:vert
  51. frag: dashed-line-fs:front
  52. priority: max - 10
  53. primitive: LINE_LIST
  54. depthStencilState:
  55. depthTest: true
  56. depthWrite: false
  57. blendState: *enable_blend
  58. - vert: dashed-line-vs:vert
  59. frag: dashed-line-fs:back
  60. priority: max - 10
  61. primitive: LINE_LIST
  62. depthStencilState:
  63. depthTest: true
  64. depthWrite: false
  65. depthFunc: greater
  66. blendState: *enable_blend
  67. - passes:
  68. - vert: triangle-vs:vert
  69. frag: triangle-fs:front
  70. priority: max - 10
  71. rasterizerState:
  72. cullMode: back
  73. depthStencilState: *disable_depth
  74. blendState: *enable_blend
  75. - passes:
  76. - vert: triangle-vs:vert
  77. frag: triangle-fs:front
  78. priority: max - 10
  79. rasterizerState:
  80. cullMode: back
  81. depthStencilState:
  82. depthTest: true
  83. depthWrite: false
  84. blendState: *enable_blend
  85. - vert: triangle-vs:vert
  86. frag: triangle-fs:back
  87. priority: max - 10
  88. rasterizerState:
  89. cullMode: back
  90. depthStencilState:
  91. depthTest: true
  92. depthWrite: false
  93. depthFunc: greater
  94. blendState: *enable_blend
  95. }%
  96. CCProgram line-vs %{
  97. precision mediump float;
  98. #include <builtin/uniforms/cc-global>
  99. in highp vec3 a_position;
  100. in vec4 a_color;
  101. out vec4 v_color;
  102. vec4 vert () {
  103. vec4 pos = cc_matViewProj * vec4(a_position, 1);
  104. pos.z -= 0.000001;
  105. v_color = a_color;
  106. return pos;
  107. }
  108. }%
  109. CCProgram line-fs %{
  110. precision mediump float;
  111. #include <legacy/output>
  112. in vec4 v_color;
  113. vec4 front() {
  114. #if USE_FORWARD_PIPELINE
  115. return CCFragOutput(v_color);
  116. #else
  117. return v_color;
  118. #endif
  119. }
  120. vec4 back() {
  121. #if USE_FORWARD_PIPELINE
  122. return CCFragOutput(vec4(v_color.rgb, v_color.a * 0.2));
  123. #else
  124. return vec4(v_color.rgb, v_color.a * 0.2);
  125. #endif
  126. }
  127. }%
  128. CCProgram dashed-line-vs %{
  129. precision mediump float;
  130. #include <builtin/uniforms/cc-global>
  131. in highp vec3 a_position;
  132. in vec4 a_color;
  133. out vec4 v_color;
  134. out float v_distance;
  135. vec4 vert () {
  136. vec4 pos = cc_matViewProj * vec4(a_position, 1);
  137. pos.z -= 0.000001;
  138. v_color = a_color;
  139. v_distance = dot(a_position, vec3(1.0, 1.0, 1.0));
  140. return pos;
  141. }
  142. }%
  143. CCProgram dashed-line-fs %{
  144. precision mediump float;
  145. #include <legacy/output>
  146. in vec4 v_color;
  147. in float v_distance;
  148. vec4 front() {
  149. if (fract(v_distance) > 0.5) {
  150. discard;
  151. }
  152. #if USE_FORWARD_PIPELINE
  153. return CCFragOutput(v_color);
  154. #else
  155. return v_color;
  156. #endif
  157. }
  158. vec4 back() {
  159. if (fract(v_distance) > 0.5) {
  160. discard;
  161. }
  162. #if USE_FORWARD_PIPELINE
  163. return CCFragOutput(vec4(v_color.rgb, v_color.a * 0.2));
  164. #else
  165. return vec4(v_color.rgb, v_color.a * 0.2);
  166. #endif
  167. }
  168. }%
  169. CCProgram triangle-vs %{
  170. precision mediump float;
  171. #include <builtin/uniforms/cc-global>
  172. in highp vec3 a_position;
  173. in vec4 a_normal;
  174. in vec4 a_color;
  175. out vec4 v_color;
  176. vec4 vert () {
  177. vec4 pos = cc_matViewProj * vec4(a_position, 1);
  178. v_color = a_color;
  179. // fake lighting: a_normal.w is 1 for lit, 0 for unlit
  180. float intensity = dot(vec3(1, 2, 4), a_normal.xyz);
  181. v_color.rgb -= a_normal.w * intensity * 0.1;
  182. return pos;
  183. }
  184. }%
  185. CCProgram triangle-fs %{
  186. precision mediump float;
  187. #include <legacy/output>
  188. in vec4 v_color;
  189. vec4 front() {
  190. #if USE_FORWARD_PIPELINE
  191. return CCFragOutput(v_color);
  192. #else
  193. return v_color;
  194. #endif
  195. }
  196. vec4 back() {
  197. #if USE_FORWARD_PIPELINE
  198. return CCFragOutput(vec4(v_color.rgb, v_color.a * 0.2));
  199. #else
  200. return vec4(v_color.rgb, v_color.a * 0.2);
  201. #endif
  202. }
  203. }%