Sign in to follow this  
MARS_999

Alpha/Blending in GLSL

Recommended Posts

MARS_999    1627
Ok with the FFP to do alpha testing/blending you would just
glEnable(GL_BLEND);
glEnable(GL_ALPHA_TEST);
glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

adjust your blendfunc() to suit your needs. Now do I still have to call these functions with GLSL being used to do my rendering instead of FFP? I guess I haven't found much on how to work with GLSL in this manner. What I am trying to do is add in transparencey to my water so I can see the terrain shore line... Thanks

Share this post


Link to post
Share on other sites
Kalidor    1087
Alpha testing, blending, and fragment shaders are three separate pieces of the graphics pipeline; you can still enable alpha test and blending in the usual fixed-function way and it will work even if you are using fragment shaders. You can use fragment shaders to implement your own alpha testing and/or blending functionality if you really wanted to though.

You can do something similar to alpha test by discarding the current fragment depending on the alpha and you can implement your own blending functionality by passing a texture of the scene to the fragment shader and blending in some way with the texel that corresponds to the current fragment.

It's probably better to use the standard OpenGL alpha test/blending if you can however.

Share this post


Link to post
Share on other sites
zedzeek    529
Quote:
It's probably better to use the standard OpenGL alpha test/blending if you can however.

not better, its the only way. glsl has no recogition of blending.
u can emulate alpha test though with the discard function

Share this post


Link to post
Share on other sites
Kalidor    1087
Quote:
Original post by zedzeek
not better, its the only way. glsl has no recogition of blending.
u can emulate alpha test though with the discard function
Yes, in the second paragraph I mentioned you can discard the fragment to do your own alpha test and you can read from a texture to do your own blending. I meant to imply that they are both possible but far from optimal, but I should've clarified better.

Share this post


Link to post
Share on other sites
rick_appleton    864
Quote:
Original post by Kalidor
... you can implement your own blending functionality by passing a texture of the scene to the fragment shader and blending in some way with the texel that corresponds to the current fragment.


Quoted for clarity. GLSL has no way of reading the current value in the framebuffer. This means that to do such blending you'd need to render the entire scene into a texture, and then use that in addition to any geometry you want blended. In practice, for the case you mention, you'll never want to do this. The normal fixed function pipeline blending is still used as it is a part of the pipeline that is still fixed, and the comes _after_ your fragment program.

Share this post


Link to post
Share on other sites

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