Firstly, thanks to Orangy Tang for pointing this out to me.
Tips on optimising particle drawing (Thanks to davedes) can be found here: http://www.java-gaming.org/topics/storing-adding-drawing-particles/27126/msg/242110/view.html#msg242110
Here are some tutorials on pre-multiplied alpha: :point:
http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Premultiplied%20alpha]]
http://blog.rarepebble.com/111/premultiplied-alpha-in-opengl/
http://www.quasimondo.com/archives/000665.php
It doesn’t seem too complicated but you also need to have the right textures, otherwise it’s not going to work.
Firstly, in the code:
Rather than having two blend modes that we use for drawing particles:
Additive, for fire, etc:
GL11.glBlendFunc(GL11.GL_SRC_ALPHA,GL11.GL_ONE);
And Normal(or Lerp) for smoke: (I use this blendmode for drawing everything else, it should be re-set after drawing the particles)
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Have just one:
GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
Now, you have two different types of particles, smoke and fire. You need to keep track of these because they are drawn in slightly different ways.
Firstly setting the colour:
Additive(Fire):
GL11.glColor4f(r*a,g*a,b*a,0);
Normal “Lerp” (Smoke)
GL11.glColor4f(r*a,g*a,b*a,a);
The other part is the textures.
Additive textures must have a black background.
Normal/lerp textures have a transparent background.
Here is a sample additive texture for fire:
Here is a sample lerp texture for smoke:
If you use an additive texture with a transparent background you will get something like this(BAD):
Final results:
If I have any of this wrong, please correct me!
-roland