TetrahedraRender.bsl 1.5 KB

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