Here is a sample fragment shader that implements one of the blend modes (overlay) for A/B mixing. If you can show me how to get this working in a patch that has two texture inputs for one rect object at the end of a gemhead render chain, that would really be awesome, and I could wrap it easily in an abstraction.
Thanks for taking the time to look at it. Yeah, I know, weird Jitter texcoord template, deal with it :)
uniform vec4 amount;
// define our rectangular texture samplers
uniform sampler2DRect tex0;
uniform sampler2DRect tex1;
// define our varying texture coordinates
varying vec2 texcoord0;
varying vec2 texcoord1;
vec4 one = vec4(1.0);
vec4 two = vec4(2.0);
vec4 lumcoeff = vec4(0.2125,0.7154,0.0721,0.0);
vec4 overlay(vec4 myInput, vec4 previousmix, vec4 amount)
{
float luminance = dot(previousmix,lumcoeff);
float mixamount = clamp((luminance - 0.45) * 10., 0., 1.);
vec4 branch1 = two * previousmix * myInput;
vec4 branch2 = one - (two * (one - previousmix) * (one - myInput));
vec4 result = mix(branch1, branch2, vec4(mixamount) );
vec4 mixresult = mix(previousmix, result, amount);
return mixresult;
}
void main(void)
{
vec4 input0 = texture2DRect(tex0, texcoord0);
vec4 input1 = texture2DRect(tex1, texcoord1);
vec4 mix1 = overlay(input1, input0, amount* two );
vec4 mix2 = overlay(input0, input1, (1.0 - amount) * two );
vec4 result = mix(vec4(mix1.rgb,1.),vec4(mix2.rgb,1), amount);
gl_FragColor = result;
}
varying vec2 texcoord0;
varying vec2 texcoord1;
void main()
{
// perform standard transform on vertex
gl_Position = ftransform();
// transform texcoords
texcoord0 = vec2(gl_TextureMatrix[0] * gl_MultiTexCoord0);
texcoord1 = vec2(gl_TextureMatrix[1] * gl_MultiTexCoord1);
}