2.5D perspective rendering order challenges

I’m createing a 2.5D game, with a 3/4 perspective. Here is a shot of the scene layout. The camera is perspective, and the characters are leaning back so they are flat against the camera view.

My characters are made up of 10 parts each, and although the z-depths of all the parts are correctly layered, I learned that Unity decides which one to render first based on the centerpoint of the object, and not the object itself like you would think. Depending on the camera angle, this makes for some strange results ( I read that somewhere, could be corrected)


I thought I could fix the problem with Shaders and RenderQueue so I created custom shaders for all 10 parts of the character. (Lower leg, upper leg)
I set each shader to Transparent + (1,2 or 3) depending on which level I wanted it to be on. As expected, this works great for one character. However, when there are multiple characters on the screen, the legs and arms always render on-top of the torso, because the Shader tells them to, even if they are behind the other character.


Can anyone help? Is there such thing as selective renderQu? It would be awesome if the z-depth could just handle this so I don’t have to manage it manually.

Also, excuse the art, its temporary :slight_smile:

I am a noob in Unity so maybe this doesnt help but I have a Idea.

make the parts of the body on separate unity layers and make for each layer a own camera.
set the cameras to only render there layer and then you could maybe decide which part of the body is rendered first.

No special shaders required, and no individual layers.

You can modify the shader’s render queue for transparent objects directly:

var queueOffset = 1;
function Start(){
	var allRenderer=GetComponentsInChildren();
	foreach (Renderer r in allRenderer) {
		foreach (Material m in r.materials) {
			m.renderQueue = m.shader.renderQueue + queueOffset;

Attach this script to each (hierarchy) of objects, and select a unique offset for each “layer” you need. Larger offsets mean in front of other object.

Note this might lead to additional drawcalls, as each queue number needs to be processed individually.

EDIT: @joeyaaaaa has a point that all “cutout” shaders don’t do/need transparency sorting, they use standard z-Buffer occlusion. But they only work if you have/want only 100% transparent and 100% opaque pixels, not half-transparent objects.

EDIT2: woops, my code is a mixture of UnityScript and C#. But I guess you get the point.