浏览代码

Moved depth copying to an include file.

/main
Aleksandr Kirillov 6 年前
当前提交
430af144
共有 4 个文件被更改,包括 71 次插入63 次删除
  1. 27
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader
  2. 41
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader
  3. 57
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl
  4. 9
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl.meta

27
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepth.shader


#pragma vertex vert
#pragma fragment frag
#include "LWRP/ShaderLibrary/Core.hlsl"
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VertexOutput vert(VertexInput i)
{
VertexOutput o;
o.uv = i.uv;
o.position = TransformObjectToHClip(i.vertex.xyz);
return o;
}
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, i.uv);
return SampleDepth(i.uv);
}
ENDHLSL
}

41
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightCopyDepthMSAA.shader


#pragma require msaatex
#include "LWRP/ShaderLibrary/Core.hlsl"
#define MSAA_DEPTH 1
Texture2DMS<float> _CameraDepthTexture;
float _SampleCount;
float4 _CameraDepthTexture_TexelSize;
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VertexOutput vert(VertexInput i)
{
VertexOutput o;
o.uv = i.uv;
o.position = TransformObjectToHClip(i.vertex.xyz);
return o;
}
#include "LWRP/ShaderLibrary/DepthCopy.hlsl"
int2 coord = int2(i.uv * _CameraDepthTexture_TexelSize.zw);
int samples = (int)_SampleCount;
#if UNITY_REVERSED_Z
float outDepth = 1.0;
#define DEPTH_OP min
#else
float outDepth = 0.0;
#define DEPTH_OP max
#endif
for (int i = 0; i < samples; ++i)
outDepth = DEPTH_OP(LOAD_TEXTURE2D_MSAA(_CameraDepthTexture, coord, i), outDepth);
return outDepth;
return SampleDepth(i.uv);
}
ENDHLSL
}

57
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl


#ifndef LIGHTWEIGHT_DEPTH_COPY_INCLUDED
#define LIGHTWEIGHT_DEPTH_COPY_INCLUDED
#include "LWRP/ShaderLibrary/Core.hlsl"
struct VertexInput
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct VertexOutput
{
float4 position : SV_POSITION;
float2 uv : TEXCOORD0;
};
VertexOutput vert(VertexInput i)
{
VertexOutput o;
o.uv = i.uv;
o.position = TransformObjectToHClip(i.vertex.xyz);
return o;
}
#if MSAA_DEPTH
Texture2DMS<float> _CameraDepthTexture;
float _SampleCount;
float4 _CameraDepthTexture_TexelSize;
#else
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
#endif
float SampleDepth(float2 uv)
{
#if MSAA_DEPTH
int2 coord = int2(uv * _CameraDepthTexture_TexelSize.zw);
int samples = (int)_SampleCount;
#if UNITY_REVERSED_Z
float outDepth = 1.0;
#define DEPTH_OP min
#else
float outDepth = 0.0;
#define DEPTH_OP max
#endif
for (int i = 0; i < samples; ++i)
outDepth = DEPTH_OP(LOAD_TEXTURE2D_MSAA(_CameraDepthTexture, coord, i), outDepth);
return outDepth;
#else
return SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, sampler_CameraDepthTexture, uv);
#endif
}
#endif // LIGHTWEIGHT_DEPTH_COPY_INCLUDED

9
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/DepthCopy.hlsl.meta


fileFormatVersion: 2
guid: 971e7c84ed6bc40fc95bdbb2e008013f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存