Showing results for 
Search instead for 
Did you mean: 

DepthAPI Occlusion Lit conflict with stencil shader


Hi there,

I'm currently working on creating a local multiplayer XR experience that involves both portal effects (using a custom stencil shader) and DepthAPI to allow players to see each other in a shared space.I've managed to get DepthAPI and the stencil shader to work individually, but I can't figure out how to combine them.

The main issue is that DepthAPI
, which uses the depth sensor of the Meta Quest 3, recognizes physical walls around players and prevents pixels of objects that are virtually further from the headset than the walls from being drawn. So, while the portal stencil works, it can't render the "outside" of the room.

Do you have any ideas on how to deal with this
? I'm not skilled enough in shaders to resolve it on my own.
Here some screenshots of my current progress : 




There’s no reason why you need to use the occlusion shader on the environment through the portal. You could just occlude only the stencil surface. If a stencil fragment is occluded, so is everything behind it


edit: this may not work with soft occlusion and it may not look right with the right-eye depth reprojection. I’m playing with a similar issue and will get back to you if my other solution works out

Well I tried playing with the EnvironmentDepthBias to try modify the occlusion z distance but its not working very well. I also tried occluding only the portal w/ stencil shader and here what happens : 
- plane w/ stencil is occluded so there's a "mask" arround hands 
- through this mask, external environment is drawn over hands so hands aren't visible 
- same with every real world furniture that should be drawn over the environment

What does your stencil portal shader look like? Can you paste it here?


Here it is, its really basic : 

Shader "Custom/StencilPassthroughShader"
        [IntRange] _StencilID("Stencil ID", Range(0, 255)) = 0
            "RenderType" = "Opaque"
            "Queue" = "Geometry"
            "RenderPipeline" = "UniversalPipeline"
            Blend Zero One
            ZWrite Off
                Comp Always
                Pass Replace