- Home /
Close meshes render in 2D, but not 3D
I'm making a 2D map using 4 overlapping meshes to give it some randomness. I have them in a specific order, each on a z-axis of 0,-0.01,-0.02,-0.03 respectively.
Everything renders well in 2D, both in the scene editor and an orthographic camera. However, as soon as I switch to 3D to add a bit of a tilt and perspective to the map, the order of the 4 meshes becomes random. Both in the scene editor and switching a camera to perspective.
It seems if I increase the magnitude of the z axis value to close to between 0.5 and 1, then I can get one mesh to appear atop another, but then everything is skewed by that difference in height.
It seems like this is a 3D rendering issue, and should be solvable, but I can't find any information on it.
I think I can narrow this down further. It may have something to do with the shader. I have the Sprite/Default shader applied to the mesh material, which works on 2D.
The closest I can come to a solution is by changing the shader to 'unlit transparent cutout', but the alpha is not smooth on this like the sprite shader in 2D. Ins$$anonymous$$d, all the alpha edges on the meshes are choppy. Is there another shader that could work? Is there another workaround?
After further search on this problem and shaders, I found the correct answer here:
http://answers.unity3d.com/questions/609021/how-to-fix-transparent-rendering-problem.html
Long story short, you can set the renderqueue of the material to different values, so that the order is always the same. This works for 2D as well as 3D. Not obvious, but it works.
Renderer renderer = $$anonymous$$esh32x32PrefabInstance.GetComponent<Renderer>();
renderer.material.renderQueue = 3;
A higher render queue number renders atop lower render numbers.