light-probe-visualization.effect 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. - vert: gizmo-vs:vert
  21. frag: gizmo-fs:back
  22. priority: max - 10
  23. rasterizerState:
  24. cullMode: none
  25. depthStencilState: *disable_depth
  26. blendState: *enable_blend
  27. }%
  28. CCProgram gizmo-vs %{
  29. precision mediump float;
  30. #include <builtin/uniforms/cc-local>
  31. #include <builtin/uniforms/cc-global>
  32. in vec3 a_position;
  33. in vec3 a_normal;
  34. out vec3 normal_w;
  35. out vec3 pos_w;
  36. out vec3 pos_l;
  37. out vec3 right;
  38. out vec3 up;
  39. out vec3 forward;
  40. vec4 vert () {
  41. vec4 pos = vec4(a_position, 1);
  42. vec4 normal = vec4(a_normal, 0);
  43. pos_l = a_position;
  44. pos_w = (cc_matWorld * pos).xyz;
  45. normal_w = (cc_matWorldIT * normal).xyz;
  46. right = vec3(cc_matView[0][0], cc_matView[1][0], cc_matView[2][0]);
  47. up = vec3(cc_matView[0][1], cc_matView[1][1], cc_matView[2][1]);
  48. forward = vec3(cc_matView[0][2], cc_matView[1][2], cc_matView[2][2]);
  49. return cc_matProj * (cc_matView * cc_matWorld) * pos;
  50. }
  51. }%
  52. CCProgram gizmo-fs %{
  53. precision mediump float;
  54. #include <common/lighting/rect-area-light>
  55. #include <builtin/uniforms/cc-global>
  56. #include <common/color/gamma>
  57. #if CC_USE_LIGHT_PROBE
  58. #include <legacy/output-standard>
  59. #else
  60. #include <legacy/output>
  61. #endif
  62. in vec3 normal_w;
  63. in vec3 pos_w;
  64. in vec3 pos_l;
  65. in vec3 right;
  66. in vec3 up;
  67. in vec3 forward;
  68. uniform Constant {
  69. vec4 mainColor;
  70. // SH coefficents used for light probe visualization
  71. vec4 cc_sh_linear_const_r;
  72. vec4 cc_sh_linear_const_g;
  73. vec4 cc_sh_linear_const_b;
  74. vec4 cc_sh_quadratic_r;
  75. vec4 cc_sh_quadratic_g;
  76. vec4 cc_sh_quadratic_b;
  77. vec4 cc_sh_quadratic_a;
  78. };
  79. #if CC_USE_LIGHT_PROBE
  80. #include <builtin/functionalities/sh>
  81. #endif
  82. vec4 gizmo_fs (float alpha) {
  83. #if CC_USE_LIGHT_PROBE
  84. vec3 N = normalize(normal_w) * (float(gl_FrontFacing) * 2.0 - 1.0);
  85. vec3 diffuse = SHEvaluate(N);
  86. #if USE_FORWARD_PIPELINE
  87. return CCFragOutput(vec4(diffuse, mainColor.a * alpha));
  88. #else
  89. return vec4(diffuse, mainColor.a * alpha);
  90. #endif
  91. #else
  92. vec3 N = normalize(normal_w) * (float(gl_FrontFacing) * 2.0 - 1.0);
  93. vec3 V = normalize(cc_cameraPos.xyz - pos_w);
  94. // vec3 L = normalize(cross(forward, vec3(0, 1, 0)));
  95. // vec3 diffuse = color.rgb * (0.2 + max(0.0, dot(N, L)) * 0.8);
  96. vec3 points [4];
  97. //vec3 up = vec3(0, 1, 0);
  98. points[0] = (forward * 3.0 + right + up) * 40.0;
  99. points[1] = (forward * 3.0 - right + up) * 40.0;
  100. points[2] = (forward * 3.0 - right - up) * 40.0;
  101. points[3] = (forward * 3.0 + right - up) * 40.0;
  102. vec3 diffuse = LinearToSRGB(mainColor.rgb * LTC_Evaluate(N, V, pos_l, mat3(1), points));
  103. #if USE_FORWARD_PIPELINE
  104. return CCFragOutput(vec4(diffuse, mainColor.a * alpha));
  105. #else
  106. return vec4(diffuse, mainColor.a * alpha);
  107. #endif
  108. #endif
  109. }
  110. vec4 front () {
  111. return gizmo_fs(1.0);
  112. }
  113. vec4 back () {
  114. return gizmo_fs(0.2);
  115. }
  116. }%