- Home /
Occlude object behind 'invisible' wall
Dear All
I have a series of walls in a fort, and a soldier walking around the battlements. I want to be able to show the soldier hidden by the ramparts, but don't want to render the ramparts themselves. Therefore as the soldier walks along, it looks as if he is patrolling around an invisible fort, but is still hidden by the architecture (i.e. it looks as if half a soldier is walking along in mid-air). I hope this makes sense!
Is this possible? If I just turn off the Mesh Renderer of the walls, the whole soldier is visible, so I presume I need some kind of fancy shader or something, but am not sure where to start. Many thanks for any help you can give.
Murdoch.
Answer by Jessy · Nov 30, 2010 at 04:10 PM
Render the ramparts after other opaque geometry. Render the soldier after that. Use ColorMask 0 on the ramparts, which will do nothing but change the depth buffer value. I can't get you a well-formatted shader right now, because I'm on my iPhone, but if you go watch my first ShaderLab tutorial on YouTube, that's nearly all you need. Just look up rendering queues and ColorMask in the ShaderLab manual to learn the rest. The code in the SubShader will only be three lines:
Tags {"Queue" = "Geometry+1"} ColorMask 0 Pass {}
Just use whatever shader you already were, for the soldier, but use Geometry+2 or something.
FYI, ColorMask has had some bugs on Windows, so if the bugs still exist, this may be impossible. I can't test that myself, though.