Problem with shader transparancy

Started by
7 comments, last by Aeluned 18 years, 9 months ago
Hey I've been tring to write a shader that does very basic boolen transparency, but it seems that I can't just set the color's alpha(which is not how I wanted to do it) nor do I seem to be able to get the current color of the pixel in the fragment shader. Something along the lines of 'gl_FragColor = 0.5*gl_FragColor + myColor' didn't work all to well, nor does simply not setting the color. I know I'm ether not finding the write pixel color variable or havn't enabled something. Thanx in advance! -IsMakeFire
Advertisement
knowing my luck I did some more reading and found the 'discard' keyword, so now my question is a matter of getting the pixel color, if possible.

Thanx again, IsMakeFire
IIRC, its not possible to get the dest pixel colour in a fragment shader. Probably because at any given moment you could have a whole bunch of fragments ahead of you in the pipeline that could be doing the same thing, and you'd either get weird results or have to flush your pipeline.

The only solution I think is to read the current framebuffer to a texture and access that in your fragment program.
thank you for the input and ouch, that's a lot of pixels...

How about partial transparency? Is there anyway of setting an opcity to a fragment result? I know I can change the 4th color value, but it dosn't seem to do anything.

Thanx in advance,
IsMakeFire
Quote:Original post by ismakefire
How about partial transparency? Is there anyway of setting an opcity to a fragment result? I know I can change the 4th color value, but it dosn't seem to do anything.
Do you have blending and/or alpha testing enabled?
i know pure transparency is an easy task. just create your texture, color key your transparent areas, and in the shader just discard that color and voila a transparent piece of geometry!
Kalidor: Thanx, I'll check for alpha testing next, I got started on a different project, so I'll try it soon.

Adem17: BTW, PARITAL transparncy is the issue
Quote:Original post by ismakefire
Kalidor: Thanx, I'll check for alpha testing next, I got started on a different project, so I'll try it soon.

Adem17: BTW, PARITAL transparncy is the issue
Alpha testing will render a pixel if it passes a certain alpha function (check out glAlphaFunc), so that is just for full transparency. Blending (look at glBlendFunc) handles partial transperency.

By the way, blending and alpha testing are totally separate from fragment shaders, so you don't need to use them unless you want to do some custom blending that regular blend functions don't support.
Quote:Original post by ismakefire
Kalidor: Thanx, I'll check for alpha testing next, I got started on a different project, so I'll try it soon.

Adem17: BTW, PARITAL transparncy is the issue


color keying isn't an alpha channel.
You should use an alpha channel to get translucency (partial transparency).

enable blending glEnable(GL_BLEND) and you're set - OpenGL will handle the rest for you.

There's really no reason to use fragment shaders for simple blending.

This topic is closed to new replies.

Advertisement