Advertisement

Particle Blending

Started by August 09, 2002 12:56 PM
2 comments, last by Monder 22 years, 6 months ago
Ok I''ve decided to use OGL ortho mode to do 2d stuff. I made a simple particle engine and set up blending using this function glBlendFunc(GL_SRC_ALPHA,GL_ONE); That worked great while on a black background. I changed the background color to blue for a test and my once orange/red fire went pink/white. I assume the particles are blending in with the background. What is a good way to stop this while the particles still blend well(I think it''s called additive blending). I tried some other blend modes but my particles all looked like little balls. For my particle texture I am using a radial gradient that fades from white to black. I then tint this using glColor. Oh it''s a bmp
I think there''s a way by using alpha-blending. I tried screwing around which the glBlendFunc but couldn''t get anywhere so I continued using masks. This is how I do it...

glEnable(GL_BLEND);
glBlendFunc(GL_DST_COLOR, GL_ZERO);
... (Draw texture mask here - 2 colors - black for where any drawing should occur)
glBlendFunc(GL_ONE, GL_ONE);
... (Draw actual texture here)
glDisable(GL_BLEND);

Luigi Pino
The 23rd Dimension
Advertisement
Yeah I tried using masks but the particles are all little balls again. Oh well, I''ll work it out
use GL_ONE, GL_ONE_MINUS_SRC_ALPHA for your blend functions.

this allows you to do a mixture of additive mixing and standard alpha compositing.

use glColor4 to color your particles whatever color you want. the alpha component will be the "mix" factor -- the higher this number, the less background color you get. because you''re using GL_ONE for your source blend mode, you don''t affect your particle color with your alpha so there''s no change to the fg color being mixed. by setting your alpha to 0 you''re actually simulating GL_ONE, GL_ONE blend functions (purely additive).

i''m guessing you only need an alpha of perhaps one tenth of your particle''s "brightness" to keep it feeling like light, but to also keep its inherent color.

make sure your texture is applied to the alpha as well.

This topic is closed to new replies.

Advertisement