- Home /
Priority of two (or more) overlapping 3D objects
So I'm making a 3D game, where enemies can overlap each other completely. The enemies are spheres of the same size, but with different materials.
When they overlap, I want to make the higher priority enemy, to be on top. I mean the enemy with number 2 should be rendered completely, and the enemy with number 1 should be rendered partially, where it doesn't overlap with number 2.
Layers don't seem to work, and I kinda want to keep them in place. This is how it looks now: And I want something like this:
Answer by Eno-Khaon · Jul 18, 2021 at 11:52 PM
There are surely other solutions that might work more cleanly for this, but one possible approach would be to create a custom shader (with ZTest Off), then assign a different RenderQueue to each enemy.
By reducing their values below the basic Geometry RenderQueue (2000), this will still allow the environment with depth testing enabled normally to occlude them, where the enemies themselves will render the highest-value-RenderQueue on top.
If their RenderQueue values are the same as each other, then it will generally give priority to the most-recently-updated Material, but that basically leaves it up to luck.
Edit: some rewording