- Home /
Ordering glitches when far away from camera?
I have a textured mesh where every vertex has y == 0, and a camera looking straight down at it. I also have a LineRenderer that I use to draw on top of the mesh in solid color (e.g. to outline a part of the mesh). For the LineRenderer, I set every line vertex to have e.g. y == 1. All is good when the camera is relatively close to the mesh; however, when the camera is some distance away, the lines reliably "jump" under the mesh - I can see them properly only thru the transparent holes in the mesh texture. The jump is not gradual, as I move the camera very slowly at some point the lines just "disappear"/"reappear". Is this a bug of some sort? Is there a better way to enforce ordering of what's visible in this case?
Answer by tanoshimi · Sep 19, 2016 at 07:28 PM
What you're describing sounds like a case of Z-fighting. Try increasing the distance between the linerenderer and the mesh, increasing your camera's near clip plane, or reducing its far clip plane.
How does unity resolve it for sprites? I am using meshes because sprite logic seems unwieldy for rendering a large dynamic map, but now I wonder if I should switch from meshes from sprites or if I could managed to do what unity does for sorting layers.
Sprites are really just billboarded quads - there's nothing special about the way they're rendered. But yes, sorting layers is another option.
What I mean is, how does Unity make sure there's no z-fighting between these quads? How is sorting layer implemented, in principle? If two quads for two sprites have the same z, Unity presumably does some magic to make sure they are always in sorting order on the screen... Is it using some special renderer?
Answer by flaviusxvii · Sep 21, 2016 at 02:34 AM
I think @tanoshimi is on the right track. An alternate solution would be to use a material/shader that doesn't do depth testing. That way the line will always appear on top. Also, if this is going on far from the origin (like the camera position has elements in the thousands.. then floating point precision issues will creep into everything causing jitters and whatnot.
Your answer
Follow this Question
Related Questions
Geometry in one room has a silhouette that shows through other geometry? 0 Answers
Heap problem when creating a large number of objects. 1 Answer
More tris after adding material?! 0 Answers
Remove part of a mesh or points of pointcloud 1 Answer
[PS4] Mesh becomes invisible in-game after it rotates for a while 0 Answers