Skip to main content
GameDev.net gamedev.net
🔒 Locked

glBlendFunc and particles

Started by Darkeye Jan 28, 2005 at 9:41 PM 7 replies 2k views
Original Post
Darkeye
Darkeye
Hey, A friend and I have just completely a particle system in OpenGL. As per most resources on the subject, the blending function we're using is GL_SRC_ALPHA, GL_ONE. Whilst this works fine on black backgrounds, when we try to draw on a white background then clearly the (1.0, 1.0, 1.0) is scaled up by 1x to give (1.0, 1.0, 1.0) - and our particles are totally invisible. We are unable to find any combination of blending functions that give good results. Does anyone have any solutions to this?
Renegade
Renegade
Long time no see Darkeye, how's it going?
Forfaox
Forfaox
Well, with a blending function as you specified, what you're doing is for each fragment that you draw, you multiply it with its alpha, and then add to that the value of what's already in the framebuffer. This is then clamped to [0, 1]. So if there's pure white in your framebuffer, no matter what color your particles are, the pixels will always end up white.

A possible solution is using GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, but this will require you to sort the particles from back to front.
Magicdude
Magicdude
We did try this, as that is our default blend mode to work properly with our tgas. However, when using this blend mode, the particles lack any kind of intensity and look very flat. I assume this is because they arent taking into consideration the intensity of white in the particle image. Any idea how to fix this one?
Forfaox
Forfaox
I'm sorry, I don't really understand your problem.. could you try to explain it in more detail, or show a small screenshot or so?
Magicdude
Magicdude
OK, here's an image. The one on the left is with teh normal SRC_ALPHA, ONE blend mode on a black background. The one on the right is with SRC_ALPHA, ONE_MINUS_SRC_ALPHA on a white background. As you can see, on the left tehre is a feeling of intensity at the core, while on the right, teh particles look flat and lifeless. Any idea to make this look any better?
Renegade
Renegade
Looks like they want flames instead of orange sherbert.
Forfaox
Forfaox
After some experimentation and putting some thought into it, I haven't been able to find a blendfunc that will work the way you want. I found that a blendfunc of GL_ONE, GL_ONE_MINUS_SRC_ALPHA came close though, so maybe the solution can be found in that direction.
Darkeye
Darkeye
I think perhaps the solution may lie in drawing each particle twice - once with the blendfunc set so we get soeme kind of mask to draw the particle onto, and once to actually draw the particle properly.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.