GL_DEPTH_TEST dilemma
In order for my explosion particles to draw correctly, I have to disable GL_DEPTH_TEST. But when I do this, if the explosion occurs behind a hill, I see them drawn on top of the terrain. When I don't disable it, they don't show up correctly when drawn over each other, but the hill correctly masks the explosion. Any ideas of how to fix this?
You need to draw your transparent objects from farthest to nearest.
Just to clarify, you need to draw your particles from farthest to nearest, with the depth test on.
Try disabling depth *writes* with glDepthMask instead of the entire depth test.
All you need to do Is for every frame:
Enable depth test
Enable depth write glDepthMask(GL_TRUE);
Draw everything that IS NOT using transparencies first.
Then disable depth writting ( glDepthMask(GL_FALSE); ) and draw your explosion.
happy coding!...
Enable depth test
Enable depth write glDepthMask(GL_TRUE);
Draw everything that IS NOT using transparencies first.
Then disable depth writting ( glDepthMask(GL_FALSE); ) and draw your explosion.
happy coding!...
The depth mask trick won't work unless all your sprites are uniform in color and opacity, since the blending equation is not symmetric.
This is why you need to draw them farthest to nearest.
If you draw them after all opaque objects, whether you write depth or not should be irrelevant, except perhaps to performance.
This is why you need to draw them farthest to nearest.
If you draw them after all opaque objects, whether you write depth or not should be irrelevant, except perhaps to performance.
OneSadCookie Wrote:If you draw them after all opaque objects, whether you write depth or not should be irrelevant, except perhaps to performance.
If your explosion is nothing more than fire, and smoke you don't care about back-front because explosions will blend together.
If there's more than one explosion going on and the closest explosion is draw fefore the second one you may not get the desired results if writes to depth buffer is ON when drawing.
![[Image: explode.jpg]](http://shamrock.med.nyu.edu/~garcij01/explode.jpg)
multiple explosions
Thanks for all the tips you guys have given me, but I'm having a hard time figuring out how I'm actually going to fix it.
See, I'm using the code from the OpenGL Game Programming Book for windows. I'm using my own "engine" code plus the game code from the book. I'm doing everything the same way that the book does it (or so I think) but it isn't working correctly. Anybody have experience with this code? I'm referring to the game that involves shooting the MD2 models on the terrain.
Thanks again,
Wheatie
See, I'm using the code from the OpenGL Game Programming Book for windows. I'm using my own "engine" code plus the game code from the book. I'm doing everything the same way that the book does it (or so I think) but it isn't working correctly. Anybody have experience with this code? I'm referring to the game that involves shooting the MD2 models on the terrain.
Thanks again,
Wheatie
Seems like you're doing everything ok.
when you call glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
depth is reset properly, so I don't think you need to call glClearDepth(1.0f); // that sets all the bits in the depth buffer to it's highest value.
when you call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); the depth
buffer is set to it's highest value(1.0).
so when you set glDepthFunc(GL_LESS); depth test will return true if the pixel z value is less than the one stored in the depth buffer.
I think the problem is on the glDepthFunc(GL_GREATER);
you should use glDepthFunc(GL_LESS);
this is a fragment from my enterframe function in my engine.
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glDepthMask(GL_TRUE);
glColorMask(1,1,1,1);
glDepthMask(GL_TRUE);
glShadeModel( GL_SMOOTH );
objHandle = modelSearchResult[0];
n = modelSearchResult.GetIndex();
for(i=0; i<n; i++)
( (S3Model3D*) objHandle[i] )->BeginDraw();
UpdateGameObjectSearchStack();
S3Physics::EnterFrame();
-----------------
another way it may work is calling glClearDepth(0.0f);
glDepthFunc(GL_GREATER);
when you call glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;
depth is reset properly, so I don't think you need to call glClearDepth(1.0f); // that sets all the bits in the depth buffer to it's highest value.
when you call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); the depth
buffer is set to it's highest value(1.0).
so when you set glDepthFunc(GL_LESS); depth test will return true if the pixel z value is less than the one stored in the depth buffer.
I think the problem is on the glDepthFunc(GL_GREATER);
you should use glDepthFunc(GL_LESS);
this is a fragment from my enterframe function in my engine.
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glDepthMask(GL_TRUE);
glColorMask(1,1,1,1);
glDepthMask(GL_TRUE);
glShadeModel( GL_SMOOTH );
objHandle = modelSearchResult[0];
n = modelSearchResult.GetIndex();
for(i=0; i<n; i++)
( (S3Model3D*) objHandle[i] )->BeginDraw();
UpdateGameObjectSearchStack();
S3Physics::EnterFrame();
-----------------
another way it may work is calling glClearDepth(0.0f);
glDepthFunc(GL_GREATER);
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
GL_DEPTH_TEST and or Blending | Volte | 1 | 3,558 |
May 7, 2009 04:49 PM Last Post: AnotherJake |
|
GLSL dilemma (in my Objective-C application) | arrelid | 21 | 12,515 |
Sep 8, 2006 07:02 AM Last Post: arrelid |