Terrain edges keep shaking / vibrating....

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 ?

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.

>> gluPerspective(45.0f, w/h, 0.1f, 20000);
I suspect z-fighting caused by insufficient depth buffer precision.
Does the shaking looks like this ? 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

Originally posted by jide:
[b]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.[/b]
Hi JIDE !

Thanks a lot.

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

Originally posted by ZbuffeR:
[b]>> gluPerspective(45.0f, w/h, 0.1f, 20000);
I suspect z-fighting caused by insufficient depth buffer precision.
Does the shaking looks like this ? 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 [/b]
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 ) ?

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.

Originally posted by OGL_PGR:
[b]Hi JIDE !

Thanks a lot.

Water looks a lot better now…( i.e more realistic. )[/b]
No problems :slight_smile: