1717#if defined (UNITY_STEREO_INSTANCING_ENABLED) || defined (UNITY_STEREO_MULTIVIEW_ENABLED)
1818#define DEPTH_TEXTURE_MS (name, samples) Texture2DMSArray <float , samples> name
1919#define DEPTH_TEXTURE (name) TEXTURE2D_ARRAY_FLOAT (name)
20- #define LOAD (uv , sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA (_CameraDepthAttachment, uv , unity_StereoEyeIndex, sampleIndex)
21- #define SAMPLE (uv) SAMPLE_TEXTURE2D_ARRAY (_CameraDepthAttachment, sampler_CameraDepthAttachment, uv, unity_StereoEyeIndex).r
20+ #define LOAD_MSAA (coord , sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA (_CameraDepthAttachment, coord , unity_StereoEyeIndex, sampleIndex)
21+ #define LOAD (coord) LOAD_TEXTURE2D_ARRAY (_CameraDepthAttachment, coord, unity_StereoEyeIndex)
2222#else
2323#define DEPTH_TEXTURE_MS (name, samples) Texture2DMS <float , samples> name
2424#define DEPTH_TEXTURE (name) TEXTURE2D_FLOAT (name)
25- #define LOAD (uv , sampleIndex) LOAD_TEXTURE2D_MSAA (_CameraDepthAttachment, uv , sampleIndex)
26- #define SAMPLE (uv) SAMPLE_DEPTH_TEXTURE (_CameraDepthAttachment, sampler_CameraDepthAttachment, uv)
25+ #define LOAD_MSAA (coord , sampleIndex) LOAD_TEXTURE2D_MSAA (_CameraDepthAttachment, coord , sampleIndex)
26+ #define LOAD (coord) LOAD_TEXTURE2D (_CameraDepthAttachment, coord)
2727#endif
2828
2929#if MSAA_SAMPLES == 1
3030 DEPTH_TEXTURE (_CameraDepthAttachment);
31- SAMPLER (sampler_CameraDepthAttachment);
3231#else
3332 DEPTH_TEXTURE_MS (_CameraDepthAttachment, MSAA_SAMPLES);
34- float4 _CameraDepthAttachment_TexelSize;
3533#endif
3634
3735#if UNITY_REVERSED_Z
4240 #define DEPTH_OP max
4341#endif
4442
45- float SampleDepth (float2 uv)
43+ float SampleDepth (float2 pixelCoords)
4644{
45+ int2 coord = int2 (pixelCoords);
4746#if MSAA_SAMPLES == 1
48- return SAMPLE (uv);
47+ return LOAD (coord);
4948#else
50- int2 coord = int2 (uv * _CameraDepthAttachment_TexelSize.zw);
5149 float outDepth = DEPTH_DEFAULT_VALUE;
5250
5351 UNITY_UNROLL
5452 for (int i = 0 ; i < MSAA_SAMPLES; ++i)
55- outDepth = DEPTH_OP (LOAD (coord, i), outDepth);
53+ outDepth = DEPTH_OP (LOAD_MSAA (coord, i), outDepth);
5654 return outDepth;
5755#endif
5856}
@@ -64,7 +62,7 @@ float frag(Varyings input) : SV_Target
6462#endif
6563{
6664 UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX (input);
67- return SampleDepth (input.texcoord );
65+ return SampleDepth (input.positionCS.xy );
6866}
6967
7068#endif
0 commit comments