- Home /
Why zero height mesh gets black independent of shader
When altering the scale of a gameobject with a mesh built procedurally, I've realized it gets all blacked out in Unity5, instead of dark gray in previous versions.
Testing with the default 3D cube from "GameObject -> 3D object -> Cube" the same thing happenned, so I'm confident there's nothing particularly wrong with the mesh generation.
After a couple of trial and error experiments, 1e-12 is the smallest height for which material and color properties seem to take effect in Unity5. In Unity 4.6.1f1 it rendered the expected color with height as low as 1e-19.
Anyone knows why you can't have a zero height render itself correctly and how to do it if there's a way? The project where it's being used doesn't need them to be actually zero height, but the work around for this small problem is quite a lot of work.
Thanks in advance
Yes, zach. Recently the code that generates procedural meshes has been altered to use transform.scale.y to set zero height due to problems arising from settting all vertices to the same height in the mesh itself.
Answer by Piflik · Jul 16, 2015 at 11:43 AM
Unity automatically flips face normals according to the sign of the numbers in the scale-vector, to prevent negatively scaled objects from turning inside out. At 0 scale, this breaks.
The cutoff at 1e-12 doesn't really make any difference compared to 1e-19, neither visaully nor mathematically. There is not much that you cannot do with 12 orders of magnitude that would be possible with 19. Especially if you factor in float-inaccuracies.
If you need flat geometry, use flat geometry, like Planes (NOT aircrafts) or Quads.
The cutoff was really just a curiosity. For another part of this program we really use quads just to avoid all this pain of loosing material properties. However, a few features demand extrudable regular polygons and the work around was set the scale to keep a $$anonymous$$imum height of 1e-12.
Thanks for the attention and the insight on normals.