box-height-light.effect 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. CCEffect %{
  2. editor:
  3. hide: true
  4. techniques:
  5. - passes:
  6. - vert: line-vs:vert
  7. frag: line-fs:front
  8. properties:
  9. selectedColor: { value: [1, 1, 0, 0.0784313] }
  10. selectedFaceForward: { value: [0, 0, 0, 0 ] }
  11. priority: max - 10
  12. rasterizerState:
  13. cullMode: none
  14. depthStencilState:
  15. depthTest: false
  16. depthWrite: false
  17. blendState:
  18. targets:
  19. - blend: true
  20. blendSrc: src_alpha
  21. blendDst: one_minus_src_alpha
  22. blendDstAlpha: one_minus_src_alpha
  23. }%
  24. CCProgram line-vs %{
  25. precision mediump float;
  26. #include <builtin/uniforms/cc-local>
  27. #include <builtin/uniforms/cc-global>
  28. in highp vec3 a_position;
  29. in vec3 a_normal;
  30. out vec3 normal;
  31. #if USE_DASHED_LINE
  32. in float a_lineDistance;
  33. out float lineDistance;
  34. #endif
  35. vec4 vert () {
  36. normal = a_normal;
  37. vec4 pos = cc_matProj * (cc_matView * cc_matWorld) * vec4(a_position, 1);
  38. pos.z -= 0.000001;
  39. #if USE_DASHED_LINE
  40. lineDistance = a_lineDistance;
  41. #endif
  42. return pos;
  43. }
  44. }%
  45. CCProgram line-fs %{
  46. precision mediump float;
  47. #include <legacy/output>
  48. in vec3 normal;
  49. in float lineDistance;
  50. uniform Constant {
  51. vec4 mainColor;
  52. vec4 selectedColor;
  53. vec4 selectedFaceForward;
  54. };
  55. vec4 front() {
  56. vec4 outputColor = mainColor;
  57. // dot
  58. vec3 d = normal.xyz * selectedFaceForward.xyz;
  59. float m = max(max(d.x, d.y), d.z);
  60. float selected = step(0.9999,m);
  61. outputColor = selected==1. ? selectedColor : mainColor ;
  62. #if USE_FORWARD_PIPELINE
  63. return CCFragOutput(outputColor);
  64. #else
  65. #if USE_DASHED_LINE
  66. if (mod(lineDistance, 10.0) > 5.0) {
  67. discard;
  68. }
  69. #endif
  70. return outputColor;
  71. #endif
  72. }
  73. vec4 back() {
  74. #if USE_FORWARD_PIPELINE
  75. return CCFragOutput(vec4(mainColor.rgb, mainColor.a * 0.2));
  76. #else
  77. return vec4(mainColor.rgb, mainColor.a * 0.2);
  78. #endif
  79. }
  80. }%