PDA

View Full Version : problem with blending



HamsterofDeath
01-15-2003, 11:09 AM
i got a tree texture, 24 bit, png format
i got a tree mask texture, 256 colors, from black(0% visible) to white(100% visible)

how can i render the tree as a simple 2d texture with parts totally invisible, and some parts 100% opaque ?

i dont want to use masking, because this reduces the performance -> i have to draw everything 2 times

Dan82181
01-15-2003, 11:27 AM
First, take your 24-bit targa file and insert the 8-bit (256 color) mask file as your alpha channel to create a single 32-bit texture. Enable alpha testing by using glEnable(GL_ALPHA_TEST); and setting the alpha comparision using glAlphaFunc(GL_GREATER, 0);

Dan

HamsterofDeath
01-15-2003, 11:30 AM
how to insert it ?

HamsterofDeath
01-15-2003, 11:39 AM
found another (very simple) solution :
glblend on
glcolor4f 1,1,1,1
glblendfunc src_alpha,one_minus_src_alpha -> complete opaque everywhere exept where the texture is black

Dan82181
01-16-2003, 06:25 AM
Problem with the blending approach, it is one of the last things done in the pipeline. With the alpha test method, you can render the tree before or after you render things behind it (i.e. where it should not be rendered, it doesn't update the depth or color buffers at those pixels). With the blending approach, you need to render it after you render everything behind it (so you have to depth sort your objects). Not to mention you will create extra traffic for GL to update the depth buffer where the color shouldn't be updated. The alpha test occurs before the depth test (In case you are planning on using a bunch of trees)

Dan

HamsterofDeath
01-16-2003, 10:52 AM
now everything works fine. no more errors.

[This message has been edited by HamsterofDeath (edited 01-16-2003).]

JustHanging
01-17-2003, 02:29 AM
When using alpha test, you get much better results by using glAlphaFunc(GL_GREATER, 0.5) with an antialiased alpha channel.

-Ilkka