DepthOffset function

I have a question concerning the usage of DepthOffset.
[Offset Factor, Units]

According to the page below, I understand that its more or less the same as the glPolygonOffset function/usage.


When tweaking the Factor field, everything works as expected.
But, tweaking the Units field, it doesn’t work, no matter what value is put in.
The [r] value stated in the above page, seemes to behaves as if it is 0 or as close as possible to a 0.
Thank you.

It’s exactly the same as the glPolygonOffset function. The problem is the actual implementation of it isn’t defined by either OpenGL or DirectX. The above is likely based on the OpenGL reference implementation, but there’s no requirement that GPU makers actually implement it exactly like that. The result is exactly how offset works is GPU specific, and may be different between GPU makes and models!

Would it be better to just add a function to the vertex shader to perform pretty much the same thing, or am I way off base?

Depends on what you’re trying to do. If you’re just looking to push the object closer to the camera, then absolutely adjusting the vertex position would be better. If you’re looking to do it based on the triangle slope like Offset does, then you’d need to implement it in a geometry shader or fragment shader. GPUs technically do it by adjusting fragment output depth, similar to setting SV_Depth.

1 Like

Thank you for your answer.

This time I just want to make Object closer to the camera, so I will try to use vertex shader.

I’m not sure offset is even accessible per pixel with Universal pipeline. It is with HDRP.

Yeah, there’s a lot of render state stuff not exposed yet to Shader Graph (which Offset falls under), especially in the LWRP/URP. Some of it is getting exposed for the HDRP and hopefully that filters down to the URP at some point.

Either way, offsetting towards the camera using a Shader Graph isn’t super hard. I posted a super basic implementation here:

Thank you for the sample. I am going to use it as an example.