View Full Version : Z-buffer strange behaviour
07-30-2010, 10:00 AM
I cant' understand how z-buffer and depthfunc works in a particular case:
depth func = LEQUAL
depth test = ON
z range between 0 and 1
Now I print, one before other, a set of points WITH THE SAME Z (0.5).
May I be sure that the second is drawn ON the first, the third ON the second and so on?
OpenGL specs say this?
Or this behaviour depends upon video board specs?
Where can I find official documentation about this?
When I try to draw an object AFTER another usually (99%) the second is ON the first, but sometimes I see the opposite!!!!
How can I be sure that the second object is ON the first?
Please help me!!
07-30-2010, 10:45 AM
WITH THE SAME Z (0.5)
Are you sure you have :
- exactly same transformation matrices ?
- exactly same coordinates ?
Indeed this is quite fragile behaviour, can you explain what you want to do ? There may be better ways.
07-30-2010, 02:53 PM
Yes... exactly equal matrix.
I'm learning OpenGL: now I 'only' need to know how, in detail, z-buffer works.
Do you think that, with z-buffer actived and with the same z for each object, I MUST see the second ON the first?
What about if I see the first ON the second? An insufficient precision of z-plane?
07-30-2010, 03:44 PM
Well then it will depend on the implementation, as the smallest variation in how primitive is rasterized will generate different Z values.
Do you draw only triangles, always with the same vertex order, etc ? All the details are important. Can you show a minimal code that produces the problem ?
07-31-2010, 12:16 AM
Of course, I'll send the code on monday when I'll come back at work.
Do you think that it's a anomalous behaviour?
Which is the ideal behaviour as it comes from OpenGL specs?
In other words: what OpenGL specs say? I understand this (zbuffer and depth func actived):
- when z is different, drawing or not depends upon z value (and of course depthfunc)
- when z is the same, drawing or not depends upon temporal order
Is this correct? May I say that anomalous behaviour depends upon poor resolution of video card zbuffer (bit number)?
Help me to understand this!
07-31-2010, 11:33 AM
The OpenGL specs is not very precise about the details of implementation, but AFAIK mentions that repeated rendering of exactly the same data will give exactly the same results. So even with very low depth buffer resolution, it should work as you intended it.
But, this is fragile, ie. you rely on the fact that GL implementation follows the repeated render==repeated result, which may not always work.
That is why I also asked :
can you explain what you want to do ? There may be better ways.
to which you still have not given the slightest clue ...
07-31-2010, 03:03 PM
I'm developing a cartographic software.
Z-buffer range must be (0-10000) with depth-test activated.
At level zero (exactly zero) I've to draw cartographic data (maps, routes, railways, grids and so on), and I have to be sure that the second cartographic layer covers the first drawn and so on for the other layers.
I know that if I can set z=i for the layer number i, depth-test will work fine (even without temporal order, of course) but I MUST put all the layer at level zero.
My goal is being SURE that the second layer covers the first and so on for the others. That's all.
How can I do?
Thanks a lot!!
08-01-2010, 12:03 AM
Just to be sure, when you speak about Z as view Z or as world Z ?
View Z in your case means that the view can not be rotated/translated freely.
World Z has not chance to work by definition (depth buffer only works on view Z).
For view Z, you can have a lot more sublevels, common 24 bits depth allows 16 million different values, so you current "level 0" can be split in 1600 values.
Ortho view or perspective ?
08-01-2010, 12:59 AM
I use ortho view: X (longitude) from -180 to 180, Y (latitude) from -90 to 90 and Z from 0 to 10000 (Everest is less!!).
So, if I've understood well, I use Z as view and as world.
I'm wondering that if I set depth-test=ALWAYS ONLY for cartographic layer on level zero, there is no chance that the layer drawn before covers the layer drawn after, isnt'it?
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.