Does the CustomDepth have different precision in the forward renderer?

amoffat
Sun, 04 Apr 2021 02:44:46 +0000
Rendering

Hi, I’ve written a post-process material that uses CustomDepth and SceneDepth. I’m also using the forward renderer. In my material, when I compare CustomDepth and SceneDepth, they never match, and it requires me to do something funky below in order to find where they are “equal”.

Essentially what I am doing here is an absolute difference between CustomDepth and SceneDepth, but I am scaling the threshold difference for equality based on distance from the camera (this gives me consistent accuracy close up and far away):

With this hack in place, I have artifacts. Below is an example of an artifact. The squiggly tube is opaque and rendering to the CustomDepth. The cube is also opaque and is intersecting with the tube. The red color is being added with the post-process material, based on if CustomDepth roughly equals SceneDepth. You can see the red is “bleeding” onto the cube, because the cube is within the threshold of equality.

I can tune this threshold, but then I get artifacts in the other direction. For example, if I make the threshold smaller, I get:

Now the red isn’t bleeding onto the cube, but it also isn’t always covering the tube. This is because the CustomDepth and the SceneDepth never match, even when they should.

My only thought is that these buffers must have different precision when using the forward renderer. I say this because most tutorials online that use a post-process material (for example, to do outlines, or “x-ray” effects) compare the SceneDepth and CustomDepth with a simple equality, which could only be possible if both buffers were say 24-bit or 32-bit. My hunch is that with the forward renderer, one is 24-bit (or less), while the other is 32-bit.

Any ideas on what is going on here and how to fix? Thanks

3 posts - 3 participants