How to prevent virtual hands rendering on top of passthrough with shaders

Had to do this for our app. Here’s the general approach.

Add a stencil to your passthrough material’s shader that claims spots in the stencil buffer and prevent the hand shader from rendering pixels that have been claimed:

// Replace all Stencil blocks in your hand shader with this:

Stencil {
    Ref 2
    Comp notequal
    Pass keep
}

// Add this to your overlay's material shader Pass block

Stencil {
    Ref 2
    Comp always
    Pass replace
}
1 Like