ShadowDepthBase.bslinc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "$ENGINE$\PerObjectData.bslinc"
  2. #include "$ENGINE$\SkinnedVertexInput.bslinc"
  3. #include "$ENGINE$\NormalVertexInput.bslinc"
  4. #define USE_BLEND_SHAPES
  5. #include "$ENGINE$\SkinnedVertexInput.bslinc"
  6. #include "$ENGINE$\NormalVertexInput.bslinc"
  7. #undef USE_BLEND_SHAPES
  8. Technique : base("ShadowDepthBase") =
  9. {
  10. Pass =
  11. {
  12. Common =
  13. {
  14. struct ShadowVStoFS
  15. {
  16. float4 position : SV_Position;
  17. #ifdef USES_GS
  18. float4 worldPos : TEXCOORD0;
  19. #endif
  20. };
  21. cbuffer ShadowParams
  22. {
  23. float4x4 gMatViewProj;
  24. float gDepthBias;
  25. float gDepthRange;
  26. };
  27. };
  28. Vertex =
  29. {
  30. void linearizeDepth(inout float4 clipPos)
  31. {
  32. // Clamp to near plane if behind it
  33. if (clipPos.z < 0)
  34. {
  35. clipPos.z = 0.000001f;
  36. clipPos.w = 1.0f;
  37. }
  38. // Output linear depth in range [0, 1]
  39. // TODO - Handle case for backends using [-1, 1] depth range
  40. #if LINEAR_DEPTH_RANGE
  41. float linearDepth = clipPos.z * gDepthRange + gDepthBias;
  42. clipPos.z = linearDepth * clipPos.w;
  43. #endif
  44. }
  45. ShadowVStoFS main(VertexInput_PO input)
  46. {
  47. ShadowVStoFS output;
  48. float4 worldPosition = getVertexWorldPosition(input);
  49. #ifdef USES_GS
  50. output.worldPos = worldPosition;
  51. output.position = worldPosition;
  52. #else
  53. float4 clipPos = mul(gMatViewProj, worldPosition);
  54. linearizeDepth(clipPos);
  55. output.position = clipPos;
  56. #endif
  57. return output;
  58. }
  59. };
  60. };
  61. };
  62. Technique
  63. : inherits("PerObjectData")
  64. : inherits("NormalVertexInput")
  65. : inherits("ShadowDepthBase")
  66. : inherits("ShadowDepth") =
  67. {
  68. };
  69. Technique
  70. : inherits("PerObjectData")
  71. : inherits("SkinnedVertexInput")
  72. : inherits("ShadowDepthBase")
  73. : inherits("ShadowDepth") =
  74. {
  75. Tags = { "Skinned" };
  76. };
  77. Technique
  78. : inherits("PerObjectData")
  79. : inherits("MorphVertexInput")
  80. : inherits("ShadowDepthBase")
  81. : inherits("ShadowDepth") =
  82. {
  83. Tags = { "Morph" };
  84. };
  85. Technique
  86. : inherits("PerObjectData")
  87. : inherits("SkinnedMorphVertexInput")
  88. : inherits("ShadowDepthBase")
  89. : inherits("ShadowDepth") =
  90. {
  91. Tags = { "SkinnedMorph" };
  92. };