Stencil Buffer with depth? possible? Suggestions for fixing this rendering issue.

Hi all,

I am not sure if I am using the correct terms for what I am look for- but is it possible to configure a stencil buffer to only make things that are in front of it transparent?

If you can see the attached image, I implemented a stencil buffer to see through walls in front of my player but it affects walls behind them as well if the angle is correct. The implementation uses a sphere that has a material/shader that is writing to the stencil buffer and the layer masking is configured the URP renderer settings, basically like this example.

I’m not sure the best way to configure the stencil buffer to get the effect I am looking for, any help is appreciated, thanks.

You will need to just render things in the right order, or a custom order.

Cool thanks. I did some digging. Am I correct in thinking I will have to update the render order in real time for each mesh or is there smarter way of doing it?