CustomDepth Stencil Render Behind Everything Else

Hi,

Question: Is there a way to make a CustomDepth Stencil render behind everything in the scene instead of infront (rendering infront of shown below)?

Context: I am trying to have a dematerialize effect that will move from the top of a mesh to the bottom of a mesh. Doing this in a post processing material works great for dematerializing the whole scene but if I want to do it on an individual mesh then it seems I need to use an opacity mask on that mesh. Unforunately, the meshes I am needing to do it on have a lot of materials per mesh and adding the dematerialize effect per material is more complexity than I would like.

I would like to do a CustomDepth Stencil that is sorted behind everything instead. That way I can use the stencil above a certain global height value and have all the portions of the mesh above that be sorted behind the rest of the scene. Make it look like the mesh is disappearing. Any help would be greatly appreciated.

Thank you

Looking back after writing this, what you have now seems to be what you want. It’s only rendering in front, so you just need to flip it using a one minus node to make it never render in front (flip prior to multiplying by red).

You can do this by comparing scene depth to custom depth.
If they’re the same, that means either there is no object with custom depth or the object is in front.
If they’re different, that means that there is something in front of the custom-depth enabled object.
You can then just use this value as a mask.

Effect normally:

Effect with custom depth check:

Effect:

3 Likes