#Project to far plane in Shader Graph

1 messages · Page 1 of 1 (latest)

radiant fractal
#

I have a Shader Graph that is used to render far away terrain. I want to prevent it from getting clipped by the far plane.
This is very simple in shader code:

output.positionCS = TransformWorldToHClip(positionWS);

#if defined(UNITY_REVERSED_Z)
output.positionCS.z = max(0.000001f, output.positionCS.z);
#else
output.positionCS.z = min(output.positionCS.w - 0.00001, output.positionCS.z);
#endif

But I don't see this being possible to replicate in Shader Graph, since it doesn't let you modify the HClip position, only the object space position.
Any ideas for the best approach to achieve this in Shader Graph?

sonic cipher
#

Not pretty... but I think overriding the function by defining a macro in a custom function can replicate it

Out = In; // both Vector3, just passing Position (object space) through unchanged to connect custom function to master stack

#ifdef UNITY_REVERSED_Z
#define TransformWorldToHClip(ws) float4(TransformWorldToHClip(ws).xy, max(TransformWorldToHClip(ws).z, 0.001f), TransformWorldToHClip(ws).w)
#else
#define TransformWorldToHClip(ws) float4(TransformWorldToHClip(ws).xy, min(TransformWorldToHClip(ws).z, TransformWorldToHClip(ws).w - 0.001f), TransformWorldToHClip(ws).w)
#endif

But while testing I was still seeing some triangles being clipped (in both graph & code form?)
Also only tested in URP