Clearing the z buffer using a shader, or using z bias

I’m working on a first person shooter game and I’m rendering a gun. However, when the character gets close to a wall, the gun clips through the wall.

If I render the gun in a different camera, the shadows cast from other objects don’t affect the gun.

If I scale the gun to make it really small, the shadows work but they work as a shadow would on a really small object…so if u go under a tree the shadows from the leaves look huge.

If I disable the depth buffer, the gun wont render right, as the gun has animations like reloading and theres models for the hands etc, so the z buffer is important for rendering the gun right.

I was wondering if it was somehow possible via a shader to clear the z buffer, or change the bias value of the zbuffer. Using the render queue I can make the gun be the last object rendered, if I could clear the z buffer it would fix this issue.

Thanks for reading.

Same problem here i cant find a solution HELP ME!!

How are these ideas not incompatible?

If you draw you gun Second last , then your Character last in your geometry layer and make sure you do the following it might work for you. This will require a little shader code.

Gun pass Zwrite on and Ztest Always.
Character pass Zwrite On Ztest Lequal.

The gun should draw over any geometry it clips and still write to the Zbuffer for shadows ect.
the character will draw properly with the gun as per normal.

Hope it helps
Brn