Archived

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

VanKurt

Making grass translucent

Recommended Posts

VanKurt    133
I just played the SeriousSam2 Demo and had to realise that my grass compared to theirs is simply UGLY. Then I found out that they use a simple trick to do a smooth fade between the area with grass and the area without: The more far the grass is away, the more translucent it gets. So I would like to implant this thing into my engine, but I have no idea what blending params to use. At the moment I have a bitmap, load it with an alpha channel (black) and then call "glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);". How can I do this, so that the (black) border around the grass is invisible and that I can specify an alpha-value to make the sprite more translucent ? Thanks, VK

Share this post


Link to post
Share on other sites
zedzeek    529
yes src_alpha, one minus src alpha is the blending mode u want (enable also alphatesting)
turn off lighting + use glColor4f(1,1,1,blend factor) blendfactor=0..1 depending on the distance to the camera

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
VanKurt    133
Mmmmmmmhhhhhh.......
Ok, I use these code before I start drawing:

  
glEnable(GL_BLEND);
glDisable(GL_LIGHTING);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0);
glColor4f( 1.0, 0.0, 1.0, 0.5f );


But everything that happens is that the black border around my sprites is removed.
THE GRASS DOES NOT GET TRANSPARENT !!!
(It doesn''t even matter what 4th parameter I pass to glColor4f (It changes NOTHING))

whyyyyyyyyy ?????
(Perhaps something with the AphaFunc ? I dunno...)

Share this post


Link to post
Share on other sites
merlin9x9    174
Since your grass texture has translucency as defined in an alpha channel and you''re using GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA, why are you doing the alpha test thing at all? You''ll get better-looking results if you do, anyway.

Share this post


Link to post
Share on other sites
zin    110
You say your alpha channel is black?

It should be indicative of where the grass is, i.e. no grass=0, grass=1 or even variable based upon (r+g+b)/3 or some other algorithm, for a fethered effect. This is for the alphatesting to work properly.

And the alpha value in glColor() must be scaled as an inverse function of distance, i.e. alpha=1/length(cameraPos-grassPos). This value is used in conjunction with the texel alpha to do the blending.

What is the alpha value in your texture where the grass is? Perhaps it is too low, enough to pass the alpha test, but not enough for blending.

Curious how your doing grass w/ no green in glColor() btw.

zin

zintel.com - 3d graphics & more or less

Share this post


Link to post
Share on other sites