Stencil Objects infront of Player only

I am currently working on a 3rd person player project where the players will have any walls between them and the camera stencil’d.
So to do this I decided to add a sphere that would stencil the walls away, however, it also stencil the walls behind the players as well and I’m trying to figure out what the best way to resolve this would be.

My first thought was to just add another stencil shader behind it that would reset it, but I then realized whenever they overlap in FoV the sphere gets overwritten so the walls don’t disappear.

Any advice on how to achieve what I want? Or do I need to go and make a script that will set only the walls I want stenciled and then any walls I don’t currently want stencil’d a different shader?

A few options:

  1. Don’t use stencil. Instead use a clip shader that checks if the wall is closer than the player before cutting out a screen space circle around the player’s position.

  2. Detect objects between the camera and the player in c# and swap the material to the stencil affected version when one is in the way. Otherwise use the non-stencil version.

  3. Manually sort your entire world back to front with no batching to make sure the stencil mask object doesn’t render until after the further away walls have been rendered. Yeah, this is dumb and expensive… it’s also how 2D games do it since they’re already sorted that way, and is the only way to do it when you’re using stencils since they’re fully dependent on the exact draw order of stuff since they’re a 2D effect and don’t know anything about depth.

As a complete noob to Shaders, you know of any good tutorials or anything that I should look at?

Honestly I don’t know of any that deal with the problem in the way I described in my “1.” suggestion. Most examples online use stencils and ignore the problem you’re having, or use material swaps like I mentioned in option 2.