Parts of a runway dissapear randomly - why

Hi!
I have a bit of terrain surface which is completely flat onto which I put my runway. A few simple textured quads which are glued to the terrain surface.
Now the terrain surface is at height 54.0 and the runway I put slightly higher then the terrain surface ie. at 54.005 which in real world would look like it is hanging above the ground about 20 cm. I guess this is right way of doing because if I rendered terrain surface and the runway quads at the same height ie. 54.0 then the runway would be shown partially and the terrain would also be shown pratially or not at all. This is what I am getting. its annoying because my runway doesn’t stay still. it sort of pops or flashes (random parts of runway dissapear- NOT whole quads just parts of it). appears and dissapears even though it is slightly higher than the terrain surface. I wonder why??
I am drawing in my loop first terrain and then the runway. both have GL_DEPTH_TEST enabled!?
oh yeah. Once I am getting closer to the runway (say landing) then the runway becomes more visible and when I land I can see the runway properly! what do u think is wrong?

In real simulators do u think they hang the runway slightly higher on Y axis eg. by .00005 then the terrain or both terrain and runway are rendered at the same height but they apply some tricky methods to make the runway visible.
Please let me know if you know something about it!! thank you!

Below you can see the screenshot of the problem I am getting:
(Parts of runway which this time dissapeared are circled!)

http://homepage.ntlworld.com/robert.stuliglowa/projects/GL-Flightor/temp/temp.htm

[This message has been edited by robert_s (edited 02-28-2002).]

You are probably experiencing ‘z-fighting’: depth buffer accuracy causes nearly-equal depth polygons to alternately obscure each other.

Possible solutions are (YMMV):

  • increase depth buffer precision by increasing zNear, decreasing zFar and making the ratio zFar/zNear as small as possible
  • use polygon-offset when drawing the landing strip
  • disable depth test when drawing the landing strip (could be tricky if partially obscured by buildings…)
  • texture the terrain itself with the landing strip

HTH

Jean-Marc

It seems like 20 cm are not enough :wink: Ok, the problem is, that the resolution of the z-buffer depends on the near and far plane you choose. If you have a big terrain you have maybe set the near and far plane the the extents of your terrain. Then the resolution of your z-buffer could be less than 0.005 and you get z-fighting.
To avoid this you have two possibilities:

  1. You set the near and far plane only to the extents of your visible system (where the fog limits the terrain).

  2. You use glPolygonOffset instead of offsetting the runway by yourself. glPolygonOffset add’s a value to the rendered pixels in the z-buffer. So it is independent of the near and far values.

Kilam.

Try using GL_LEQUAL instead of GL_LESS as your depth test function (or GL_GEQUAL if you’re currently using GL_GREATER).

Are u guys talking about
gluPerspective(65.0, (GLfloat) winWidth/(GLfloat) winHeight, 0.1, TERRAIN_LENGTH*4);
function.

hmmmm… Znear I could increase a little bit but Zfar I can’t decrease it as what you can see on the screenshot this is a small terrain patch.
far into the distance is my skybox. now if I decrease the Zfar it will clip my skybox partially.

JML you suggesting not to use GL_BUFFER_TEST for the terrain. do u mean no BUFFER test at all for the whole terrain?
but what about all those hills and stuff? they will be all visible at the same time. even those behind other hills. won’t they?
I’ll try anyway!

Kilam Malik
if I decrease the Zfar distance from camera to fog back edge then I will se only my terrain but not front face of my skybox.
I have’nt tried the glPolygonOffset. I’ll try that now!!

zeckensack
I am already using
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//render terrain
//disable depth test.
Thanks guys for help!! I am going to try to use glPolygonOffset and see if it’ll help. First I need to understand how it works! .
If not then otherwise I’ll be forced to increase the distance between runway and the ground which will look a bit odd.

[This message has been edited by robert_s (edited 02-28-2002).]

Originally posted by robert_s:
Are u guys talking about
gluPerspective(65.0, (GLfloat) winWidth/(GLfloat) winHeight, 0.1, TERRAIN_LENGTH*4);
function.

Argh! Another z-killing victim!

Never ever set your near clipping plane to 1.f or closer!

richardve
I thought that zNear cannot be set to 0.0 or less than but becuase its a float,
so 0.1 I thought will not be equal to 0.0 and therefore it is ok!?

In spec I found its says “zNear must never be set to 0”
Why you saying that set to 1.0 is still wrong? I dont get that as in specs they dont mention that. They say that setting to 0.0 is wrong!! ???

BTW I’ve set the zNear to 5.0 to be on safe side but it still gives me the same undesired effect! arghh…

So now I have
gluPerspective(65.0, (GLfloat) winWidth/(GLfloat) winHeight, 5.0, TERRAIN_LENGTH*4 );

24576 = TERRAIN_LENGTH*3;

JML
I disabled GL_DEPTH_TEST before I render my terrain and it proves now that I don’t really need buffer GL_DEPTH_TEST enabled when rendering terrain.
Is it true? so whe they advice in tutorials to use GL_DEPTH_TEST when rendering terrain?

[This message has been edited by robert_s (edited 02-28-2002).]

Originally posted by robert_s:
JML you suggesting not to use GL_BUFFER_TEST for the terrain. do u mean no BUFFER test at all for the whole terrain?
but what about all those hills and stuff? they will be all visible at the same time. even those behind other hills. won’t they?
I’ll try anyway!

Correct, forget that suggestion. The rest may help you though.

On the zBuffer: the ratio zFar/zNear roughly determines how many bits out of the available depth-bits are available (the red book has an explanation of this). Due to the perspective projection, the depth bits are exponentially distributed between zNear and zFar, with most of the precision being used in the area quite near to the zNear.

Jean-Marc.

Thats what I thought! as when you get closer to the ground then the runway becomes full visible but when ur really high above ground then the runway is almost invisible. You can see only terrain.
So the terrain wins the Zbuffer fight!

Regarding the Z-fighting problem due to ZNear and ZFar values, richardve already explained everything in this thread:
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/005502.html

Though you’d find it interesting.

Regards.

Eric

Originally posted by richardve:
[b] Argh! Another z-killing victim!

Never ever set your near clipping plane to 1.f or closer![/b]

Never say never. It all depends on your scale. The important thing is not how large or small the near/far clip planes are set to (except that near cant be zero), but how near/far they are relative to each other. Using a near of 1.0f and a far of 1000.0f is equivalent to using a near of 0.01f and a far of 10.0f.

For a FPS, you probably want to make your world units something like feet. In that case, you probably want to have a near plane of something like 1.0f (and several thousand for the far), but in a flight sim, its probably more convenient to do world units in miles, and have a near plane of 0.1f or less (and maybe up to 100.0f for the far, just guessing).

Thanks eric!!
I found in that forum a link to the excellent paper about my problem!

which is http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

Thanks all! I simply need to increase the zNear to 1.0. but the problem I’ll get is that If I set it to 1.0 I’ll lose near polygons. Eg. the current setting 0.1 allows me to land on ground without clipping the close polygons (ground in front of me) and when I park on the runway then the height from the planes cockpit seat to the ground looks quite realistic like eg. 2 meteres high above ground but when I increase the Znear to 1.0 then automatically the cockpit must be positioned heigher above the ground to prevent clipping the nearest polygons. If I do that then it looks as I am 20 meters above the ground instead of 2 meters which would look a bit odd. In this case I would have to change the whole engines scale factor. Ie. make the runway, buildings, mountains etc… 10 times bigger then they are now! arghh… this will be a bit of extra work!!

LordKronos! it looks as you got my point!!


It all depends on your scale!

I mean won’t argue with anyone here as I am sure you’re all much more advanced as me but I am just trying to find some excuse to not to rewrite my code again!

It looks as I 'll have to as my zNear is at 0.1 and zFar at 24576, so 0.1-24576 is a bit not right!!

[This message has been edited by robert_s (edited 02-28-2002).]

Originally posted by LordKronos:
Never say never. It all depends on your scale. The important thing is not how large or small the near/far clip planes are set to (except that near cant be zero), but how near/far they are relative to each other. Using a near of 1.0f and a far of 1000.0f is equivalent to using a near of 0.01f and a far of 10.0f.

Have a look at the screenshot I’ve posted in the topic mentioned by Eric…

Hey richardve I can see that you had a nice & gentle conversation with Evil-Dog! haha!! Joking!!

I can’t see the link to ur screenshot! could you cut/paste it here plz??!
Sorry I’m blind!
I’m serious I can’t find it!

[This message has been edited by robert_s (edited 02-28-2002).]

Originally posted by robert_s:

If I set it to 1.0 I’ll lose near polygons. …

One solution to this is to always keep your near:far ratio the same, but to have the whole window slide. The main reason in a flight sim for having such a large far clip plane is because you need to see hills and mountains way off in the distance. On the other hand, you normally dont have close objects in the sky, so you can offset this with a larger near plane value.

However, when landing, you have much closer objects (as you noted), so you have to decrease the near plane value. At the same time, you usually dont have to see things quite so far away (mountain ranges can be a problem, but most everything else is obscured by nearby hills). what you can do is try to experiment with a sliding near:far window, where once you get below an elevation of X, you being to slide the window closer to 0. How close to scale, as well as how to scale it (linear, logarithmic, etc) I can’t say…you will have to experiment. But it seems to me like maybe its the best choice.

[This message has been edited by LordKronos (edited 02-28-2002).]

Originally posted by richardve:
Have a look at the screenshot I’ve posted in the topic mentioned by Eric…

I looked at it, Im not sure what it shows exactly, other than that your near to far ratio was too large and you got some type of z error. You can fix this by either pushing out your near clip plane or pulling in your far. The screen shot doesnt seem to have any bearing on what I said (unless you were just trying to visually demonstrate what I said).

Yeah!! this is a good idea LordKronos!
I am going to experiment with this!
THANKS!!!

You wrote that you can’t decrease zFar because of your SkyBox. But you could draw the SkyBox first without depths buffer writes and checks. There is nothing behind the skybox so you don’t have to check. Then you could set the zFar to the end of fog.

Kilam Malik.

Exactly!! but for some reason I still get the skybox clipped at the zFar why??
see the screenshot here http://homepage.ntlworld.com/robert.stuliglowa/projects/GL-Flightor/temp/temp.htm
this is what I have:

GLvoid display(GLvoid)
{
// Clear the buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();

glPushMatrix();

//--- RENDER SKY --------
renderSkyBox();

Render Terrain and other stuff!!
blah blah …
} //end of display

GLvoid renderSkyBox()
{
glDisable(GL_DEPTH_TEST); glDisable( GL_BLEND );
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
//====>>>>>>> draw skybox here <<<=======//
glDisable(GL_TEXTURE_2D);
}

Is there anything I forgot to add!!??
I thought that for example if the sky fron wall is 1000 units from me and my zFar clipping plane is set eg. to 100 from me then regardless if I use depth buffer or not I’ll not see teh front wall as its clipped! is it true or false? I am not sure!

[This message has been edited by robert_s (edited 02-28-2002).]

Yes, if it’s that large then it gets clipped regardless of whether you enable depth testing. However, what Kilam Malik was saying is that if you render it first, and without depth writes, you can make it any size you want. It’s centered around your camera, so changing its size does not change its appearance. Hence, you can make it small enough to fit in front of the far clipping plane. It doesn’t change the Z-buffer, so you can just render the rest of your scene on top of it afterwards.

– Tom