- Home /
Render one object behind another.
Is there any way to render one object behind another keeping both objects at same position.?In simple both objects will be at same transform.position but in render one should be rendered behind another.how can I accomplish this..?
Answer by Statement · Apr 08, 2014 at 11:25 AM
Change the materials (or shaders) render queue.
Changing material render queue is done by script (either with a custom editor script or at runtime).
Changing shader render queue is done by modifying the shader code itself.
Material render queue is by default the same as shader render queue, but it can be overridden on the material (so two materials can use the same shader, but have different overrides for its render queue).
Note that most shaders will perform depth testing, so if you have two objects intersecting each other, the second rendered object will test depth clipping against the first rendered object.
If your first object doesn't write depth, then it won't be a problem since there will be nothing for the second object to test clip against. Likewise if your first object writes depth but your second object doesn't test depth, it would work as well.
You can also make use of multiple cameras, where you can set one of the cameras to render before the other camera, and make the first camera only render objects with a specific layer where the second camera render objects with an inverted layer. The idea is that the second camera clears depth buffer before rendering.
Thanks man using multiple cameras with different depth did the trick.Cheers :-)
Your answer
