- Home /
Rendering Order Revisited
I know that there are plenty of questions out there related to rendering order:
http://answers.unity3d.com/questions/14752/forcing-a-gameobject-to-the-highest-depth-closest.html
http://answers.unity3d.com/questions/8220/rendering-order.html
and more closely related to my issue
However, I'm either misunderstanding this whole concept, or I'm doing something wrong, because I just can't get it to work at all.
What I want to do is: make sure that a certain object / material / shader is rendered on top of everything else in the scene. That is to say: set the shader to a queue sometime after all the other geometry is rendered, clear the depth buffer, and then render the object so that it appears 'written over' the rest of the scene. That way, no matter what other objects get between it and the camera it will always be drawn on top.
I know that this can be done with multiple cameras, but we run into the same problems as the last example above: trying to manage a whole bunch of cameras, framerates dropping, etc. From other folks' statements (e.g. the top example above that talks about drawing a gizmo that is inside a mesh object) it sounds like what I'm trying to do should be possible, but I've tried changing the shader tags, the renderQueue of the material, and everything else I can think of, and nothing seems to have an effect on the depth buffer.
Does the queue actually do what I'm trying to do here, or if not is there another way to do it at any level (shader, object, camera) without resorting to one camera for each object?
Answer by KvanteTore · Oct 06, 2011 at 11:59 AM
Even if use set the render queue, it will still do depth testing, and therefore not draw your object if something is closer to the camera. To achieve what you want, I believe you can disable zbuffer testing by setting
[ZTest Always][1]
as well as a sufficiently high renderqueue in your shader.
Of course, this will only work if your mesh is simple enough to not have any overdraw artifacts.
Another (untested) approach would be to do a two pass render, where the first pass has
ZTest Always
ZWrite On
ColorMask 0
The second pass has
ZTest LEqual
ZWrite On
and renders the object normally
The effect of the first pass would be to "clear" the zbuffer where you want your object to be drawn and the second pass to actually draw the object
[1]: http://unity3d.com/support/documentation/Components/SL-Pass.html
Thanks $$anonymous$$vanteTore
I did a bit of poking around on ZTest and found these great tutorial clips, that expand on what you've said here:
http://www.burgzergarcade.com/tutorials/game-engines/unity3d/unity-ios-shaderlab-tutorial-9-ztest
Thanks for the tip!
To be able to use the gameobjects renderQueue i also had to create two custom shaders both for the object that i wanted to be shown in front and the object that would be shown behind, even though the main object was sometimes in 3d space behind it.
The shader for the object that would be shown at the back at all times had ZWrite Off in the pass.
Then it was able to use the renderQueue.
Your answer
Follow this Question
Related Questions
Control render order of geometry besides queues 1 Answer
How do I specify the render order of GameObjects? 2 Answers
Combining multiple layers and water 0 Answers
Camera depthbuffer question. 0 Answers
Rendering to DepthTextureMode.Depth 0 Answers