Hi, Marcus: First, I set up the render to color texture camera, and set the render order to PRE_RENDER, and the render target to FRAME_BUFFER_OBJECT, then I set up the render to normal and depth texture camera, with the same render order and render target. I use the uniform variable to tell the GLSL what to set to gl_FragColor, if RENDERNORMALANDDEPTH is set false, the gl_FragColor is set to the shaded color, otherwise, I set the normalized normal vector in the RGB tunnel of the gl_FragColor, and the depth value in the A tunnel of the gl_FragColor.
Now, I have the color and depth texture, I can set a POST_RENDER hud to render synthetic texture and use these two textures as the input, and do some calculation in this camera's shader. I'm not sure whether I have expressed this clear or not, anyway, I'm just gonna paste my code here, and if you have any questions, feel free to discuss. Actually, I got a problem myself here, I want to do some more post render process like antialias even after the silhouette pass, I don't know how to set some later render camera. Anyone who knows please tell me. /*************************************************************************** ***********************************/ osg::ref_ptr<osg::Texture2D> colorTexture = new osg::Texture2D; colorTexture->setTextureSize(windowWidth, windowHeight); colorTexture->setInternalFormat(GL_RGBA); colorTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); colorTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); colorTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER ); colorTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER ); colorTexture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); // set up the render to color texture camera. { osg::ref_ptr<osg::Camera> colorCamera = new osg::Camera; colorCamera->setName("ColorCamera"); colorCamera->setClearColor(clearColor); colorCamera->setViewport(0,0,windowWidth,windowHeight); //colorCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); //colorCamera->setViewport(the_viewport.get()); //colorCamera->setProjectionMatrix(proj_matrix); //colorCamera->setViewMatrix(view_matrix); colorCamera->setRenderOrder(osg::Camera::PRE_RENDER); colorCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT) ; colorCamera->attach(osg::Camera::COLOR_BUFFER, colorTexture.get()); colorCamera->addChild(viewnode); osg::ref_ptr<osg::StateSet> stateset = colorCamera->getOrCreateStateSet(); stateset->addUniform(new osg::Uniform("RENDERNORMALANDDEPTH",false),osg::StateAttribute::ON); root->addChild(colorCamera.get()); } osg::ref_ptr<osg::Texture2D> normalAndDepthTexture = new osg::Texture2D; normalAndDepthTexture->setTextureSize(windowWidth, windowHeight); normalAndDepthTexture->setInternalFormat(GL_RGBA); normalAndDepthTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D:: LINEAR); normalAndDepthTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D:: LINEAR); normalAndDepthTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_ TO_BORDER); normalAndDepthTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_ TO_BORDER); // set up the render to normal and depth texture camera. { osg::ref_ptr<osg::Camera> normalAndDepthCamera = new osg::Camera; normalAndDepthCamera->setName("NormalAndDepthCamera"); normalAndDepthCamera->setClearColor(clearColor); normalAndDepthCamera->setViewport(0,0,windowWidth,windowHeight); //normalAndDepthCamera->setViewport(the_viewport.get()); //normalAndDepthCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); //normalAndDepthCamera->setProjectionMatrix(proj_matrix); //normalAndDepthCamera->setViewMatrix(view_matrix); normalAndDepthCamera->setRenderOrder(osg::Camera::PRE_RENDER); normalAndDepthCamera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFE R_OBJECT); normalAndDepthCamera->attach(osg::Camera::COLOR_BUFFER, normalAndDepthTexture.get()); normalAndDepthCamera->addChild(viewnode); osg::ref_ptr<osg::StateSet> depstateset = normalAndDepthCamera->getOrCreateStateSet(); depstateset->addUniform(new osg::Uniform("RENDERNORMALANDDEPTH",true),osg::StateAttribute::OVERRIDE); root->addChild(normalAndDepthCamera.get()); } // set hud to render synthetic texture { osg::ref_ptr<osg::Geode> geode = new osg::Geode; osg::ref_ptr<osg::Geometry> geom = osg::createTexturedQuadGeometry(osg::Vec3(0,0,0),osg::Vec3(windowWidth,0.0,0 .0),osg::Vec3(0.0,windowHeight,0.0)); geom->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); geode->addDrawable(geom.get()); osg::ref_ptr<osg::Camera> viewCamera = new osg::Camera; viewCamera->setName("ViewCamera"); viewCamera->setClearColor(clearColor); viewCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,windowWidth,0,windowH eight)); viewCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); viewCamera->setViewMatrix(osg::Matrix::identity()); viewCamera->setViewport(0,0,windowWidth,windowHeight); viewCamera->setRenderOrder(osg::Camera::POST_RENDER); viewCamera->addChild(geode.get()); osg::ref_ptr<osg::StateSet> viewstateset = viewCamera->getOrCreateStateSet(); osg::ref_ptr<osg::Program> program = new osg::Program; program->addShader(Shaders::Instance()->getSilhouetteFragmentShader()); viewstateset->setAttributeAndModes(program.get(),osg::StateAttribute::ON); viewstateset->setTextureAttributeAndModes(0,colorTexture.get(),osg::StateAtt ribute::ON); viewstateset->setTextureAttributeAndModes(1,normalAndDepthTexture.get(),osg: :StateAttribute::ON); viewstateset->addUniform(new osg::Uniform("colorTexture",0)); viewstateset->addUniform(new osg::Uniform("normalAndDepthTexture",1)); viewstateset->addUniform(new osg::Uniform("windowWidth",(int)windowWidth)); viewstateset->addUniform(new osg::Uniform("windowHeight",(int)windowHeight)); viewstateset->addUniform(new osg::Uniform("SILHOUETTEONLY",false)); viewstateset->addUniform(new osg::Uniform("DepthThreshold", (float)0.5)); viewstateset->addUniform(new osg::Uniform("NormalThreshold", (float)0.5)); viewstateset->addUniform(new osg::Uniform("DEPTHONLY",false)); viewstateset->addUniform(new osg::Uniform("NORMALONLY",false)); viewstateset->addUniform(new osg::Uniform("DEPTHANDNORMAL",true)); viewstateset->addUniform(new osg::Uniform("silhouettecolor",osg::Vec4f(0.0f,0.0f,0.0f,1.0f))); viewstateset->addUniform(new osg::Uniform("backgroundcolor",clearColor)); root->addChild(viewCamera.get()); } /*************************************************************************** ***********************************/ -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marcus Fritzen Sent: Wednesday, July 18, 2007 3:20 PM To: osg users Subject: Re: [osg-users] multipass rendering Hi Shuxing Xiao, I have a similar problem, perhaps you can help me. I have a prerender camera with a texture attached and make computations on it with a fragment shader. Now I want to use the output of the shader as the input of another shader. I am not really sure how I can do this. Do I need another Camera or what? It would be usefull to me if you could explain me how you did it. Thank, Marcus Shuxing Xiao schrieb: > I used to implement the silhouette calculating by multipass rendering. > > I calculated the rendering image and the normal and depth buffer in some pre > render camera, respectively, and save them in some textures, which are the > inputs of the post render camera.(all of these three cameras are rendered by > GLSL shader.) > > I don't know what exact problem you have encountered, but if you want to > discuss, feel free. > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Andreas Hollmann > Sent: Monday, July 16, 2007 10:21 PM > To: osg-users@openscenegraph.net > Subject: [osg-users] multipass rendering > > I need to implement post process effect. > > I have to change the color of rendered picture depending on the depth > buffer. So I wrote shader for my post process, but as input it needs the > rendered image and depth buffer. > > Is there some another technique to render post process as differing shading? > > I looked at osg prereder and reflection examples, but I do not have real > strategy. :-( > > Help!!! > _____________________________________________________________________ > Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 > > _______________________________________________ > osg-users mailing list > osg-users@openscenegraph.net > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ > > _______________________________________________ > osg-users mailing list > osg-users@openscenegraph.net > http://openscenegraph.net/mailman/listinfo/osg-users > http://www.openscenegraph.org/ > > -- ---------------------------------------------------------------- Marcus Fritzen E-mail: [EMAIL PROTECTED] University Koblenz Triererstr. 105, 56072 Koblenz, HIWI FB4 Herr Jackel ---------------------------------------------------------------- _______________________________________________ osg-users mailing list osg-users@openscenegraph.net http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/ _______________________________________________ osg-users mailing list osg-users@openscenegraph.net http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/