Skip to main content
gamedev.net
🔒 Locked

blend function woes

Started by ehmdjii Jun 29, 2006 at 7:51 AM 18 replies 1.5k views
Original Post
ehmdjii
ehmdjii
hello, my current blend function is: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); but i am not getting the blend function result i want. here is a screenshot as you probably guess, i want the green thing to smoothly blend on the ground and not this dark, ugly border. what am i doing wrong? thanks!
Zakwayda
Zakwayda
Make sure to render the yellow and orange shapes before the green shape, not after. I'm guessing that will solve the problem.
ehmdjii
ehmdjii
thanks, but the green part is already rendered after the yellow and orange part.
darkprophet
darkprophet
Do you have alpha testing enabled? If so, disable it.

Alpha testing is yet another gate the fragments have to go through before appearing on the screen (depth and stencil are others); It allows fragments to pass through providing they meet the conditions you have set. For example:

glEnable( GL_ALPHA_TEST );glAlphaFunc(GL_GEQUAL, 0.3f);


That will simply get rid of any fragments that have an alpha that is less than 0.3.

Disabling alpha testing is a simple matter of:

glDisable(GL_ALPHA_TEST);


Regards,
DarkProphet
3rd generation time waster
ehmdjii
ehmdjii
thanks,
yes disabling the alpha test improved it a bit, but still it fades to a dark color on the outside.



btw: if i depth sort all my objects correctly, can i completely drop the alpha test?
darkprophet
darkprophet
The alpha tests as far as I know, have no relation to depth sorting.

You depth sort transperant objects in back to front order to get correct blending as the "source" pixel is taken into account when doing blending. The source pixel is the pixel that was there before the current pixel.

You depth sort opaque objects in front to back order to avoid pixel overdraw.

In short, alpha testing has nothing to do with depth sorting. :)

Regards,
DarkProphet
3rd generation time waster
zedzeek
zedzeek
not much u can do u will have to change the texture's alpha channel instead of such a gradual fade do an abrupt one.
perhaps u can try src_lpah, one but most likely to bright
Ysaneya
Ysaneya
How's your texture set up ?

For the effect you're trying to achieve, i think you should have a constant green RGB color everywhere, and the circular gradient in the alpha. In that case, no dark pixels should appear.

Y.
Jernej.L
Jernej.L
from the screenshoot it looks like your green texture is green ring with alpha channel but you have black color around the green ring, make the ring wholy green.
Projects: Top Down City: http://mathpudding.com/
ehmdjii
ehmdjii
Quote:
Original post by Ysaneya
How's your texture set up ?
For the effect you're trying to achieve, i think you should have a constant green RGB color everywhere, and the circular gradient in the alpha. In that case, no dark pixels should appear.
Y.


that might be the problem, unfortunately i am using png textures which dont seem to support an extra alpha channel. :/
Ysaneya
Ysaneya
PNG images support RGB 24 bits + Alpha 8 bits.

Y.
ehmdjii
ehmdjii
hmmm, i cant seem to get this correctly using photoshop. it does not seem to store an extra alpha channel.

here is the image:
Rasterman
Rasterman
Use a solid green for the color (the whole texture), then for the alpha use a ring as you wanted, you can create 32bit alpha texture in PS, use the alpha channel when editing (controls are in the lower right).
ehmdjii
ehmdjii
yes, i got that, but when i save it out as png, it is fully green with no alpha channel at all.
Falhar
Falhar
try:
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
nts
nts
Quote:
Original post by ehmdjii
yes, i got that, but when i save it out as png, it is fully green with no alpha channel at all.


When saving make sure you choose 32-bit (if it asks). Most viewer programs don't show an alpha channel but only the RGB component. Open it up again in PS and take a look at the channels, alpha should be there.

Solias
Solias
Which version of photoshop are you using? With 7 there are some issues with alpha in pngs. If you just do a save as, the alpha information is discarded. Instead you have to use the save for the web option. I think that's on the file menu if I remember right. This brings up a different dialog box which allows you to save it with the alpha data. However, this uses the transparency of the image as alpha instead of an explict channel when generating the alpha channel in the file. This can make working with the alpha data kind of difficult sometimes. I'm not sure if this has been improved in the latest version of photoshop.
noisecrime
noisecrime
In regards to png issues in Phtotoshop you could look at superPNG as a replacement plugin.
zedzeek
zedzeek
youre getting sidetracked the png or phoyoshop etc aint the problem the alpha is obviously working correctly
try this app which shows how opengl blending works set the background color to yellow + the input color to green + play around with the blending modes + input colors alpha value

http://uk.geocities.com/sloppyturds/stuff/opengl_blending.zip
ehmdjii
ehmdjii
just FYI: after all it was the blendfunc

i am now using
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

and everything looks pretty! :)

Topic Locked

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

Sign in to reply to this topic.