Sign in to follow this  

Problem with shader transparancy

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this