gizmo.effect 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. CCEffect %{
  2. editor:
  3. hide: true
  4. techniques:
  5. - passes:
  6. - vert: gizmo-vs:vert
  7. frag: gizmo-fs:front
  8. priority: max - 10
  9. rasterizerState:
  10. cullMode: none
  11. depthStencilState: &disable_depth
  12. depthTest: false
  13. depthWrite: false
  14. blendState: &enable_blend
  15. targets:
  16. - blend: true
  17. blendSrc: src_alpha
  18. blendDst: one_minus_src_alpha
  19. blendDstAlpha: one_minus_src_alpha
  20. - passes:
  21. - vert: line-vs:vert
  22. frag: line-fs:front
  23. priority: max - 10
  24. rasterizerState:
  25. cullMode: none
  26. depthStencilState: *disable_depth
  27. blendState: *enable_blend
  28. - passes:
  29. - vert: line-vs:vert
  30. frag: line-fs:front
  31. priority: max - 10
  32. depthStencilState:
  33. depthTest: true
  34. depthWrite: false
  35. blendState: *enable_blend
  36. - vert: line-vs:vert
  37. frag: line-fs:back
  38. priority: max - 10
  39. depthStencilState:
  40. depthTest: true
  41. depthWrite: false
  42. depthFunc: greater
  43. blendState: *enable_blend
  44. - passes:
  45. - vert: sprite-vs:vert
  46. frag: sprite-fs:frag
  47. priority: max - 10
  48. rasterizerState:
  49. cullMode: none
  50. depthStencilState: *disable_depth
  51. blendState: *enable_blend
  52. - passes:
  53. - vert: gizmo-vs:vert
  54. frag: gizmo-fs:front
  55. priority: max - 10
  56. rasterizerState:
  57. cullMode: none
  58. depthStencilState:
  59. depthTest: true
  60. depthWrite: false
  61. blendState: *enable_blend
  62. - vert: gizmo-vs:vert
  63. frag: gizmo-fs:back
  64. priority: max - 10
  65. rasterizerState:
  66. cullMode: none
  67. depthStencilState:
  68. depthTest: true
  69. depthWrite: false
  70. depthFunc: greater
  71. blendState: *enable_blend
  72. }%
  73. CCProgram gizmo-vs %{
  74. precision mediump float;
  75. #include <builtin/uniforms/cc-local>
  76. #include <builtin/uniforms/cc-global>
  77. in vec3 a_position;
  78. in vec3 a_normal;
  79. out vec3 normal_w;
  80. out vec3 pos_w;
  81. out vec3 pos_l;
  82. out vec3 right;
  83. out vec3 up;
  84. out vec3 forward;
  85. vec4 vert () {
  86. vec4 pos = vec4(a_position, 1);
  87. vec4 normal = vec4(a_normal, 0);
  88. pos_l = a_position;
  89. pos_w = (cc_matWorld * pos).xyz;
  90. normal_w = (cc_matWorldIT * normal).xyz;
  91. right = vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]);
  92. up = vec3(cc_matView[0][1], cc_matView[1][1], cc_matView[2][1]);
  93. forward = vec3(cc_matView[0][2], cc_matView[1][2], cc_matView[2][2]);
  94. return cc_matProj * (cc_matView * cc_matWorld) * pos;
  95. }
  96. }%
  97. CCProgram gizmo-fs %{
  98. precision mediump float;
  99. #include <common/lighting/rect-area-light>
  100. #include <builtin/uniforms/cc-global>
  101. #include <common/color/gamma>
  102. #include <legacy/output>
  103. in vec3 normal_w;
  104. in vec3 pos_w;
  105. in vec3 pos_l;
  106. in vec3 right;
  107. in vec3 up;
  108. in vec3 forward;
  109. uniform Constant {
  110. vec4 mainColor;
  111. // SH coefficents used for light probe visualization
  112. vec4 cc_sh_linear_const_r;
  113. vec4 cc_sh_linear_const_g;
  114. vec4 cc_sh_linear_const_b;
  115. vec4 cc_sh_quadratic_r;
  116. vec4 cc_sh_quadratic_g;
  117. vec4 cc_sh_quadratic_b;
  118. vec4 cc_sh_quadratic_a;
  119. };
  120. vec4 gizmo_fs (float alpha) {
  121. vec3 N = normalize(normal_w) * (float(gl_FrontFacing) * 2.0 - 1.0);
  122. vec3 V = normalize(cc_cameraPos.xyz - pos_w);
  123. vec3 points [4];
  124. points[0] = (forward * 3.0 + right + up) * 40.0;
  125. points[1] = (forward * 3.0 - right + up) * 40.0;
  126. points[2] = (forward * 3.0 - right - up) * 40.0;
  127. points[3] = (forward * 3.0 + right - up) * 40.0;
  128. vec3 diffuse = LinearToSRGB(mainColor.rgb * LTC_Evaluate(N, V, pos_l, mat3(1), points));
  129. #if USE_FORWARD_PIPELINE
  130. return CCFragOutput(vec4(diffuse, mainColor.a * alpha));
  131. #else
  132. return vec4(diffuse, mainColor.a * alpha);
  133. #endif
  134. }
  135. vec4 front () {
  136. return gizmo_fs(1.0);
  137. }
  138. vec4 back () {
  139. return gizmo_fs(0.2);
  140. }
  141. }%
  142. CCProgram line-vs %{
  143. precision mediump float;
  144. #include <builtin/uniforms/cc-local>
  145. #include <builtin/uniforms/cc-global>
  146. in highp vec3 a_position;
  147. #if USE_DASHED_LINE
  148. in float a_lineDistance;
  149. out float lineDistance;
  150. #endif
  151. vec4 vert () {
  152. vec4 pos = cc_matProj * (cc_matView * cc_matWorld) * vec4(a_position, 1);
  153. pos.z -= 0.000001;
  154. #if USE_DASHED_LINE
  155. lineDistance = a_lineDistance;
  156. #endif
  157. return pos;
  158. }
  159. }%
  160. CCProgram line-fs %{
  161. precision mediump float;
  162. #include <legacy/output>
  163. uniform Constant {
  164. vec4 mainColor;
  165. };
  166. in float lineDistance;
  167. vec4 front() {
  168. #if USE_FORWARD_PIPELINE
  169. return CCFragOutput(mainColor);
  170. #else
  171. #if USE_DASHED_LINE
  172. if (mod(lineDistance, 10.0) > 5.0) {
  173. discard;
  174. }
  175. #endif
  176. return mainColor;
  177. #endif
  178. }
  179. vec4 back() {
  180. #if USE_FORWARD_PIPELINE
  181. return CCFragOutput(vec4(mainColor.rgb, mainColor.a * 0.2));
  182. #else
  183. return vec4(mainColor.rgb, mainColor.a * 0.2);
  184. #endif
  185. }
  186. }%
  187. CCProgram sprite-vs %{
  188. precision mediump float;
  189. #include <builtin/uniforms/cc-local>
  190. #include <builtin/uniforms/cc-global>
  191. in vec3 a_position;
  192. in vec2 a_texCoord;
  193. out vec2 uv0;
  194. vec4 vert () {
  195. vec4 pos = vec4(a_position, 1);
  196. pos = cc_matProj * (cc_matView * cc_matWorld) * pos;
  197. uv0 = a_texCoord;
  198. return pos;
  199. }
  200. }%
  201. CCProgram sprite-fs %{
  202. precision mediump float;
  203. #include <builtin/uniforms/cc-global>
  204. in vec2 uv0;
  205. uniform Constant {
  206. vec4 mainColor;
  207. };
  208. uniform sampler2D mainTexture;
  209. vec4 frag () {
  210. vec4 o = vec4(1, 1, 1, 1);
  211. o *= texture(mainTexture, uv0);
  212. o *= mainColor;
  213. return o;
  214. }
  215. }%