[osg-users] blending with shader

Gianni Ambrosio g.ambrosio+osg at gmail.com
Thu Nov 10 00:02:55 PST 2016

Hi All,
I can apply blending to a texture rendered with a RTT camera from a shader but now I have a different problem.

Before blending I have to apply a distortion to the scene because of a projection on a curved screen. Blending image is already distorted so I have to apply blending on an already distorted texture of the scene.
I'm trying to implement distortion/warping moving texcoords of a Geometry node (i.e. geometry->setTexCoordArray(0, tcoords);). That geometry is a grid where the texture, that comes from RTT camera, is applied.

Here is the code to attach the blending shader to the Geometry/Geode:


void addShader(osg::Geode* node, double width, double height)
   osg::StateSet * stateset = node->getOrCreateStateSet();

   osg::Program * program = new osg::Program;
   addFragmentShader(program, blendingShaderFilePath);

   stateset->addUniform(new osg::Uniform("width", (float)width));
   stateset->addUniform(new osg::Uniform("height", (float)height));
   stateset->addUniform(new osg::Uniform("gamma", gamma));
   stateset->addUniform(new osg::Uniform("eye", osg::Vec3(0.0f, 0.0f, 0.0f)));

   osg::ref_ptr< osg::Image> blendingImage = osgDB::readImageFile(blendingImagePath);
   osg::Texture2D* blendingTexture = new osg::Texture2D(blendingImage.get());
   blendingTexture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
   blendingTexture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);

   stateset->setTextureAttribute(1, blendingTexture);
   stateset->addUniform(new osg::Uniform("blendTexture", 1));

The problem is that I can just see the blended image, while distortion is lost.

How could I make distortion/warping live together with blending?


Read this topic online here:

More information about the osg-users mailing list