PDA

View Full Version : Blending



dukey
02-28-2011, 05:51 PM
I am trying to export images with transparency, ie not composite them on a white background. So .. anyway. I am wondering is it possible to do this


char *fragmentTransComposite =

"uniform sampler2D tex1;\n"
"uniform sampler2D tex2;\n"

"void main()\n"
"{\n"
"float alpaTotal;\n"
"vec4 colourFinal;\n"
"vec4 colour1;\n"
"vec4 colour2;\n"

"colour1 = texture2D( tex1, gl_TexCoord[0].st );\n"
"colour2 = texture2D( tex2, gl_TexCoord[0].st );\n"

"alphaTotal = colour1.a + colour2.a;\n"

"colour1.rgb = colour1.rgb * (colour1.a/alphaTotal);\n"
"colour2.rgb = colour2.rgb * (colour2.a/alphaTotal);\n"

"colourFinal.rgb = colour1.rgb + colour2.rgb;\n"
"colourFinal.a = alphaTotal;\n" // <-- will get clamped

"gl_FragColor = outColour;\n"
"}\n";

without a shader? With just the standard blending modes.

Essentially for alpha I just want to add the values together.
For colour I want to multiply them by

SourceColour * SourceAlpha / Alpha Total
then
DestColour * DestAlpha / Alpha Total

then sum them together

Dark Photon
03-01-2011, 06:15 AM
Take a look at texture combiners (old pre-shaders feature):

http://www.opengl.org/wiki/Texture_Combiners

You may be able to do this all in one pass without any blending (haven't mentally mapped it all -- middle stage with sum/blend might be tricky -- but the rest is garden variety register combiners). If not, you can also break into two passes.

dukey
03-01-2011, 09:46 AM
I really wanted to do this without blitting between 2 render targets, because it gets very expensive ! But it honestly doesn't look like it's possible with the standard ogl blending modes.