Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2008
    Posts
    57

    Problem with Depth tests- particles vs geometry

    I just finished the particle system VTM's and everything particle related is working perfectly right up until I bring in geometry, the main issue being that either the particles are getting obscured by the geometry or the particles are just being drawn on everything reguardless, and in extreme cases im getting whole faces not being drawn.

    Ive tracked the problem down to the point in the emitters class where it gets rady to draw the particles by disabling the depth test:
    glDisable(GL_DEPTH_TEST);

    I figure im getting issues because nowhere in my loop am I enabling it again. So at the moment im getting this: (I put a cube in the middle to demonstrate)


    To attempt to fix this I tried enabling the Depth test before I drew my geometry, but this caused my particles to always be drawn on top, no matter what. as below.


    Also just stabbing at the dark I thought id take a screeny of never actually disabling the depth tests even when drawing particles, I got this:


    Thank you for taking the time to read this, I can post additional information if needed
    Last edited by reknorak; 12-19-2009 at 11:46 AM.

  2. #2
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    Quote Originally Posted by reknorak View Post
    To attempt to fix this I tried enabling the Depth test before I drew my geometry, but this caused my particles to always be drawn on top, no matter what. as below.
    this seems to be the closest to what you wanted.
    by disabling the depth test, you tell the opengl that you want just that: draw the particles on top no matter what. there's a fundamental issue here: the particles need to be drawn without depth testing, or else the geometry of the different particles will interfere in a way that causes the artefacts in the third picture. since this will cause geometry that is occluding the particles to be overwritten in the framebuffer, you will want to render the particles *before* rendering this geometry.
    however, the particles must also be rendered *after* the geometry it's occluding, or else the alpha blending transparency won't work.

    okay, what now, first i say render it before, then i say render it after - wtf?
    the solution is actually quite easy: render the geometry twice! first render the scene with full depth testing so you have your framebuffer ready for the alpha blending. then render the particles without depth testing. then render the complete scene again with depth testing, which should now only touch those parts of the scene that where illegally overwritten by particles.

  3. #3
    Join Date
    Apr 2008
    Posts
    57
    Thanks san, the explanation makes complete sense but when I apply it to my drawScene function it doesnt seem to beplaying nice, as a test I laid the code out like this:

    Code:
    //draws the Plane and Cube with depth testing
    glEnable(GL_DEPTH_TEST);
    	glDisable(GL_BLEND);
    	glEnable(GL_LIGHTING);
    	glDisable(GL_TEXTURE_2D);
    	drawCube();
    	drawGrid();
    
    	glDisable(GL_DEPTH_TEST);
    	glEnable(GL_BLEND);
    //disables the depth test, loops through emitters and draws particles
    	for ( int i = 0; i < (int)emitters.size(); i++ )
    		emitters[i]->Update( SDL_GetTicks() );
    //draws the Plane and Cube with no depth testing for the second time
    	glDisable(GL_BLEND);
    	glEnable(GL_DEPTH_TEST);
    	glEnable(GL_LIGHTING);
    	glDisable(GL_TEXTURE_2D);
    	drawCube();
    	drawGrid();
    The problem im getting is now my particles are always getting drawn behind geometry. Here's what im seeing at the moment:



    Thanks again

  4. #4
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    looks like a z-buffer problem.

    unfortunately, this stuff can be quite a pain to debug
    first of all, take a look at opengl's depth buffer faq to ensure your basic setup is correct.
    now comes the funny part: acquire a few depth buffer dumps from different rendering stages to isolate the error.
    this means reading the depth buffer back into a texture (*hint-hint*) and from there, make it available for display (either by saving it as a tga or ppm, or by rendering it directly). this will require some research and coding, but it is also an excellent way of making yourself familiar with the depth buffer and its perils

  5. #5
    Join Date
    Jul 2005
    Location
    Norway
    Posts
    122
    my particle related is working particle related is working particles are just before I drew my geometry or the main issue being the main issue being drawn on top, no mattempt to fix this I tried enabling the main issue being particles are just before I drew my geometry, but this caused my particles are just before I drew my geometry, but this I tried enabling it again.

  6. #6
    Join Date
    Apr 2008
    Posts
    57
    Quote Originally Posted by HaZes View Post
    my particle related is working particle related is working particles are just before I drew my geometry or the main issue being the main issue being drawn on top, no mattempt to fix this I tried enabling the main issue being particles are just before I drew my geometry, but this caused my particles are just before I drew my geometry, but this I tried enabling it again.
    Could you break that down for me?

    Sans: Thanks for taking a look, i'll go read through that information and see what my buffer is looking like through the various stages, might take me a couple of days to get through all that, due to xmas and all but ill post my results just incase anyone else is interested

    Merry Xmas

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •