ShadowDepthCube.bsl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 ShadowCubeParams
  13. {
  14. float4x4 gFaceVPMatrices[6];
  15. uint gFaceMasks[6];
  16. uint padding[2];
  17. };
  18. [maxvertexcount(18)]
  19. void gsmain(triangle ShadowVStoFS inputs[3], inout TriangleStream<GSToPS> outStream)
  20. {
  21. // Output a triangle to all relevant faces
  22. [unroll]
  23. for (int faceIdx = 0; faceIdx < 6; faceIdx++)
  24. {
  25. // Check the per-object masks that were determined based on CPU frustum culling
  26. [branch]
  27. if (gFaceMasks[faceIdx] > 0)
  28. {
  29. float4 clipPos[3];
  30. [unroll]
  31. for (int vertIdx = 0; vertIdx < 3; vertIdx++)
  32. clipPos[vertIdx] = mul(gFaceVPMatrices[faceIdx], inputs[vertIdx].worldPos);
  33. // Per-triangle frustum culling
  34. // Note: Test if this helps or hurts performance
  35. float4 testMask = saturate(clipPos[0].xyxy * float4(-1, -1, 1, 1) - clipPos[0].w);
  36. testMask *= saturate(clipPos[1].xyxy * float4(-1, -1, 1, 1) - clipPos[1].w);
  37. testMask *= saturate(clipPos[2].xyxy * float4(-1, -1, 1, 1) - clipPos[2].w);
  38. [branch]
  39. if (all(testMask == 0))
  40. {
  41. GSToPS output;
  42. output.targetIdx = faceIdx;
  43. [unroll]
  44. for (int vertIdx = 0; vertIdx < 3; vertIdx++)
  45. {
  46. output.position = clipPos[vertIdx];
  47. outStream.Append(output);
  48. }
  49. outStream.RestartStrip();
  50. }
  51. }
  52. }
  53. }
  54. };
  55. };