PDA

View Full Version : Rendering artifacts, possible precision issue?



cluosh
07-26-2015, 08:16 AM
Greetings!

I've stumpled upon an issue while porting ancient OpenGL code. I used that code years ago to display 3D models, using display lists and fixed pipeline; the purpose was to display these models in a shaded mode and as "white" model with a wireframe overlay. This worked perfectly fine with the models i had back then.

Now, I've ported most of the code for modern OpenGL Versions (display lists to VBOs, shaders instead of fixed pipeline), the respective functions, i.e. displaying the model with light and displaying a wireframe overlay, still basically working the same way (using polygon offset for the wireframe overlay). This time I've stumbled upon strange artifacts:
1962 1964

I've seen the same problem before when I wrote the original OpenGL 1.1 code, back then it was a depth buffer issue. So I tried increasing the depth buffer size again in the new version, only to realize it's already 24 bit. My second thought was about the model coordinate range: While models with coordinates ranging from -10 to 10 worked fine, the issues appeared on models with range from 7000 to -7000. I divided the bigger range models through a value close to their maximum and it worked:
1961 1963

I'm not quite sure WHY this works or what caused the artifacts. My best guest would be something related to the float precision, but I don't know.
My question is: Has anybody experienced similiar problems? If so, what might cause these artifacts?

GClements
07-26-2015, 06:04 PM
what might cause these artifacts?

All kinds of things might cause them. But probably the biggest single cause of problems with depth precision is using too small a value for the near distance.

As a rough guide, the portion of the scene beyond N times the near distance gets 1/N of the depth range. So if you make the near distance so small that the closest point on an object is 100x the near distance, 99% of the depth range is wasted and the other 1% is actually used for objects in the scene.

The far distance doesn't make much difference. You can actually set the far distance to infinity without having much effect upon the depth resolution for most of the scene.

cluosh
07-27-2015, 01:49 AM
As a rough guide, the portion of the scene beyond N times the near distance gets 1/N of the depth range. So if you make the near distance so small that the closest point on an object is 100x the near distance, 99% of the depth range is wasted and the other 1% is actually used for objects in the scene.


Thanks a bunch! As you mentioned, I tried moving the far distance, which didn't help. I corrected the near distance and it works like a charm. :)