Hello,
actually i try to integrate a blur shader to my test scene. To realize
this I've implemented a small scene with a dot3 textured quad (done by a
shader). This scene is rendered to a texture oriented on the distortion
example. This works fine, but when i bind the secondary blur shader on
this render to texture pass i got no blur effect. The 2nd shader is
definitively executed, if i set the glFragColor of this second shader to
some test value (i.e. blue) the texture is rendered by this color value.
I've attached the actual rtt-Pass with the 2nd shader binding. Have i
overseen something?
Best regards,
Christian
// set up the render to texture camera.
{
float m_height = 1024.0f;
float m_width = 1280.0f;
osg::Geode* m_geode = new osg::Geode();
osg::Geometry* m_geometry = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array();
vertices->push_back( osg::Vec3( 0, 0,-1) ); //Lower-left
vertex
vertices->push_back( osg::Vec3(m_width, 0,-1) );
//Lower-right vertex
vertices->push_back( osg::Vec3(m_width, m_height,-1) ); //Upper-right
vertex
vertices->push_back( osg::Vec3( 0, m_height, -1) );
//Upper-left vertex
m_geometry->setVertexArray(vertices.get());
// Set the normal in the positive z direction (torwards the user)
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array();
normals->push_back(osg::Vec3(0.0f,0.0f,1.0f));
m_geometry->setNormalArray(normals.get());
m_geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array();
texcoords->push_back(osg::Vec2(0.0f,0.0f));
texcoords->push_back(osg::Vec2(1.0f,0.0f));
texcoords->push_back(osg::Vec2(1.0f,1.0f));
texcoords->push_back(osg::Vec2(0.0f,1.0f));
m_geometry->setTexCoordArray(0,texcoords.get());
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(0.8f,0.8f,0.8f,0.8f));
m_geometry->setColorArray(colors.get());
m_geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
// define render mode and attach to geode
m_geometry->addPrimitiveSet(new osg::DrawArrays
(osg::PrimitiveSet::QUADS, 0, vertices->size()));
m_geode->addDrawable(m_geometry);
// new we need to add the texture to the Drawable, we do so by creating
a
// StateSet to contain the Texture StateAttribute.
osg::StateSet* stateset = m_geometry->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,
texture,osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
// create Shader sources
osg::Program* m_program = new osg::Program();
osg::Shader* m_vertexShader = new osg::Shader(osg::Shader::VERTEX);
osg::Shader* m_pixelShader = new osg::Shader( osg::Shader::FRAGMENT );
bool ok = loadShaderSource(m_vertexShader, "shader/motion.vert")
&& loadShaderSource(m_pixelShader, "shader/motion.frag") ;
if(!ok)
{
std::cout << "Couldn't load shaders" << std::endl;
exit(1);
}
m_program->addShader(m_vertexShader);
m_program->addShader(m_pixelShader);
osg::Texture2D* texture2 = new osg::Texture2D;
texture2->setTextureSize(tex_width, tex_height);
texture2->setInternalFormat(GL_RGBA);
texture2->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
texture2->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
stateset->setTextureAttributeAndModes(1,
texture2,osg::StateAttribute::ON);
stateset->setAttributeAndModes(m_program, osg::StateAttribute::ON);
stateset->addUniform(new osg::Uniform("Prev", 0));
stateset->addUniform(new osg::Uniform("Next", 1));
stateset->addUniform(new osg::Uniform("fBlur", 0.90500f));
// set up the camera to render the textured quad
osg::CameraNode* camera = new osg::CameraNode;
// just inherit the main cameras view
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
// set the camera to render before the main camera.
camera->setRenderOrder(osg::CameraNode::NESTED_RENDER);
// tell the camera to use OpenGL frame buffer object where supported.
camera->setRenderTargetImplementation(osg::CameraNode::FRAME_BUFFER_OBJECT);
// attach the texture and use it as the color buffer.
camera->attach(osg::CameraNode::COLOR_BUFFER, texture2);
// add subgraph to render
camera->addChild(m_geode);
quadNode->addChild(camera);
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org