planar-shadow.effect 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: planar-shadow-vs:vert
  6. frag: planar-shadow-fs:frag
  7. phase: planarShadow
  8. depthStencilState:
  9. depthTest: true
  10. depthWrite: false
  11. stencilTestFront: true
  12. stencilFuncFront: not_equal
  13. stencilPassOpFront: replace
  14. stencilRef: 0x80 # only use the leftmost bit
  15. stencilReadMask: 0x80
  16. stencilWriteMask: 0x80
  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 planar-shadow-vs %{
  25. precision highp float;
  26. #include <legacy/input>
  27. #include <builtin/uniforms/cc-global>
  28. #include <legacy/decode-base>
  29. #include <legacy/local-batch>
  30. #include <builtin/uniforms/cc-shadow>
  31. #include <common/lighting/functions>
  32. out float v_dist;
  33. vec4 vert () {
  34. vec4 position;
  35. CCVertInput(position);
  36. // World Space
  37. mat4 matWorld, matWorldIT;
  38. CCGetWorldMatrixFull(matWorld, matWorldIT);
  39. vec3 worldPos = (matWorld * position).xyz;
  40. vec4 shadowPos = CalculatePlanarShadowPos(worldPos, cc_cameraPos.xyz, cc_mainLitDir.xyz, cc_planarNDInfo);
  41. position = CalculatePlanarShadowClipPos(shadowPos, cc_cameraPos.xyz, cc_matView, cc_matProj, cc_nearFar, cc_shadowWHPBInfo.w);
  42. v_dist = shadowPos.w;
  43. return position;
  44. }
  45. }%
  46. CCProgram planar-shadow-fs %{
  47. precision highp float;
  48. #include <builtin/uniforms/cc-shadow>
  49. #include <legacy/output>
  50. in float v_dist;
  51. vec4 frag () {
  52. if(v_dist < 0.0)
  53. discard;
  54. return CCFragOutput(cc_shadowColor);
  55. }
  56. }%