[osg-users] blending with shader

David Heitbrink david-heitbrink at uiowa.edu
Fri Sep 30 13:09:34 PDT 2016

Its kind of tough to say without having a good idea about what exactly you can do with your plugin. I can say what you most likely need to do is to bind a texture with your blend map to your scene some how.

Ideally you would do this in a 2nd rendering pass. Basically you want to perform blending on a final image. 

In your fragment shader you can use gl_FragCoord, this will get you the screen coordinate of the current fragment (basically pixel). Then you can use texelFetch to lookup a scaler for your output pixel. For example if you had this function you called last in your fragment shader:

uniform sampler2D blendTexture;
void BlendFunct(inout vec4 color){
    vec4 blendVal = texalFetch(blendTexture,gl_FragCoord.xy,0);
    color.rgb = color.rgb * blendVal.rgbl;

In practical terms you often have to deal with the gamma settings for your projectors, and things are not always linear. When you have things in your scene with transparency were things get blended together, its ideal to do a multi-pass rendering.

Read this topic online here:

More information about the osg-users mailing list