Opaque and Translucent Objects Intersection Artifacts
So I'm trying to add water to a terrain engine I'm working on. And just to start out I'm drawing a blended quad that intersects with the landscape at the height I want the water to appear. The problem is where the quad intersects the terrain there's some nasty drawing artifacts. When the quad is entirely above or below the terrain and doesn't intersect in any places it draws fine.
Is this a known problem with OpenGL or am I missing some crucial step?
Here's a picture of the problem (with textures turned off):
http://www.killerrobots.com/pictures/water_problem.jpg
And here's some of the code:
Is this a known problem with OpenGL or am I missing some crucial step?
Here's a picture of the problem (with textures turned off):
http://www.killerrobots.com/pictures/water_problem.jpg
And here's some of the code:
Code:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(VertexRec), &vertices[0].x);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexRec), &vertices[0].u);
glNormalPointer(GL_FLOAT, sizeof(VertexRec), &vertices[0].nX);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f ); // Full brightness, 50% alpha
glEnable( GL_BLEND );
glDepthMask( GL_FALSE );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
glBegin(GL_QUADS);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(50, 5.8, 0);
glVertex3f(100, 5.8, 0);
glVertex3f(100, 5.8, 100);
glVertex3f(50, 5.8, 100);
glEnd();
glDepthMask( GL_TRUE );
glDisable( GL_BLEND );
Check that your near and far clipping planes are as close to each other as possible.
Yea, this looks like your z buffering is too inaccurate. but if you have a static terrain, I would consider creating exactly matching polys in the first place, it would certainly not make the situation worse, at least, just more complicated.
- D.G
- D.G
Okay, that was it. I had: "gluPerspective( 45.0f, sceneBounds.size.width / sceneBounds.size.height, 0.099f, 500.0f );" and I changed it to: "gluPerspective( 45.0f, sceneBounds.size.width / sceneBounds.size.height, 1.0f, 350.0f );" and now it works fine. I hate it when answers are that obvious...
Is there anyway to get more precision in the z-buffer? Switching to a 32-bit depth buffer maybe? I probably won't need really long views for this project, but it would be handy to know in case it comes up in the future.
Is there anyway to get more precision in the z-buffer? Switching to a 32-bit depth buffer maybe? I probably won't need really long views for this project, but it would be handy to know in case it comes up in the future.
Quote:Originally posted by Bachus
Okay, that was it. I had: "gluPerspective( 45.0f, sceneBounds.size.width / sceneBounds.size.height, 0.099f, 500.0f );" and I changed it to: "gluPerspective( 45.0f, sceneBounds.size.width / sceneBounds.size.height, 1.0f, 350.0f );" and now it works fine. I hate it when answers are that obvious...
Is there anyway to get more precision in the z-buffer? Switching to a 32-bit depth buffer maybe? I probably won't need really long views for this project, but it would be handy to know in case it comes up in the future.
32 bit z-buffer is not always available, I think I can only get 24 on my gf2mx. So don't rely on that to fix your problems.
- D.G
The best way to get Z precision is to ensure that near is never less than 1. You can take far out quite a long way with no problems as long as you keep that restriction on near...
Quote:Originally posted by OneSadCookie
The best way to get Z precision is to ensure that near is never less than 1. You can take far out quite a long way with no problems as long as you keep that restriction on near...
The near and far planes can be anywhere you like provided the ratio between them isn't too great. If your object dimensions were very small you probably would have to have your near plane closer than 1.0 unit, so to avoid getting Z buffer shearing you'd have to make sure the far plane was proportionally closer as well.
With regards to Z buffer depth, under AGL you can ask for AGL_MAXIMUM_POLICY and AGL_DEPTH_SIZE = 32 to get a 32 bit Z buffer if one is available. If the hardware doesn't support it, you get whatever its maximum depth is instead. Of course, you should still test with a 16 bit Z buffer to make sure your game doesn't look terrible!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES 2.0, 2D Alpha Transparency Artifacts | Macmenace | 3 | 6,080 |
Mar 28, 2010 11:18 PM Last Post: AnotherJake |
|
| Need ray-sphere intersection code | MattDiamond | 23 | 12,816 |
Aug 31, 2009 02:28 PM Last Post: Gengar003 |
|
| Multisample AA Artifacts | metacollin | 4 | 4,281 |
Aug 14, 2009 07:11 PM Last Post: metacollin |
|
| Shadow Mapping - Self-Shadowing Z-Fighting Artifacts | Bachus | 16 | 16,609 |
Feb 11, 2009 12:24 PM Last Post: arekkusu |
|
| 2d Polygon Intersection | bizimCity | 6 | 5,977 |
Aug 31, 2006 05:29 PM Last Post: reubert |
|

