Hi Thomas,
carnibirdy wrote:
>
> Actually, it's not doing anything.
> It's supposed to pass through 4 units...
>
> UnitTexture->UnitInOut->UnitInOut->UnitInOut
>
> ... which does nothing!
>
Of course, this will do nothing. You do not forward the output of the pipleine
to the main screen. The way you did it just do some offscreen rednering. In
order to see the results on the screen, you have to add an UnitOut at the end
of the pipeline.
Here is the code you posted, however, I changed it slightly, so that it works,
like you expect it:
Code:
// Texture unit
osgPPU::UnitTexture* textureUnit = new osgPPU::UnitTexture();
{
osg::Texture2D* greenTexture = new osg::Texture2D();
osg::Image* image = osgDB::readImageFile("Data/Images/reflect.rgb");
if (image)
{
osg::Texture2D* texture = new osg::Texture2D;
greenTexture->setImage(image);
}
textureUnit->setTexture(greenTexture);
}
// Green Shader Attribute
osgPPU::UnitInOut* greenUnit = new osgPPU::UnitInOut();
osgPPU::ShaderAttribute* greenSA = new osgPPU::ShaderAttribute();
{
const char* greenSrc =
"uniform sampler2D textureBase2D;\n"
"void main()\n"
"{\n"
"
gl_FragColor=texture2D(textureBase2D,gl_TexCoord[0].st)+vec4(0.0,0.5,0.0,1.0);\n"
"}";
// create fragment shader for depth test
osg::Shader* greenFS = new osg::Shader(osg::Shader::FRAGMENT);
greenFS->setShaderSource(greenSrc);
greenSA->setName("greenSA");
greenSA->add("textureBase2D", osg::Uniform::SAMPLER_2D);
greenSA->set("textureBase2D", 0);
greenSA->addShader(greenFS);
// Green Unit
greenUnit->getOrCreateStateSet()->setAttributeAndModes(greenSA);
greenUnit->setName("greenUnit");
// we have to setup the viewport of the InOut unit, because the texture
size
// is not defined until the first frame is completly run through
greenUnit->setInputTextureIndexForViewportReference(-1);
greenUnit->setInputToUniform(textureUnit,"textureBase2D",true);
}
// Red Shader Attribute
osgPPU::UnitInOut* redUnit = new osgPPU::UnitInOut();
osgPPU::ShaderAttribute* redSA = new osgPPU::ShaderAttribute();
{
const char* redSrc =
"uniform sampler2D textureBase2D;\n"
"void main()\n"
"{\n"
"
gl_FragColor=texture2D(textureBase2D,gl_TexCoord[0].st)+vec4(0.5,0.0,0.0,1.0);\n"
"}";
// create fragment shader for depth test
osg::Shader* redFS = new osg::Shader(osg::Shader::FRAGMENT);
redFS->setShaderSource(redSrc);
redSA->addShader(redFS);
redSA->setName("redSA");
redSA->add("textureBase2D", osg::Uniform::SAMPLER_2D);
redSA->set("textureBase2D", 0);
//Red Unit
redUnit->setName("redUnit");
redUnit->getOrCreateStateSet()->setAttributeAndModes(redSA);
redUnit->setInputBypass(-1);
redUnit->setInputTextureIndexForViewportReference(0);
redUnit->setInputToUniform(greenUnit,"textureBase2D",true);
}
// setup a unit, which will render the output
osgPPU::UnitOut* ppuout = new osgPPU::UnitOut;
ppuout->setName("Output");
ppuout->setInputTextureIndexForViewportReference(-1); // need this here to
get viewport from camera
// setup viewers camera
setupCamera(viewer->getCamera());
processor->setCamera(viewer->getCamera());
redUnit->addChild(ppuout);
greenUnit->addChild(redUnit);
textureUnit->addChild(greenUnit);
processor->addChild(textureUnit);
node->addChild(processor);
Please, next time, check if all your shaders are loaded (maybe this was the
case). Then check that you have correct pipeline, maybe draw it on a sheet of
paper to see, if you have correctly specified all inputs and outputs. And
please, next time, put full source code file, which can just be compiled by
others. Otherwise it would be hard to get any feedback from other people by
just looking on a small peace of code.
Cheers,
art
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=17627#17627
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org