Currently, I have this code.

I try to do a simple operation : invert Red and Green color components, but I 
get only a black screen.

Could anyone help me ?

Thanks.


Code:
// Configure Camera
p_osgCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
p_osgCamera->setViewport(new osg::Viewport(0,0,800,600));

// Create render texture
osg::Texture2D* textureColor = new osg::Texture2D();
textureColor->setDataVariance(osg::Object::DYNAMIC); 
textureColor->setNumMipmapLevels(0);
textureColor->setUseHardwareMipMapGeneration(false);
textureColor->setResizeNonPowerOfTwoHint(false);
textureColor->setTextureSize(800, 600);
textureColor->setInternalFormat(GL_RGBA);
textureColor->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
textureColor->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
textureColor->setInternalFormat(GL_RGBA16F_ARB);
textureColor->setSourceFormat(GL_RGBA);
textureColor->setSourceType(GL_FLOAT);

// Attach the texture and use it as the color buffer.
p_osgCamera->attach(osg::Camera::COLOR_BUFFER, textureColor);

// Create PPU pipeline
osgPPU::Processor* processor = new osgPPU::Processor(); 
processor->setCamera(p_osgCamera);

// Create colorby pass
osgPPU::UnitCameraAttachmentBypass* colorBypass = new 
osgPPU::UnitCameraAttachmentBypass;
colorBypass->setBufferComponent(osg::Camera::COLOR_BUFFER);

// Create test unit
osgPPU::UnitInOut* testUnit = new osgPPU::UnitInOut;
osg::Shader* fpShader = new osg::Shader(osg::Shader::FRAGMENT);

fpShader->setShaderSource("uniform sampler2D colorTexture;\n"
"void main() {\n"
" vec4 color = texture2D(colorTexture, gl_TexCoord[0].xy);\n"
" vec4 colorTmp = (color.x, color.y, color.z, color.w);\n"
"   gl_FragData[0] = colorTmp;\n"
"}\n");

// create shader attribute and setup one input texture
osgPPU::ShaderAttribute* shader = new osgPPU::ShaderAttribute;
shader->addShader(fpShader);
shader->add("colorTexture", osg::Uniform::SAMPLER_2D);
shader->set("colorTexture", 0);

// attach the shader
testUnit->getOrCreateStateSet()->setAttributeAndModes(shader);

// Create PPU output
osgPPU::UnitOut* ppuout = new osgPPU::UnitOut; 
ppuout->setInputTextureIndexForViewportReference(-1); 

// Setup pipeline ("p_osgRoot" is the OSG node used as sceneData for the 
"p_osgCamera" camera)
p_osgRoot->addChild(processor); 
processor->addChild(colorBypass); 
colorBypass->addChild(testUnit); 
testUnit->addChild(ppuout);




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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to