- Home /
Why pixel artifacts on aligned cubes?
There seem to be lots of posts on this but without satisfactory answers. I know quite a bit about 3D rendering (primarily OpenGL) and something does seem to be going on. See this screenshot marked up with the artifacts:
The project is attached.
Now this is a project freshly created in Unity 4.5 on OS X (Mavericks) running on MacBook Air (2011 version). Should be an easily supported platform.
The first row of cubes (closest to screen with z=0) are just 8 unit cubes, positioned at 1, 2, 3 etc. with no parents. You can verify the transforms in the (forced text) scene file, they look like:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 1, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1}
Next row (z=1) is same, but moved 0.5 to the right.
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 1.5, y: 0, z: 1} m_LocalScale: {x: 1, y: 1, z: 1} etc.
Next row also offset by 0.5 in the x direction, and is at z=2 in an empty parent at z=2 (otherwise all at origin).
The last row is a copy of the third parent, moved to z=3, and the cubes are shrunk to 0.5 in the y direction and moved to y=0.25.
All these should be perfectly aligned (floating point can be "approximate" but not in the case of 1, 0.5, and 0.25) given their coordinates and parents. In OpenGL, vertices with the same floats are guaranteed to rasterize lines between them perfectly the same no matter which primitive they are from, to avoid precisely this problem. So it's not a problem I'd expect in Unity, given the scene setup.
However, all rows exhibit pixel artifacts at the seams, in both the scene view, the game view (small), and the game view (full screen). Depending on the exact camera position/orientation, the pixel artifacts scintillate along the seams.
The material is a simple blue diffuse, with a single directional light. The camera is orthographic.
So what's going on? I'd like an explanation beyond "vertices are fuzzy" or "try expanding your cubes" because something is definitely amiss. Thanks.
Don't have an answer for you but just had a play around and here are my findings:
Reproduced on Unity 4.3.4f1 on Windows 8
Supplied project behaved the same as you reported. Clean project replication behaved the same
Testing at 1024x768 primarily
At fixed camera and resolution, artifacts appear regardless of directional light rotation (provided target is lit).
With no lights at all, I cannot reproduce the artifacts. I have tried manipulating the ambient colour to no effect. Using an unlit material gives the same result.
Point lights do not seem to produce the artifacts.
The artifacts appear in builds as well.
Seems to be something to do with directional lights? Point light seems to not give these same issues.
I noticed similar, but white artifacts with a combination of two directional lights and a single point light. These seem more random/"picky" than the black ones and I'm not convinced they're related, except from see$$anonymous$$gly having something to do with aliasing.
I'm struggling with the same problem. I can confirm that this is also definitely related to Directional Lights. @mlepage Did you ever figure out a solution for this?
Answer by Lythox · Nov 29, 2016 at 07:00 AM
I HAVE FOUND A SOLUTION THOUGH FOR THIS AWFUL PROBLEM: Fiddle around with the "Clipping Planes" of your main camera. I have changed my clipping plane (near) of my main camera from .01 to 1, and suddenly all grid artifacts are gone!
Your answer
Follow this Question
Related Questions
Grid matching issue 0 Answers
Adding Imperfections? 1 Answer
What is wrong with my code? 1 Answer
Round position 1 Answer
How to display a picture with his own pixel size on a cube? 0 Answers