暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CopyDepthPass.hlsl 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
  2. #define UNIVERSAL_COPY_DEPTH_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
  5. #if defined(_DEPTH_MSAA_2)
  6. #define MSAA_SAMPLES 2
  7. #elif defined(_DEPTH_MSAA_4)
  8. #define MSAA_SAMPLES 4
  9. #elif defined(_DEPTH_MSAA_8)
  10. #define MSAA_SAMPLES 8
  11. #else
  12. #define MSAA_SAMPLES 1
  13. #endif
  14. #if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
  15. #define DEPTH_TEXTURE_MS(name, samples) Texture2DMSArray<float, samples> name
  16. #define DEPTH_TEXTURE(name) TEXTURE2D_ARRAY_FLOAT(name)
  17. #define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, uv, unity_StereoEyeIndex, sampleIndex)
  18. #define SAMPLE(uv) SAMPLE_TEXTURE2D_ARRAY(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv, unity_StereoEyeIndex).r
  19. #else
  20. #define DEPTH_TEXTURE_MS(name, samples) Texture2DMS<float, samples> name
  21. #define DEPTH_TEXTURE(name) TEXTURE2D_FLOAT(name)
  22. #define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, uv, sampleIndex)
  23. #define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv)
  24. #endif
  25. #if MSAA_SAMPLES == 1
  26. DEPTH_TEXTURE(_CameraDepthAttachment);
  27. SAMPLER(sampler_CameraDepthAttachment);
  28. #else
  29. DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
  30. float4 _CameraDepthAttachment_TexelSize;
  31. #endif
  32. #if UNITY_REVERSED_Z
  33. #define DEPTH_DEFAULT_VALUE 1.0
  34. #define DEPTH_OP min
  35. #else
  36. #define DEPTH_DEFAULT_VALUE 0.0
  37. #define DEPTH_OP max
  38. #endif
  39. float SampleDepth(float2 uv)
  40. {
  41. #if MSAA_SAMPLES == 1
  42. return SAMPLE(uv);
  43. #else
  44. int2 coord = int2(uv * _CameraDepthAttachment_TexelSize.zw);
  45. float outDepth = DEPTH_DEFAULT_VALUE;
  46. UNITY_UNROLL
  47. for (int i = 0; i < MSAA_SAMPLES; ++i)
  48. outDepth = DEPTH_OP(LOAD(coord, i), outDepth);
  49. return outDepth;
  50. #endif
  51. }
  52. #if defined(_OUTPUT_DEPTH)
  53. float frag(Varyings input) : SV_Depth
  54. #else
  55. float frag(Varyings input) : SV_Target
  56. #endif
  57. {
  58. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  59. return SampleDepth(input.texcoord);
  60. }
  61. #endif