Additive blending for flames

Oldtimer
Posts: 832
Joined: 2002.09
Post: #1
I was just wondering, how do you guys set up additive blending for flame particle systems? I have one that looks quite okay... against dark/brownish backgrounds. Against bright green or bright blue, it becomes pure yellow, since the green channel maxes out together with red.

I set up the blending mode as follows:
glBlendFunc (GL_SRC_ALPHA, GL_ONE);

...and drawing a dark-red flame sprite with about 0.5-alpha.

Is this the best way to do it?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
That's usually the blend I use as well. Maybe the alpha function needs to be specified differently. Just a wild guess. I still don't quite understand how blending works myself.
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2011.07
Post: #3
If I recall correctly, it should be:

(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA).

That should be somewhat of a decent compromise.
Quote this message in a reply
ben_dyer
Unregistered
 
Post: #4
Generally I find that additive blending works well for flame-type effects. However, if you're ending up with a solid colour, you might like to try throwing in tiny values for the particle G and B (depending on the number of particles, perhaps around 0.02). This makes everything blend to white eventually (or, if you omit the B component, yellow); I do muzzle flashes that way. Steady flames (e.g. a candle) are a bit more complex, so you might like to try particles of different colours with different alpha values. Finally, for the outer, lower-energy parts of the flame, you might find a blending function of GL_SRC_COLOR for the source, and GL_ONE_MINUS_SRC_ALPHA for the destination works well. Basically, that works the same as additive blending (except all your source colour values will be effectively squared), only you get to control the amount of background that gets through via the alpha channel of the source. So, as particles lose energy and become redder, you can send their alpha values towards one, so less of the background gets through. Basically, experiment -- just those two blending modes give you a huge amount of flexibility!
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #5
Chopper had some of the particles using the additive blend mode and the rest using the normal blend mode. This helps avoid the "everything goes to white" problem. But it still had it's problems.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Moderator
Posts: 770
Joined: 2003.04
Post: #6
The thing with fire is that flames aren't really transparent. There is some opacity ( Blush "spelling" corrected) which is pretty obvious if you watch fire in front of, say, a white wall: the flame will still be yellow/orange. So, pure additive blending doesn┬ąt fully reflect the true nature of flames.
Quote this message in a reply
w_reade
Unregistered
 
Post: #7
Opacity.
[extra chars]
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #8
I think the blending problem lies with using too few particles. You can use the normal blending (eg. GL_SRC_ALPHA, GL_SRC_ALPHA_MINUS_ONE) if you have a lot of particles and their color is animated to change as they progress on the flame/explosion, for example go from blue to yellow to brown. Of course, loads of particles slow down rendering somewhat, you have to see for yourself what is acceptable.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  "Controlled Additive Blending", or, awesome particle system trickery TomorrowPlusX 10 7,777 May 10, 2007 11:09 AM
Last Post: Frank C.
  general blending versus texture blending questions WhatMeWorry 2 4,897 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  Additive/Subtractive blending mode for particle systems TomorrowPlusX 2 4,373 Dec 10, 2004 05:29 AM
Last Post: TomorrowPlusX