Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Weird jagged edges / precision problems

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2018
    Posts
    8

    Weird jagged edges / precision problems

    Dear Community,

    I'm having strange issues at the edges of my object:
    Click image for larger version. 

Name:	WeirdJaggedEdges.jpg 
Views:	25 
Size:	4.5 KB 
ID:	2598
    Click image for larger version. 

Name:	WeirdJaggedEdges2.jpg 
Views:	28 
Size:	6.1 KB 
ID:	2599

    The edges appear to be from the other side of the cube.
    Does anyone know what is going on? I'd love to hear it because I've been looking around but haven't been able to find an answer.

    Depth testing is enabled. I'll create a git if access to the code is required.

    Best regards,

    Jip

  2. #2
    Junior Member Newbie
    Join Date
    Jan 2018
    Posts
    8
    Strangely, it always happens to be that once you've asked and / or posted a question anywhere you find the answer yourself an hour or two later.

    What happens is a Z-buffer conflict. The fragments are fighting over which one is in front of the other one - that is also why this only happens at the edges of the model and not in the middle. The following things can fix this:
    - decrease the difference between the near and far field of the frustum (perspective matrix). Especially very small near values (0.1 or smaller) cause a lot of issues, because the most detail is at the beginning of the frustum.
    - When the values mentioned above cannot be changed, perhaps increase the bit depth of the depth buffer. You can increase this to 24 bits - if this doesn't help then your buffer was probably already at 24 bits by default.

    Hope this helps anyone!

    Best regards,

    Jip

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,829
    Quote Originally Posted by Jippie View Post
    - decrease the difference between the near and far field of the frustum (perspective matrix). Especially very small near values (0.1 or smaller) cause a lot of issues, because the most detail is at the beginning of the frustum.
    To elaborate upon that: -Z values which are beyond N times the near distance use approximately 1/N of the range of depth values. So e.g. -Z values beyond 10 times the near distance only use 1/10th of the range of depth values.

    So if the near distance is too small, most of the scene will have greatly reduced depth resolution.

    The far distance doesn't actually have that much effect; in fact, it's entirely possible to have the far plane at infinity, using the projection matrix:
    Code :
    [X 0  0   0]
    [0 Y  0   0]
    [0 0 -1 -2n]
    [0 0 -1   0]
    where n is the near distance, and X and Y are the scale factors determined by the field-of-view angle and the aspect ratio. You can see how this arises by examining the matrix constructed by glFrustum and considering that as nearVal becomes small compared to farVal, both nearVal+farVal and nearVal-farVal become approximately equal to farVal, so C and D tend to -1 and -2*nearVal respectively

    With the far plane at infinity, the proportion of depth values used by -Z values beyond N times the near distance is exactly 1/N.

  4. #4
    Junior Member Newbie
    Join Date
    Jan 2018
    Posts
    8
    @GCElements, thank you for the further elaboration!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •