FPS shader fixing
Hi everyone, So lately I've been doing some researches and tried to develop a working FPS view without clipping that still receives shadows from the world.
As a result I don't use the culling mask/multi camera technique. I ended up wrapping together something. I have a completely transparent shader that writes to the Z buffer, and a second shader that uses the Z buffer normally (LEqual) to actually draw the weapon. They're both bound to 2 different materials on the same submesh (despite Unity's advice the performance doesn't seem to suffer, probably because the first shader is really lightweight).
The second shader is a complete copy of the built-in standard shader, except I added to both subshaders the tag "Queue"="Overlay+2" (Overlay+1 being used by the transparent shader, to make sure the Z buffer is affected last by the transparent shader before drawing the gun). My problem is that it still doesn't receive shadows. As soon as I remove the Queue tag it works again, it does receive the shadows, but the Z buffer doesn't affect the drawing of the gun/hand anymore.
Any hint at what could cause that, because I've been bumping my head for the last hours, and my lacking skills in shader development is driving me crazy right now :(
Thanks in advance guys !
Answer by DevilBlackDeath · Dec 11, 2016 at 12:36 PM
Well that's just me at work there -_-
I'm sorry to have bothered you. My problem was with the actual queue chosen... Of course if I draw the mesh AFTER the shadows they won't receive those. My solution was simply to switch to Geometry+1 and Geometry+2 queues. This way I have my meshes always on top, no matter how many different meshes are in the first-person view, and they still receive shadows from the world (and from what I can say their owns shadows too). Well I guess I may post this solution to the Unity reddit or somewhere, considering a lot of theory has been done on that, but noone ever posted a definitive answer !