PDA

View Full Version : jagged coastline problem



Danno
12-12-2005, 10:12 AM
I am having issues doing a simple water quad over a terrain square.

Once I place the Quad into the scene with the height-mapped terrain. I get a jagged coast-line. I am not sure what I am doing wrong here. I think I have correctly enabled blending, because the water is transparent.

here is a screenshot
http://filebox.vt.edu/users/dahill1/Guest/jaggedcoast.jpg

What am i missing here?
I've placed this code before the water:

glEnable( GL_BLEND );
glDepthMask( GL_FALSE );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );

glPushMatrix();
glBegin( GL_QUADS );

//water
glColor4f( 0.0f, 0.2f, 0.7f, 0.7f );
glVertex3f( 0.0f, 20.0f, 0.0f );
glVertex3f( 0.0f, 20.0f, (float)[terrain iSize] );
glVertex3f( (float)[terrain iSize], 20.0f, (float)[terrain iSize] );
glVertex3f( (float)[terrain iSize], 20.0f, 0.0f );


glEnd();
glPopMatrix();

glDepthMask( GL_TRUE );
glDisable( GL_BLEND );

I also enable it with glDepthTest, and glDepthFunc

I am not sure what else to do here to remove the jagged coastline. The resolution shouldn't be too much of an issue, because its 128 x 128.

dorbie
12-12-2005, 12:31 PM
Your problem is caused by limited zbuffer precision.

You can fix this by pushing the near clip plane out a little bit and pulling the far clip plane in to some sensible value, (the near clip value will have most influence over the quality). Basically you want to fit everything in the scene or that might be in the scene between the clip planes but also accept a bit of near clipping if something gets really close.

I'd bet you've set near to something like 0.01 and far way out there in like 100000.0 just to catch everything, it sounds like a good idea but infact it's not for reasons you've now discovered (there are other problems with it too). It's a very common mistake.