Converting a Unity's cgim shader to HLSL (URP). I am stuck on Unity's macro in depth texture "COMPUTE_EYEDEPTH", Docs: https://docs.unity3d.com/2020.1/Documentation/Manual/SL-DepthTextures.html. Can you share HLSL equivalent?
CodePudding user response:
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.