Re: Help with shaders
Posted by Martin on Feb 12, 2012; 5:33pm
URL: https://forum.jogamp.org/Help-with-shaders-tp3737063p3737734.html
To ease your understanding: gl_FragColor is set by a second shader, as shown below. In my opinion the global process works well. When using a fixed color in the init fragment shader (e.g. vec4(1.0,0.0,0.0,1.0) ) I can see the dragon colored as expected.
Regards,
Martin
----------------------------------------
uniform samplerRECT ColorTex0;
uniform samplerRECT ColorTex1;
uniform vec3 BackgroundColor;
void main(void)
{
vec4 SumColor = textureRect(ColorTex0, gl_FragCoord.xy);
float n = textureRect(ColorTex1, gl_FragCoord.xy).r;
if (n == 0.0) {
gl_FragColor.rgb = BackgroundColor;
return;
}
vec3 AvgColor = SumColor.rgb / SumColor.a;
float AvgAlpha = SumColor.a / n;
float T = pow(1.0-AvgAlpha, n);
gl_FragColor.rgb = AvgColor * (1 - T) + BackgroundColor * T;
}