TetrahedraRender.bsl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "$ENGINE$\PerCameraData.bslinc"
  2. shader TetrahedraRender
  3. {
  4. mixin PerCameraData;
  5. variations
  6. {
  7. MSAA = { true, false };
  8. MSAA_RESOLVE_0TH = { true, false };
  9. };
  10. raster
  11. {
  12. cull = cw;
  13. };
  14. depth
  15. {
  16. compare = lte;
  17. };
  18. code
  19. {
  20. struct VertexInput
  21. {
  22. float3 position : POSITION;
  23. uint index : TEXCOORD0;
  24. };
  25. struct VStoFS
  26. {
  27. float4 position : SV_Position;
  28. float4 clipPos : TEXCOORD0;
  29. uint index : TEXCOORD1;
  30. };
  31. VStoFS vsmain(VertexInput input)
  32. {
  33. VStoFS output;
  34. output.position = mul(gMatViewProj, float4(input.position, 1.0f));
  35. output.clipPos = output.position;
  36. output.index = input.index;
  37. return output;
  38. }
  39. #if MSAA
  40. Texture2DMS<float> gDepthBufferTex;
  41. #else
  42. Texture2D gDepthBufferTex;
  43. SamplerState gDepthBufferSamp;
  44. #endif
  45. cbuffer Params
  46. {
  47. int2 gDepthTexSize;
  48. };
  49. uint fsmain(VStoFS input
  50. #if MSAA && !MSAA_RESOLVE_0TH
  51. ,uint sampleIdx : SV_SampleIndex
  52. #endif
  53. ) : SV_Target0
  54. {
  55. float2 ndcPos = input.clipPos.xy / input.clipPos.w;
  56. float2 uv = NDCToUV(ndcPos);
  57. float sceneDepth;
  58. #if MSAA
  59. int2 pixelPos = uv * gDepthTexSize;
  60. #if MSAA_RESOLVE_0TH
  61. sceneDepth = gDepthBufferTex.Load(pixelPos, 0);
  62. #else
  63. sceneDepth = gDepthBufferTex.Load(pixelPos, sampleIdx);
  64. #endif
  65. #else
  66. sceneDepth = gDepthBufferTex.Sample(gDepthBufferSamp, uv);
  67. #endif
  68. float currentDepth = input.position.z;
  69. if(currentDepth < sceneDepth)
  70. discard;
  71. return input.index;
  72. }
  73. };
  74. };