Unity shader (HLSL) equivalent of Unity macro "COMPUTE_EYEDEPTH"

Viewed 18
1 Answers

You download the built-in unity shaders for each unity version here: https://unity3d.com/get-unity/download/archive by pressing either "Download (Windows)" or "Download (Mac)" and then "Built-in shaders".

Open the zip in IDE like VSCode and search for COMPUTE_EYEDEPTH and you will see the macro in the file UnityCG.cginc

#define COMPUTE_EYEDEPTH(o) o = -UnityObjectToViewPos( v.vertex ).z

Repeat the same for UnityObjectToViewPos and you will find this in the same file UnityCG.cginc

// Tranforms position from object to camera space
inline float3 UnityObjectToViewPos( in float3 pos )
{
    return mul(UNITY_MATRIX_V, mul(unity_ObjectToWorld, float4(pos, 1.0))).xyz;
}

I hope that's starting point to implement it in HLSL for URP.

Related