Results 1 to 5 of 5

Thread: Particles and Depth Testing

  1. #1
    Senior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Particles and Depth Testing

    My particles are coded as such:
    Code :
    	glDisable (GL_LIGHTING);
    	glEnable(GL_BLEND);
    	glDisable(GL_DEPTH_TEST);
    	glBlendFunc(GL_DST_COLOR, GL_ZERO);
    	glBindTexture(GL_TEXTURE_2D, smoketexture[1]);
    	particles();
    	glDisable(GL_BLEND);
    Now before that code I have code to build the rest of my scene. The problem with this code is that the particle is drawn on top of the whole scene, when I want it to be drawn infront of what is behind it, yet behind what is infront of it. But if I try to reinstate the GL_DEPTH_TEST it messes up my blending. Any ideas?

    And also, how would I implement some more blending afterwards, so that the particles seem to fade accourding to my glColor4f function?

  2. #2
    Guest

    Re: Particles and Depth Testing

    leave depth testing on
    but disable depth masking glDepthMask(GL_FALSE)

    easiest blend for particles is like
    glBlendFunc(GL_SRC_ALPHA,GL_ONE)

    which is additive blending (requires no sorting) and your alpha values influence the blend factor

    other popular blend is transparency
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)

    this however requires that you draw your particles in back to front order (ie furthest from camera first)

  3. #3
    Senior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Re: Particles and Depth Testing

    Ok, the depth mask fixed that problem. But I am still stuck with the blending using the alpha value. The blending function I am using does the desired result with the image, but does not seem to use the alpha value. I need something that will do the same effect, but use the alpha so I can set how opaque it is.

  4. #4
    Senior Member Regular Contributor Swiftless's Avatar
    Join Date
    Apr 2005
    Location
    Australia
    Posts
    118

    Re: Particles and Depth Testing

    Anyone? My particles are making smoke, the smoke is black, if I use the options mentioned, the particle becomes white on the screen. I need it black.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    May 2000
    Location
    Naarn, Austria
    Posts
    1,102

    Re: Particles and Depth Testing

    I think what you need is GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA. But this has the disadvantage that you have to sort the particles for a correct result.

    What may work is GL_ZERO, GL_ONE_MINUS_SRC_ALPHA. But this is only for black smoke, because the color of the particle is entirely ignored with this blending mode... It basically darkens the fragment by an amount specified by source alpha. This mode is order independant, no need to sort here.

Similar Threads

  1. Stencil-op depth fail with depth testing disabled
    By AvCol in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-22-2011, 09:48 PM
  2. depth testing with FBO
    By kreyszig in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 10-07-2008, 04:21 PM
  3. No Depth Testing
    By RebelPhoton in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-12-2002, 11:44 AM
  4. ATI HWA Depth Testing
    By G4Soon in forum OpenGL: macOS
    Replies: 4
    Last Post: 02-21-2001, 06:37 PM
  5. Depth Testing
    By j in forum OpenGL: Advanced Coding
    Replies: 14
    Last Post: 02-05-2001, 06:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean