ShadowDepthBase.bslinc 2.3 KB

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