Additive/Subtractive blending mode for particle systems

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

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
Code:
glBlendFunc( GL_SRC_ALPHA, GL_ONE );

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

Meanwhile, for smoke,dust,etc I use
Code:
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

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:

Code:
_smokeSystem->displayEvenParticles();
_fireSystem->displayAllParticles();
_smokeSystem->displayOddParticles();

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
Sage
Posts: 1,232
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/gamedev.net comes up with this thread, check it out...
Quote this message in a reply
Sage
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
  "Controlled Additive Blending", or, awesome particle system trickery TomorrowPlusX 10 8,297 May 10, 2007 11:09 AM
Last Post: Frank C.
  general blending versus texture blending questions WhatMeWorry 2 5,133 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  Particle Engine bronxbomber92 9 3,779 Oct 16, 2006 03:44 PM
Last Post: bronxbomber92
  Particle trails LongJumper 6 3,294 Jun 29, 2005 12:42 AM
Last Post: LongJumper
  Blending mode for Transparent fog? JeroMiya 2 2,667 Jan 30, 2004 08:09 AM
Last Post: MattDiamond