Last active
July 3, 2021 12:01
-
-
Save ValerioMarty/168a5e23c3fa9de3afcbf1c7476f70a2 to your computer and use it in GitHub Desktop.
downsampled depth pass for the volumetric light tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pass | |
{ | |
Name "SampleDepth" | |
HLSLPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" | |
struct appdata | |
{ | |
real4 vertex : POSITION; | |
real2 uv : TEXCOORD0; | |
}; | |
struct v2f | |
{ | |
real2 uv : TEXCOORD0; | |
real4 vertex : SV_POSITION; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
o.vertex = TransformWorldToHClip(v.vertex); | |
o.uv = v.uv; | |
return o; | |
} | |
real frag (v2f i) : SV_Target | |
{ | |
#if UNITY_REVERSED_Z | |
real depth = SampleSceneDepth(i.uv); | |
#else | |
// Adjust z to match NDC for OpenGL | |
real depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(i.uv)); | |
#endif | |
return depth; | |
} | |
ENDHLSL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment