View Full Version : custom blend function

06-20-2004, 06:53 PM
i have a need for a custom, piece-wise blending function (that is to say, when a semi-transparent polygon is drawn, i wish to apply a formula to determine the resultant pixel color based on the framebuffer's rgb and the current fragment's rgba values). the blending functions in the opengl core functionality are fixed, and do not suit my purposes.

i suppose i require a fragment shader to accomplish this? if so, how can i obtain the contents of the framebuffer at the fragment being drawn? it seems to me that fragment shaders ignore the content of the framebuffer and have very little to do with blending modes.

06-20-2004, 07:34 PM
It's true that you can't access the framebuffer contents from within the fragment stage. You can only access textures, and that's your solution.

You need to get the framebuffer contents into a texture somehow -- either with CopyPixels or a render-to-texture technique (pbuffers).

But I'm curious, what kind of blend equation do you want to implement?
Note that there are a few extensions to blending. There's Min/max and subtraction (new blend "equations"). You can also have separate (rgb vs alpha) parameters and equations.

Maybe you can somehow implement your desired blending by using these extensions?

06-20-2004, 08:20 PM
yes, i supposed that my solution might be along those lines (render to texture, blend, render the blend). that should work nicely.

i don't believe that any of the extended blending functions can help me for this specific task... i want a blending mode similar to photoshop's "overlay" mode, which is a piece-wise function based on the value of the framebuffer color. so i basically need a blend function with an if statement.