- Home /
Orthographic camera rendering order not always working
Hey if anybody could shed some light on this I'd be grateful... Basically I'm determining the render order of all my on-screen gameobjects each frame by setting their vertices each frame - and setting the z value to determine which should be down in front of which... The objects are all flat planes with just 4 verts .... This all works fine most of the time - but in some places where I'm sure that the z verts are being correctly assigned, some objects which should be in front of others are being drawn under them... And I really can't see why... FYI - this is a conversion from an iPhone game so that's why I'm doing it like this - in the original code the objects were rendered in the precise order they should be drAwn so each time I draw something I increase a global var that contains the z-depth for the next drawn object... Camera is orthographic... Any clues? Thanks, Ross
Not all shader perform a ZTest. $$anonymous$$ake sure yours do.
In Unity the forward direction is along the z-axis, so make sure you're not mistaken with it. The z coordinate and the z of the z-buffer are two different thing.
Answer by ScroodgeM · Aug 16, 2012 at 12:01 PM
first. check this
second. check shaders. shaders also have a render queue value that is more important that z position. shader with lower queue value will render first.
third. for transparent objects they are sorted using it's pivots. so be sure not vertices but pivots are sorted in right order
Answer by Ross_S · Aug 25, 2012 at 04:26 PM
Thanks for your answers here - The problem did seem to have something to do with using the transparent shader - when i turned it off - everything was rendered right - the solution that finally worked for me was to set the 'render queue' value for each GameObject's mesh renderer material - like so...
so each frame for each GO it's ... ...
meshRenderer.material.renderQueue = Globals.renderQueueCounter; Globals.renderQueueCounter += 1; ...
basically... thanks
methinks you should fix object's pivots. check any two objects that are renders in incorrect order - what is the distance from camera to that objects pivots?
i admit i didn't put too much effort into it but i couldn't really see where the pivots were - as the objects are all simple planes i presumed the pivot would just be in the middle of that plane. I'm repositioning them by changing the 4 verts - that doesn't also change the pivot?
it's an orthographic camera - my first attempt to get render order working was by using the z - axis... but that wasn't working...
repositioning verts always leave pivot in place, cause vert has coordinate relative to pivot. so you should use verts position so that one dimension is 0. for example (1,1,0) (-1,1,0) (-1,-1,0) (1,-1,0) and move along z axis using pivot (gameObject.transform.position)
I'm repositioning them by changing the 4 verts - that's an answer to your issue 8)
Hey thanks Scroodge - you are totally right - i fixed it as you recommended and it's working perfectly...
Your answer
Follow this Question
Related Questions
How to resize a camera's orthoSize for an object to fit inside its rect viewport? 1 Answer
Why is part of object outside camera frustum visible? 1 Answer
is it possible to set the view port rect at both ends 1 Answer
Set renderable objects on camera without Layers 2 Answers
Orthographic camera "cutting off" part of the frame 2 Answers