ShadowDepthBase.bslinc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. mixin ShadowDepthBase
  11. {
  12. code
  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. float gDepthBias;
  24. float gDepthRange;
  25. };
  26. void linearizeDepth(inout float4 clipPos)
  27. {
  28. // Clamp to near plane if behind it
  29. if (clipPos.z < 0)
  30. {
  31. clipPos.z = 0.000001f;
  32. clipPos.w = 1.0f;
  33. }
  34. // Output linear depth in range [0, 1]
  35. // TODO - Handle case for backends using [-1, 1] depth range
  36. float linearDepth = clipPos.z * gDepthRange + gDepthBias;
  37. clipPos.z = linearDepth * clipPos.w;
  38. }
  39. ShadowVStoFS vsmain(VertexInput_PO input)
  40. {
  41. ShadowVStoFS output;
  42. float4 worldPosition = getVertexWorldPosition(input);
  43. #ifdef USES_GS
  44. output.worldPos = worldPosition;
  45. output.position = worldPosition;
  46. #else
  47. float4 clipPos = mul(gMatViewProj, worldPosition);
  48. linearizeDepth(clipPos);
  49. output.position = clipPos;
  50. #endif
  51. return output;
  52. }
  53. };
  54. };
  55. technique ShadowDepth
  56. {
  57. mixin GBufferOutput;
  58. mixin PerCameraData;
  59. mixin PerObjectData;
  60. mixin NormalVertexInput;
  61. mixin ShadowDepthBase;
  62. mixin ShadowDepth;
  63. };
  64. technique ShadowDepthSkinned
  65. {
  66. mixin GBufferOutput;
  67. mixin PerCameraData;
  68. mixin PerObjectData;
  69. mixin SkinnedVertexInput;
  70. mixin ShadowDepthBase;
  71. mixin ShadowDepth;
  72. tags = { "Skinned" };
  73. };
  74. technique ShadowDepthMorph
  75. {
  76. mixin GBufferOutput;
  77. mixin PerCameraData;
  78. mixin PerObjectData;
  79. mixin MorphVertexInput;
  80. mixin ShadowDepthBase;
  81. mixin ShadowDepth;
  82. tags = { "Morph" };
  83. };
  84. technique ShadowDepthSkinnedMorph
  85. {
  86. mixin GBufferOutput;
  87. mixin PerCameraData;
  88. mixin PerObjectData;
  89. mixin SkinnedMorphVertexInput;
  90. mixin ShadowDepthBase;
  91. mixin ShadowDepth;
  92. tags = { "SkinnedMorph" };
  93. };