Hello!
I'm just trying to use a shader to push all vertices to the far clip plane, so an object renders behind everything else. Very much just copying this. (First image is the example)
I want to do it within ShaderGraph, but ShaderGraph outputs vertex positions in Object space. My simple hack solve was to try to do it in a custom node, and convert from clip space back to object space before returning- which half worked.
//UNITY_SHADER_NO_UPGRADE
#ifndef VERTEXPUSHFARCLIP_INCLUDED
#define VERTEXPUSHFARCLIP_INCLUDED
float4x4 GetHClipToWorldMatrix()
{
return UNITY_MATRIX_I_VP;
}
float3 TransformHClipToObject(float4 positionCS)
{
return mul(GetWorldToObjectMatrix(), mul(GetHClipToWorldMatrix(), positionCS)).xyz;
}
// the main function:
void TransformVerts_float(float3 In_OS, out float3 Out_OS)
{
Out_OS = float3(0, 0, 1);
float4 clipPos = TransformObjectToHClip(In_OS);
// 2. apply transformation
#if UNITY_REVERSED_Z
// when using reversed-Z, make the Z be just a tiny
// bit above 0.0
clipPos.z = 1.0e-9f;
#else
// when not using reversed-Z, make Z/W be just a tiny
// bit below 1.0
clipPos.z = clipPos.w - 1.0e-6f;
#endif
// 3. return to object space
Out_OS = TransformHClipToObject(clipPos);
}
#endif //VERTEXPUSHFARCLIP_INCLUDED
I've attached a video of what that looks like!
As you can see, it kinda works until you start getting closer up to it - and it also halves the size of the mesh.
I suspect I'm screwing something up with the matrix math, but I'm not totally sure what.
Any thoughts would be massively appreciated!