Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@
#if defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMSArray<float, samples> name
#define DEPTH_TEXTURE(name) TEXTURE2D_ARRAY_FLOAT(name)
#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, uv, unity_StereoEyeIndex, sampleIndex)
#define SAMPLE(uv) SAMPLE_TEXTURE2D_ARRAY(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv, unity_StereoEyeIndex).r
#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_ARRAY_MSAA(_CameraDepthAttachment, coord, unity_StereoEyeIndex, sampleIndex)
#define LOAD(coord) LOAD_TEXTURE2D_ARRAY(_CameraDepthAttachment, coord, unity_StereoEyeIndex)
#else
#define DEPTH_TEXTURE_MS(name, samples) Texture2DMS<float, samples> name
#define DEPTH_TEXTURE(name) TEXTURE2D_FLOAT(name)
#define LOAD(uv, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, uv, sampleIndex)
#define SAMPLE(uv) SAMPLE_DEPTH_TEXTURE(_CameraDepthAttachment, sampler_CameraDepthAttachment, uv)
#define LOAD_MSAA(coord, sampleIndex) LOAD_TEXTURE2D_MSAA(_CameraDepthAttachment, coord, sampleIndex)
#define LOAD(coord) LOAD_TEXTURE2D(_CameraDepthAttachment, coord)
#endif

#if MSAA_SAMPLES == 1
DEPTH_TEXTURE(_CameraDepthAttachment);
SAMPLER(sampler_CameraDepthAttachment);
#else
DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
float4 _CameraDepthAttachment_TexelSize;
#endif

#if UNITY_REVERSED_Z
Expand All @@ -42,17 +40,17 @@
#define DEPTH_OP max
#endif

float SampleDepth(float2 uv)
float SampleDepth(float2 pixelCoords)
{
int2 coord = int2(pixelCoords);
#if MSAA_SAMPLES == 1
return SAMPLE(uv);
return LOAD(coord).r;
#else
int2 coord = int2(uv * _CameraDepthAttachment_TexelSize.zw);
float outDepth = DEPTH_DEFAULT_VALUE;

UNITY_UNROLL
for (int i = 0; i < MSAA_SAMPLES; ++i)
outDepth = DEPTH_OP(LOAD(coord, i), outDepth);
outDepth = DEPTH_OP(LOAD_MSAA(coord, i), outDepth);
return outDepth;
#endif
}
Expand All @@ -64,7 +62,7 @@ float frag(Varyings input) : SV_Target
#endif
{
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return SampleDepth(input.texcoord);
return SampleDepth(input.positionCS.xy);
}

#endif
Loading