您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
87 行
2.4 KiB
87 行
2.4 KiB
#ifndef LIGHTWEIGHT_DEPTH_COPY_INCLUDED
|
|
#define LIGHTWEIGHT_DEPTH_COPY_INCLUDED
|
|
|
|
#include "LWRP/ShaderLibrary/Core.hlsl"
|
|
|
|
struct VertexInput
|
|
{
|
|
float4 vertex : POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
|
|
struct VertexOutput
|
|
{
|
|
float4 position : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
VertexOutput vert(VertexInput i)
|
|
{
|
|
VertexOutput o;
|
|
UNITY_SETUP_INSTANCE_ID(i);
|
|
UNITY_TRANSFER_INSTANCE_ID(i, o);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.uv = i.uv;
|
|
o.position = TransformObjectToHClip(i.vertex.xyz);
|
|
return o;
|
|
}
|
|
|
|
#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
|
|
#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)
|
|
#endif
|
|
|
|
#ifdef _DEPTH_MSAA_2
|
|
#define MSAA_SAMPLES 2
|
|
#elif _DEPTH_MSAA_4
|
|
#define MSAA_SAMPLES 4
|
|
#endif
|
|
|
|
#ifdef _DEPTH_NO_MSAA
|
|
DEPTH_TEXTURE(_CameraDepthAttachment);
|
|
SAMPLER(sampler_CameraDepthAttachment);
|
|
#else
|
|
DEPTH_TEXTURE_MS(_CameraDepthAttachment, MSAA_SAMPLES);
|
|
float4 _CameraDepthAttachment_TexelSize;
|
|
#endif
|
|
|
|
#if UNITY_REVERSED_Z
|
|
#define DEPTH_DEFAULT_VALUE 1.0
|
|
#define DEPTH_OP min
|
|
#else
|
|
#define DEPTH_DEFAULT_VALUE 0.0
|
|
#define DEPTH_OP max
|
|
#endif
|
|
|
|
float SampleDepth(float2 uv)
|
|
{
|
|
#ifdef _DEPTH_NO_MSAA
|
|
return SAMPLE(uv);
|
|
#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);
|
|
return outDepth;
|
|
#endif
|
|
}
|
|
|
|
float frag(VertexOutput i) : SV_Depth
|
|
{
|
|
UNITY_SETUP_INSTANCE_ID(i);
|
|
return SampleDepth(i.uv);
|
|
}
|
|
|
|
#endif // LIGHTWEIGHT_DEPTH_COPY_INCLUDED
|