Forum Discussion
gameside.2024
2 years agoExplorer
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 :
8 Replies
Replies have been turned off for this discussion
- jtriveriStart Partner
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
- gameside.2024Explorer
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- jtriveriStart Partner
What does your stencil portal shader look like? Can you paste it here?
- gameside.2024Explorer
Here it is, its really basic :
Shader "Custom/StencilPassthroughShader" { Properties { [IntRange] _StencilID("Stencil ID", Range(0, 255)) = 0 } SubShader { Tags { "RenderType" = "Opaque" "Queue" = "Geometry" "RenderPipeline" = "UniversalPipeline" } Pass { Blend Zero One ZWrite Off Stencil { Ref[_StencilID] Comp Always Pass Replace } } } } - dmaclean.2025Honored Guest
Did you ever find a solution? I'm dealing with a similar challenge.
- genii.393095Honored Guest
I have setup my stencil but its not working too.
- SandstedtStart Partner
You can add your meshfilter to the Environment Depth Manager's Mask Mesh Filters, and it will remove it from the depth map. Works for my stencil shaders, at least. It doesn't look the best when using soft occlusion. But it works at least. I have also set the shader to user Environmental Depth Bias -0.07. Worked best for me.
- DaemynMember
Do you mind if I ask how you got the stencil shader to occlude? I currently am working on a similar setup, and while the depth occlusion is working great on objects with an occlusion shader, it is not working on the stencil as it is (which is much the same as yours), and it sounds like you have it working with occlusion without needing to modify the shader?
As to your original question, as Sandstedt pointed out, the Depth Mask Mesh Filters is probably your best bet. You can also add the meshes to the depth mask list automatically with code, shown here: https://developers.meta.com/horizon/documentation/unity/unity-depthapi-occlusions-advanced-usage#using-the-depth-mask-feature (before I got started, I knew I would have a similar issue, and that's what came up)
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device