ShadowDepthCube.bsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #define USES_GS
  2. #include "$ENGINE$\ShadowDepthBase.bslinc"
  3. Technique : base("ShadowDepth") =
  4. {
  5. Pass =
  6. {
  7. Geometry =
  8. {
  9. struct GSToPS
  10. {
  11. float4 position : SV_Position;
  12. uint targetIdx : SV_RenderTargetArrayIndex;
  13. };
  14. cbuffer ShadowCubeMatrices
  15. {
  16. float4x4 gFaceVPMatrices[6];
  17. };
  18. cbuffer ShadowCubeMasks
  19. {
  20. uint gFaceMasks[6];
  21. };
  22. [maxvertexcount(18)]
  23. void main(triangle ShadowVStoFS inputs[3], inout TriangleStream<GSToPS> outStream)
  24. {
  25. // Output a triangle to all relevant faces
  26. [unroll]
  27. for (int faceIdx = 0; faceIdx < 6; faceIdx++)
  28. {
  29. // Check the per-object masks that were determined based on CPU frustum culling
  30. [branch]
  31. if (gFaceMasks[faceIdx] > 0)
  32. {
  33. float4 clipPos[3];
  34. [unroll]
  35. for (int vertIdx = 0; vertIdx < 3; vertIdx++)
  36. clipPos[vertIdx] = mul(gFaceVPMatrices[faceIdx], inputs[vertIdx].worldPos);
  37. // Per-triangle frustum culling
  38. // Note: Test if this helps or hurts performance
  39. float4 testMask = saturate(clipPos[0].xyxy * float4(-1, -1, 1, 1) - clipPos[0].w);
  40. testMask *= saturate(clipPos[1].xyxy * float4(-1, -1, 1, 1) - clipPos[1].w);
  41. testMask *= saturate(clipPos[2].xyxy * float4(-1, -1, 1, 1) - clipPos[2].w);
  42. [branch]
  43. if (all(testMask == 0))
  44. {
  45. GSToPS output;
  46. output.targetIdx = faceIdx;
  47. [unroll]
  48. for (int vertIdx = 0; vertIdx < 3; vertIdx++)
  49. {
  50. output.position = clipPos[vertIdx];
  51. outStream.Append(output);
  52. }
  53. outStream.RestartStrip();
  54. }
  55. }
  56. }
  57. }
  58. };
  59. };
  60. };