Weapon scope implemented using stencil portal, occlusion?
Hi!
I am trying to implement a scope by using the stencil buffer. Everything looks good (interior of scope only rendered when looking through stencil plane, unwanted weapon geometry hidden when looking through stencil plane.
The problem is when the stencil plane is occluded by other parts of the weapon, since the stencil plane (by necessity?) is rendered first the pixels that occlude the stencil plane is not rendered.
Here is an image of the scope working correctly.
Here is an image of the problem.
There are three different shaders involved:
StencilPlane:
SubShader {
Tags { "Queue" = "Background" }
ZWrite Off
ColorMask 0
Pass {
Stencil {
Ref 1
Comp always
Pass replace
}
}
}
VisibleThroughLens:
Stencil {
Ref 1
Comp Equal
}
HiddenThroughLens:
Stencil{
Ref 1
Comp NotEqual
}
Can something be done to prevent this, or is the stencil buffer not the correct tool for the job? Is there some other way to selectively hide objects viewed through a plane?
Your answer
Follow this Question
Related Questions
Sprite Occlusion with Stencil Buffer for Surface Shader? 0 Answers
Occlusion Portals Not Working in 5.5.0f3 0 Answers
Custom Obj appears behind other GameObjects when viewpoint is changed 0 Answers
Can someone please help me, unity is still giving me this error??? 0 Answers
URP: Renderer Features not Saving Changes to Stencil Settings 1 Answer