ShadowDepthCube.bsl 1.5 KB

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