[osg-users] blending with shader

Gianni Ambrosio g.ambrosio+osg at gmail.com
Fri Nov 11 07:19:05 PST 2016


Hi David,
thanks it works!

Here are my vertex and fragment shaders:

Code:

varying vec2 texCoord;

void main(void)
{
   gl_Position = ftransform();
   texCoord = gl_MultiTexCoord0.xy;
}




Code:

uniform float width;
uniform float height;
uniform float gamma;
uniform sampler2D sceneTexture;
uniform sampler2D blendTexture;
uniform sampler2D blackTexture;

varying vec2 texCoord;

void main(void) {
   vec4 sceneColor = texture2D(sceneTexture, texCoord);
   vec2 fragCoord = vec2(gl_FragCoord.x/width, gl_FragCoord.y/height);
   vec4 blendColor = texture2D(blendTexture, fragCoord);
   vec4 blackColor = texture2D(blackTexture, fragCoord);
   vec4 gammaVector = vec4(gamma, gamma, gamma, 1.0);
   gl_FragColor = pow(pow(sceneColor*blendColor, gammaVector) * (1.0 - pow(blackColor, gammaVector)) + pow(blackColor, gammaVector), 1.0/gammaVector);
};




I had to use fragCoord for blending images because those images must not be distorted.
Is that code correct? I mean, it works but maybe there is a cleaner way to implement that. In particulare, is there a way to avoid passing "width' and "height" variables to the shader?

Regards,
Gianni[/img]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69332#69332








More information about the osg-users mailing list