Particle System: Depth and Blend

Hi!
I am struggling with my point-sprites particle system and the problem I am encountering is that all objects are rendered on top of the point sprites, even though the point sprites are located in front of the object.

What must I do in order to make them show in front correctly? Does it have to do with GL_DEPTH_TESTING or DepthMask?

 PSEUDO-CODE!
glDisable (GL_LIGHTING)
glEnable (GL_DEPTH_TEST)
glDepthMask (GL_FALSE)
glEnable (GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE)
'//Render Particle System

 float quadratic[] =  { 1.0f, 0.0f, 0.01f };
    glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, quadratic );

    // The alpha of a point is calculated to allow the fading of points 
    // instead of shrinking them past a defined threshold size. The threshold 
    // is defined by GL_POINT_FADE_THRESHOLD_SIZE_ARB and is not clamped to 
    // the minimum and maximum point sizes.
    glPointParameterfARB( GL_POINT_FADE_THRESHOLD_SIZE_ARB, 60.0f );

    glPointParameterfARB( GL_POINT_SIZE_MIN_ARB, 1.0f );
    glPointParameterfARB( GL_POINT_SIZE_MAX_ARB, m_fMaxPointSize );

    // Specify point sprite texture coordinate replacement mode for each texture unit
    glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );


    glEnable( GL_POINT_SPRITE_ARB );

    glPointSize( m_fSize );

[Draw Vertex Arrays]
	
glDisable( GL_POINT_SPRITE_ARB );

    glDepthMask (GL_TRUE)
    glDisable (GL_BLEND)
      glEnable (GL_LIGHTING) 

My depth test func is glDepthFunc (GL_LEQUAL)

Another problem is that I am using glcolor4f() and I can’t make particles fade out to transparent. Color fade works correctly but there is no response to the alpha value of glcolor4f. The point sprites use black background texture which gets blended to transparent on runtime. I guess the problem is with glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );?

Any suggestions please?! :rolleyes:
Thanks so much in advance!
Cheers,
Rod

Maybe this is necesary although I don’t think the problem is here… My Vertex Array Render Call:

        glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);

	glVertexPointer(3,   //3 components per vertex (x,y,z)
						GL_FLOAT,sizeof(PointVertex),&m_PVertexArray[0].x);
	glColorPointer(	4,   //4 components per vertex (r,g,b,a)
						GL_UNSIGNED_BYTE,sizeof(PointVertex),&m_PVertexArray[0].r);  //Pointer to the first color

	
	glDrawArrays(GL_POINTS, 0 /*Starting at 0*/, i /*Rendering i points!*/); 

	glDisableClientState(GL_VERTEX_ARRAY);  // disable vertex arrays
	glDisableClientState(GL_COLOR_ARRAY); 

Any help will be deeply appreciated. :slight_smile:

Depth mask maybe, it disables writes to the depth buffer, but the thing is that sprites need to be rendered after all other geometry and not before.
And then all particles should be sorted back to front to acheve optimal quality.

Thanks! Zeeoverlod you are a genius! hehe
So simple and so effective. Depth works like a charm. :smiley:

Any hint on the blend problem?
Cheers!
Rod

Set the texture environment GL_TEXTURE_ENV_MODE to GL_MODULATE and it should fix your fade out issues.

Oops…
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)
screwed up all my textures making my whole world become non-textured flat white shaded.

So I guess that call is not the one you meant.

I then tried:
Call glTexEnvf(GL_POINT_SPRITE_ARB, GL_TEXTURE_ENV_MODE, GL_MODULATE)
but with no results… :frowning:

I placed those calls before my particle system render call

What is wrong? :confused:
With all my objects that use .tga textures blending works perfectly using glblendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).

However my particles system uses .bmp and considers black as an alpha value. I tried with the previous blend func as well as (GL_ONE, GL_ONE) but with no alpha fading results…

Any hints?
Thanks so in advance much Dorbie!
Cheers,
Rod

Hey guys no one has any ideas of what is wrong with my blending?!!! :confused:
Thanks! :slight_smile:

Hmmmm… have you tried
glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ONE );

?

mmm… Just tried it… Doesn’t work either… :frowning:

I tried different glblendfunc with the same “Star” texture. The Star texture is composed by a green star over a black baground, bmp RGB format. This are the results:

-glBlendFunc(GL_SRC_COLOR, GL_SRC_COLOR): stars are shown WITH black background. (Not masked). No alpha fade with glcolor4f.

-glBlendFunc( GL_ONE_MINUS_DST_COLOR, GL_ONE ):
stars are shown WITHOUT black background. (Masked). No alpha fade with glcolor4f.

-glBlendFunc(GL_SRC_COLOR, GL_ONE): Same as previous

-glBlendFunc(GL_ONE, GL_ONE): Same as previous

-glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA):
stars are shown WITH black background. (Not masked). Texture behave rather ramdonly! Stars flash, and appear and dissapear fast on screen… (???.. probably because texture contains no alpha value?)

What is the problem!?
Is it necessary to change to a .tga RGBA texture (instead of using RGB bitmap) in order to achieve the alpha fading effect?

Thanks so much everyone,
Cheers,
Rod

…mmm I guess I am doomed to have no alpha fading :frowning:

Instead of fixing my code (which seems a hazardous task!), could anybody provide a small example of a set of static Point Sprites that have alpha blending/fading ? If you could provide the texture loading, and render code, I would deeply appreciate it, so that I can compare it to mine. :wink:

Thanks so much everyone! :slight_smile:

Cheers!
Rod

:frowning: