Transparent pixels for billboards

Hi! I’ve a problem, I can’t for my life make my pixels see-through. I was originally working on a billboard where the colors would set a alpha-value since my texture format .raw doesn’t come with a alpha-channel.

It’s only pictures of explosions and gunfire that’re just white shapes with glowing edges on a black background. I would take 1 minus the sum of the RGB values and devide them on 3 to get a alpha-value, where black is completly see-through and white is completly solid.

However I can’t even make entire models transparent with shaders. It’s silly it doesn’t work, I don’t do anything other in the fragment shader than this:

gl_FragColor = vec4(1.0,1.0,1.0,0.5);

Shouldn’t that give me a half-transparent black model? It just makes my model black and there’s no difference whatever alpha-value I choose. I don’t get any errors and I’ve tried with different colors and textures and my shaders seems to be working perfecly, it just ignores the alpha-value I assign. I’m working with C++ and GLUT and have the glutInitDisplayMode-function take the arguments GLUT_RGBA and GLUT_ALPHA, I thought that would be enough.

glutInitDisplayMode(GLUT_ALPHA | GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);

I’ve done transparent models before without shaders and I don’t remember there being any problem. I’ve googled for similar problems but there doesn’t seem to be any, I would be very happy if someone have any idea what I’ve missed :slight_smile:

Do you have enabled alpha blending ?


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// render explosions

glDisable(GL_BLEND);

Have you read manual? You should check some opangl tutorials…

Draw your explosions last, and disable depth testing.

I would suggest GL_ONE GL_ONE as blendfunc, additive blending is well suited to explosions (but not smoke or dust).

@Zbuffer
yes… you are right.

Thanks for the help, everything works now. I’ve read alot of manuals, my problem is just that I keep forgetting everything :slight_smile:

Btw I said a little wrong in my first post how I would get the alpha-value. If anyone searches for this, this did the trick in my fragment shader:

vec3 color = texture2D(texture,gl_TexCoord[0].st);
float alpha = (color.r + color.g + color.b)/3.0;
gl_FragColor = vec4(color, alpha);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.