Additive/Subtractive blending mode for particle systems

Posts: 1,199
Joined: 2004.10
Post: #1

I've been implementing a mediocre particle system for displaying fire, smoke, explosions, etc. It works pretty well, so long as my needs are simple.

What I've noticed is that for things like fire and explosions, using
glBlendFunc( GL_SRC_ALPHA, GL_ONE );

Makes for a nice additive/saturation effect on the fire particles.

Meanwhile, for smoke,dust,etc I use

This works nicely, too.

The thing is, to model an explosion, I have to use *two* particle systems -- one for smoke and one for fire. This works reasonably well, but since I have depth writing turned off, to give the impression of interleaving I have to do something like:


This causes a mediocre impression of volumetric mixing of smoke and fire. Passable, but not *good*.

The other option is to have the particle system consider some particles to be fire and others to be smoke, and as such, draw some particles with additive GL_ONE and other with GL_ONE_MINUS_SRC_ALPHA. But I don't want to be making so many switches to the blending mode inside of my loops.

So, what I was wondering is this. The ADD_SIGNED parameter for texture blending seems to allow for situations where a value > 128 is added to the destination color and a value of < 128 is subtracted.

Unfortunately, I can't seem to find anything like this for glBlendFunc. It would be great if my particles could start out white, and fade to black over time, where they're additive in the beginning, and transition to subtractive as they get older.

This would eliminate the need for multiple particle systems for explosions.

Is there an extension that does this? Is this possible?
Quote this message in a reply
Posts: 1,234
Joined: 2002.10
Post: #2
I don't think this is possible. There is no such extension available on OS X. Even with a fragment program, the blending stage isn't programmable like you want.

There is probably a way to do this involving multiple passes, or pbuffers with a lot of texture copies, but I'm doubtful it'd be any faster than the state changes. Surely fire+smoke is a solved problem though? Googling on gamasutra/ comes up with this thread, check it out...
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #3
The premultiplicative alpha stuff looks encouraging. Ironically, I removed all NSImage code from my texture loader and replaced it with QuickTime code to *eliminate* premultiplication...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Additive blending for UIKit? BigBrother 0 1,590 Oct 20, 2015 03:52 PM
Last Post: BigBrother
  "Controlled Additive Blending", or, awesome particle system trickery TomorrowPlusX 10 11,624 May 10, 2007 11:09 AM
Last Post: Frank C.
  general blending versus texture blending questions WhatMeWorry 2 6,651 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  Particle Engine bronxbomber92 9 5,031 Oct 16, 2006 03:44 PM
Last Post: bronxbomber92
  Particle trails LongJumper 6 4,564 Jun 29, 2005 12:42 AM
Last Post: LongJumper