ShadowDepthCube.bsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. [internal]
  13. cbuffer ShadowCubeMatrices
  14. {
  15. float4x4 gFaceVPMatrices[6];
  16. };
  17. [internal]
  18. cbuffer ShadowCubeMasks
  19. {
  20. uint gFaceMasks[6];
  21. };
  22. [maxvertexcount(18)]
  23. void gsmain(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. };