Blending particles with each other but not the environment

Started by
29 comments, last by terrence321 20 years, 6 months ago
So I whipped up a pretty little particle engine, but ran into a rather embarassing roadblock when trying to render the system on anything but a black background. Problem is by blending the source pixels of the particles with the destination, the original color of the effect gets completely washed out. For example if I try my fire effect which looks perfect on a black background, its bright freaking purple against a blue background! So it seems to be what is needed is a way to blend particles with each other and not with the environment (or at least not so much), but still making sure they only blend the circular "particle" shape on the quad... and the whole quads don''t blend together! I would assume this problem has been encountered many times, but I couldn''t find any tutorial or paper that mentioned it. I''d appreciate any suggestions. Terrence
Advertisement
Try this:

glDepthMask(GL_FALSE);

before rendering your particles, and enable it after. I had the same problem once.

HTH
Unfortunately I''ve already tried that with no luck. I just don''t understand how blending a particle with WHATEVER is behind it won''t cause undesired effects, and hugely change the color of the particle system. Do I need to do multiple rendering passes with some sort of alpha mask, or use a 4-channel texture rather than a 3-channel texture and then use the texture''s alpha channel somehow? I know there''s a way.. and it should be simple. But everything I''ve tried just plain doesn''t work.
Now I have tried many blending modes, but just to make it more concrete here is one I''ve tried that works fine w/ a black background but is a nightmare against a blue/red/ whatever other color background.

glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);

Then when I render a particle:

glColor4f(Particle[k].Color[0], Particle[k].Color[1],
Particle[k].Color[2], Particle[k].Color[3] );

So I basically texture a quad with a black and white "particle mask", i.e. a texture showing the shape of my particle, and then modulate its color and alpha based on the line above. What do I need to do to turn this from only working to isolation to blending correctly with the background?
Try rendering the particles first.. that way they shouldn''t blend at all with the pixels that will eventually be behind it
Ingenu: I understand blending is how I''m doing it now, the problem is it doesn''t come NEARLY close enough to approximating reality to be even passable! If I see a fire in real life in front of a bluish wall, the fire will be pure red no matter which way I look at it, with maybe a slight tint from the background. With the blending I''m using the fire would be BRIGHT PURPLE. That just won''t do. So that''s in essence what I''m asking, how do I change my blending mode to avoid that problem?
Anonymous Poster:
When I draw the particles first, then the scenery is always drawn on top of them, even if I use glDepthMask(GL_FALSE) before rendering them rather than glDisable(GL_DEPTH_TEST). Does that seem right? I''ve tried so many different things, but just trial and error isn''t enough to be able to unify:
1)Particle quads only displaying the particle in the middle of it, which is not just a single white dot but a white dot blended into gray on its borders.
2)Particles need to blend with each other (so they get brighter, as fire or something should) but either minimally or not at all with the background (because that completely destroys the color of the original effect).
3)Particles need to be occluded by scenery, i.e. they can''t COMPLETELY ignore the depth test or they''ll be drawn if they''re behind walls.

I''ve tried using multiple render passes, blend modes, and tried drawing particles before or after the scenery, and these three criteria were never met all at once. This can''t be that complicated, can it?
the blending equation is given as args to the glBlendFunc, a quick hack with to answer your question might be to render your particles to a pbuffer(W/ blending enabled) and billboard the texture to a quad ....but this is awfull , you might want to render the particles at first and disable blending when it comes to rendering the background, but this is a hack to , I''ll give you a proper way to do this a bit later (of course if your interested in another way to do it)since I must take a nap heh.....
I don''t know what is so hard to understand about the problem..
http://www.geocities.com/terrence321/untitled.JPG
That effect is supposed to be very red. Imagine an explosion in a game that was purple. Acceptable? No. As you can see beyond the bluish quad the pixels are their original color. I''m basically trying to figure out how to CONSTRAIN my blending, so that particles blend with each other, and still are "particle"-shaped (i.e. not quads with circles in the middle of them), but so that they DONT blend with the background in some instances. It would be desirable for smoke to blend with the background, because it is transparent. An explosion is not for the most part transparent, and I''d like my explosion effect regardless of background to look almost identical to how it looks on my black background. Phew, I hope that made a little more sense!
And anonymous poster please do, I''ve spent hours on all kinds of extras for this particle system, but without being able to USE it in anything, it would be all for naught.

This topic is closed to new replies.

Advertisement