PDA

View Full Version : Terrain edges keep shaking / vibrating....



OGL_PGR
06-19-2005, 01:11 AM
Please help me to resolve the following problem:

I have created a terrain using Triangle Strips and it is being rendered properly.

But when I add water ( QUAD with BLENDING enabled - ranging from one end of terrain to the other end, lies somewhere in the middle of the terrain in Y-direction ), the edges where water ( QUAD ) intersect the terrain starts shaking(i.e vibrating).

What could be the problem ?

By the way, this is what happens in the Render() function :

Render()
{
...
...
// Draw Terrain
glPushMatrix();
glScalef(10.0f, 2.0f, 10.0f);
Draw_Terrain_UsingTStrips();
glPopMatrix();

// Draw Translucent Quad for Water
glPushMatrix();
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);

glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(1.0f, 1.0f, 1.0f, 0.3f);

glBindTexture(GL_TEXTURE_2D, WATER_TEXTURE);
glScalef(15.0f, 1.0f, 15.0f);
glBegin(GL_QUADS);
T,V Pair for all the 4 Corners
glEnd();

glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
glPopMatrix();
...
...
}

Please note: I have scaled terrain & the QUAD for water(differently).
- I have used gluPerspective(45.0f, w/h, 0.1f, 20000);

- I also have the latest driver for my RivaTNT2 M64 (v 71.89 WHQL Certified)

Any suggestions ?

jide
06-19-2005, 07:27 AM
I don't see any bad things at first glance. I just can say that if you want to do transparencies then this function should be best than the one you stippled:

BlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);

But that will surely not resolve your shaking problem.

ZbuffeR
06-19-2005, 08:01 AM
>> gluPerspective(45.0f, w/h, 0.1f, 20000);
I suspect z-fighting caused by insufficient depth buffer precision.
Does the shaking looks like this (http://www.ireallydontcare.com/images/crap.JPG) ? Then try with distance values that are nearer to each other, like :
gluPerspective(45.0f, w/h, 2.0f, 10000.0f);

If this reduce the shaking, that's it.

Some background on the topic :
http://www.opengl.org/resources/faq/technical/depthbuffer.htm
http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html
http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node28.html

OGL_PGR
06-19-2005, 08:24 PM
Originally posted by jide:
I don't see any bad things at first glance. I just can say that if you want to do transparencies then this function should be best than the one you stippled:

BlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);

But that will surely not resolve your shaking problem.Hi JIDE !

Thanks a lot.

Water looks a lot better now...( i.e more realistic. )

OGL_PGR
06-19-2005, 08:28 PM
Originally posted by ZbuffeR:
>> gluPerspective(45.0f, w/h, 0.1f, 20000);
I suspect z-fighting caused by insufficient depth buffer precision.
Does the shaking looks like this (http://www.ireallydontcare.com/images/crap.JPG) ? Then try with distance values that are nearer to each other, like :
gluPerspective(45.0f, w/h, 2.0f, 10000.0f);

If this reduce the shaking, that's it.

Some background on the topic :
http://www.opengl.org/resources/faq/technical/depthbuffer.htm
http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html
http://www.opengl.org/resources/tutorials/sig99/advanced99/notes/node28.html Hi ZbuffeR !

Thanks ! I set near to 2.0f and far to 20,000.0f... and now there are no visible vibrations / shaky stuff when I add water.

How come it got resolved when near = 2.0f ?

Is it because of the huge viewing volume when near = 0.1f ( and consequently more rendering to be done for 0.1 than 2.0 ) ?

T101
06-19-2005, 09:55 PM
Look at the "love your z buffer" link.

Basically it boils down to the formula used to encode both tiny distances (0.1) and large distances (20000) into one 16 or 24 bit integer.

It's non-linear, giving more precision near the camera where you normally want it, and less precision far away.

But Steve Baker (in that link) probably explains it better.

jide
06-20-2005, 12:20 AM
Originally posted by OGL_PGR:
Hi JIDE !

Thanks a lot.

Water looks a lot better now...( i.e more realistic. )No problems :)