Archived

This topic is now archived and is closed to further replies.

ByteMe95

OpenGl Blending Problem/Question

Recommended Posts

ByteMe95    122
Hey everyone. I''m working on my first 3d Demo in OpenGl. I just started learning OpenGl a few months ago, pretty much all from this great site. Anyway, I'';ve run into a problem in my demo. I''m trying to make a demo of a rocket ship blasting off. So I got the rocket''s flame to look pretty good using a particle engine, and they all blend together, whatever and it looked good on a black background. But now I want to put in a blue sky background, and when I do the problem I have is that the rocket flame is not only blending with itself to get the right effect, it blends itself in with the blue sky background and doesn''t look right. So, my main question is, how can I have it set up that the rocket flame particle engine only blends with itself, and not with the sky background? Thanks in advance ByteMe95::~ByteMe95() Cerebrum Software

Share this post


Link to post
Share on other sites
ByteMe95    122
Hmm, I just tried both of those suggestings but they didnt work. I think it''s that even though I dont draw the sky with blending, when i draw the particles in blending they blend with the sky in the background, i guess it blends with whatever is in the frame buffer, I think.

I tried the GL_ONE , GL_ONE_MINUS_SRC_ALPHA, but that didnt work, the particles weren''t transparent anymore for some reason.

???

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
ByteMe95    122
I dont think I really know what an alhpa channel is.

I do use alpha blending for the particles, they all have an alpha intensity from 0.0 - 1.0, and then I use glColor4f() with the alpha value and render it.

That''s it, what exactly is an alhpa channel?

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
ByteMe95    122
So can anyone help me with this problem or not?
I''ve been stuck on this one problem for well over a month and my demo hasn''t progressed at ALL because of it

any help would be appreciated
PPPPLLLLEEEEEAAAAASSSSEEEE!!!
(Damn, I promised myself i wouldnt beg! oh well)

;o)

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
DeschutesCore    122
An alpha channel is an additional channel found in several image formats. Targe .tga and personal network graphics .png files come to my mind first. More or less, you have the RGB channels, then the additionals contain all kinds of extras. when I use tga files, I make a mask using the selection tool in paint shop and add that to the alpha channel.

For example:
A common particle bitmap is usually a sphere that is lightest in the center, and darkens towards the edges. The black portion of the image can be copied, and a solid white circle placed in the center of the image that lines up with the last visible portion of your particle. This allows you to use true transparency versus blending which can lead to image distortion. Common particle engines will show the square edge of the quad or triangle if you lighten the background. With alpha channel transparencies there aren''t any egdes, the alpha channel is used to mask the black in the texture.

If I''m not making this very clear, take a close look at Lesson 20, which covers this topic by using a second bitmap as a mask. Using alpha channels is just an advanced way of doing the same thing with only one image.

Jason

Share this post


Link to post
Share on other sites
ByteMe95    122
Hmm, ok, I think I get alpha channels now, I did read lesson 20 so I know what you mean.

Now, my next question is how can I use alpha channels to help my problem? The problem isn''t that the square edges are showing, it''s just that the particles, which should range from red to red-orange in color, are getting blended with the blue background and instead of being red/red-orange are pretty much bright white.

...
Ok, I just took the time to make some screen shots of the rocket with the sky and without it. I should''ve done this a long time ago to demonstrate the real problem instead of trying to exlpain it I guess. I''m not sure if i could put html tags in here, if it doesnt work, just go to the specified URL to check it out:

Without Sky:


With Sky:


Hope I did that right.

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
Bad Monkey    145
Just taking a stab in the dark here, but maybe your sky texture is still bound when you draw your particles.

Try disabling texturing just before you draw your particles (of course, this is assuming that your particles do not use a texture... if they do, make sure you are binding that texture before drawing) like so:

...
Bind sky texture.
Draw sky.
Bind Rocket texture (or disable texturing with glDisable(GL_TEXTURE_2D) )
Draw Rocket.
(Bind particle texture if you''re using one...)
Enable blending.
Draw Particles.
Disable blending.
...

Like I said, I''m just taking a wild swing, but that''s what your pictures look like (ie, they seem to be just using the pixel colour from the last texture coordinate set while drawing with your sky texture).

Hope that was somewhat useful (or at least amusing in its stupidity )

Share this post


Link to post
Share on other sites
Danack    122
It does look like you could be using the wrong blend function, giving an additive effect ie the colours being added. You should be using:

glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

This will do:
Source Colour (of the particle ) * Alpha of the particle +
Colour of destination (ie whats already there, your sky ) * ( 1 - alpha of the particle ).

This is the way to get it looking right against the sky, but you may need to change your colour and alpha values of the particles, as they seem to be set up nicely for being rendered additively against a black background.

In theory you should also do a depth sort and render the furthest transparent particles first before the ones in front.

quote:

I tried the GL_ONE , GL_ONE_MINUS_SRC_ALPHA, but that didnt work, the particles weren't transparent anymore for some reason.




Yep, that's right...that blend function does: source colour + destination colour * ( 1 - source alpha ).
so it would be a weirdy additive effect ie particle colour plus a bit from the background.

Game production:
Good, quick, cheap: Choose two.

Edited by - Danack on January 31, 2001 2:20:47 PM

Share this post


Link to post
Share on other sites
zedzeek    528
for effects like rocket fire
i find
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
doesnt brighten enuf (hell it doesnt brighten at all) thus flames of 20 layers wont look any different to flames of one layer

one one is to bright
one one

one oneminussrcalpha


http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
ByteMe95    122
Hey, thanks for all the replies.

I tried glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); and this is what happened:



I''m sure there are other thinsg I need to change, but I''m not sure what. when I do glcolor4f when drawing the particles I changed Alpha to 1.0-Alpha but that didnt work so I guess it''s completely wrong.

Just so you know, when i draw the particles they are textured and I disable depth testing when drawing them (I thought you had to do that to do blending)

zedzeek, how did you get the slame to draw on that background without mixing in with the sky?



ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
ByteMe95    122
Hey, thanks for all the replies.

I tried glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); and this is what happened:



I''m sure there are other thinsg I need to change, but I''m not sure what. when I do glcolor4f when drawing the particles I changed Alpha to 1.0-Alpha but that didnt work so I guess it''s completely wrong.

Just so you know, when i draw the particles they are textured and I disable depth testing when drawing them (I thought you had to do that to do blending)

zedzeek, how did you get the slame to draw on that background without mixing in with the sky?



ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
zedzeek    528
your texture needs an alpha channel
RGB contain the image colours and A contains the brightness (dont make it too bright)
disable lighting
enable blending
glColor(1,1,1,0.5) // alter alpha to do a fade out

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
redmonkey    122
ive just noticed this thread, as i was gonna post something similar...

i have a font bmp for my HUD, im using just black and white as a mask, and to get different color i modify my color3f()

to make it transparent (ie: no black) i use
glBlendFunc(GL_ONE, GL_ONE); (i have no idea why this works, im thinkging it shouldnt) and only draw that texture/quad once

i also want some of the HUD to be transparent, so i then use glBlendFunc(GL_SRC_ALPHA,GL_ONE); as well.

this works, but like byteme95, it alphablends with the background too much, and red[color3f''d] font on a green background makes it orange. my font doesnt use any alpha channel, but this works, but i want to keep it red on whatever bg its on.

so, i dont want to use alpha blending[i think]... so what can i use?

__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org

Share this post


Link to post
Share on other sites
ByteMe95    122
Well, I just figured out how to make an alpha channel in photoshop, but I jsut realized that BMPs dont store that info. Looks like TGA is the right way to go, but I have NO idea how to load tga files as textures, with alpha channels.

All I know is how to load bmp files as is shown in the nehe tuts.

Anyone have any suggestions? Or beter yet some code?

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites
ByteMe95    122
Ok, I have decide to bring this topic back to life since I never really figured out the problem. I have been kinda busy wtih scvhool work over the past few weeks, but now I have time to crack this nagging bug.

SO...
I put in a TGA loader into my code, loaded my texture with an alpha channel, I''m using glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );, and here''s what it looks like now:



that doesntl look right at all, even if I take away the background sky now, here''s what I get:



that doesnt look like what I want it to look like at all
???
any suggestions now??
I really want to get past this, I think thias demo is gonna be pretty cool, hopefully I''ll be able to get it up on nehe

ByteMe95::~ByteMe95()
Cerebrum Software

Share this post


Link to post
Share on other sites