Last active
July 6, 2021 14:33
-
-
Save ValerioMarty/79423a1f559b7ea417ddb79a9088e52e to your computer and use it in GitHub Desktop.
custom depth in linear space for the colored 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
Shader "Hidden/CustomDepth" | |
{ | |
Properties | |
{ | |
} | |
SubShader | |
{ | |
Tags { "RenderType"="Opaque" } | |
LOD 100 | |
Pass | |
{ | |
Cull Off | |
HLSLPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" | |
struct appdata | |
{ | |
float4 vertex : POSITION; | |
}; | |
struct v2f | |
{ | |
float4 vertex : SV_POSITION; | |
float3 positionWS:TEXCOORD0; | |
}; | |
v2f vert (appdata v) | |
{ | |
v2f o; | |
VertexPositionInputs positionInputs = GetVertexPositionInputs(v.vertex.xyz); | |
o.vertex = positionInputs.positionCS; | |
o.positionWS = positionInputs.positionWS; | |
return o; | |
} | |
real4 frag (v2f i) : SV_Target | |
{ | |
real4 col = length( i.positionWS-_WorldSpaceCameraPos); | |
return col/_ProjectionParams.z; | |
} | |
ENDHLSL | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment