How does RenderQueue work.

Hi,
So I’ve tried looking through the forums and reading the Shader lab and the scripting help and I still don’t understand renderQueueing so I’m hoping to get a few questions answered. I’m using orthographic cameras in my scene. If I understand it correctly the higher the number the on the renderQueue later the item gets rendered and thus appears above another object.

I have the script from the Wiki that sets “renderer.sharedMaterial.renderQueue” on awake. Why does it only work with transparent/diffuse shaders? Why does it not work if both my materials have the diffuse shader? What about a custom shader? A programmer I know wrote me this universal shader that uses this subshader

	SubShader {
		Tags { 
			Queue = Geometry
			RenderType = Opaque
			}
		LOD 200
		ZWrite On
		Blend SrcAlpha OneMinusSrcAlpha

Could someone explain why using the wiki script to set renderqueueing doesn’t work with it?

Followup question
My project is for iOS, I will probably have a maximum of 10 layers I’m looking to use. Would it be better to simply attach many cameras to the main camera so they all move together set them all to depth only and using the culling mask to separate what appears over what? Can you change levels at runtime?

Which would more likely be less taxing on an iOS. I know there are lots of variables that could affect but on average which would be better.

Thanks
Russ

This is not exactly how it works. Yes, the items get rendered in the order specified by renderQueue, but the bold face part is incorrect. It’s normally the z-buffer that determines which object is rendered on top of which other object. Only when shaders ignore the z-buffer (for example if they use “ZTest Always” in their shader, or when all other shaders don’t write into it (“ZWrite Off”)) does their queue determine which object is on top.

I would recommend using the z-buffer for the layering: set the z-coordinate of your objects to determine their ordering, objects farther away from the camera will be behind objects that are closer. Any other solution is likely to have more overdraw.

2 Likes

Thanks tomvds,
Sorry for not replying earlier, I was on vacation. I’ll start googling z-buffer now. Do you know of any tutorials or walk through about it?
Russ

There is not much to tutorial about z-buffers, as their is very few things you can do with it ;). Objects farther away from the camera will be drawn behind objects that are closer. Since you’re using orthographic cameras, just move objects that need to be before other objects more towards the camera (or objects that need to be behind others farther away from the camera).

The only pitfall is when you mess with the settings of near and far plane. If you make these values really small, or really big, you may run into precision errors.

I go into it starting in Chapter 6.

1 Like