I’m working with irregular shapes made of water and I would like to apply an underwater post process to only the inside of them.
The only way I’ve found to do this is by having 2 instances of the mesh with different stencil values and using WPO to offset one of them slightly. Then in the post process material the inside stencil gets occluded by the outside stencil unless the camera is inside it.
This works, but I want to find a way to do it with a single mesh instance. In my case I’m working with Voxel Procedural Meshes, so having 2 instances is very heavy and sometimes their culling and LOD switching don’t happen in sync.
By experimenting with “Two Sided Sign” materials and the “Opacity Mask Clip Value” I can make it so only the interior faces are written to custom depth, but this doesn’t actually change the shape of the stencil because the outer faces are simply ignored rather than being subtracted from the stencil. So it seems the only way is to have an outer stencil which occludes the inner one.
Could there ever be a way to generate 2 stencils from different parts of a mesh? Or have some parts of a mesh subtract from the stencil? Perhaps this could be done by writing to a render target, or having the GPU render the same mesh twice with a different World Position Offset and stencil value rather than actually having a duplicate?