How to make meshes self occlude with No Depth Test enabled?

Godot Version

Latest Godot Version. 4.3 I think.

Question

I have this character mesh right? I want it to sort of act like a viewmodel(Without actually following the camera), The idea is for it to not clip into walls when i go close(since its Attached to my CharacterBody3D). I would usually try to achieve it with SubViewports but only for standart viewmodels that follow the camera.

If i enable No Depth Test on the mesh’s Material, it sort of works, but the mesh doesnt occlude itself(You can see parts of the mesh, that are supposed to be hidden by others)

Is there a way to just render the mesh on top of everything without this bug?

Try using X-ray stencil in standard material properties.

1 Like

Ok yeah sort of works, but when i go behind a wall, the mesh is visible, but its fully black. Is there a way to add textures to the stencil? Editing the stencil material doesnt seem to work either

Nevermind changing the albedo to white and then adding a texture fixes it, but then it doesnt self occlude again

Render to viewport and composite

1 Like