FPS Weapon going through objects

How to write shader for my weapon to render first and to recive shadows,
if i use camera culling mask my weapon not receive shadows i dont know how to solve this problem
please help.

This can be done without a shader. Just use a second camera in the same place as the main camera. Let the main camera render everything but the weapon and the other camera only the weapon. The you only need to render the HUD camera on top of the main camera and you are done