[osg-users] [Depth Buffer rendering]
Mathieu Schoutteten
matcheu at gmail.com
Thu Jun 12 03:09:36 PDT 2008
Hello,
I would like to create an effect (using osgFX) which render the depth
buffer. I'm using a RTT and then apply the texture to the object but i'm
having some problem for mapping correctly the texture on the object (see
capture in attachment). My RTT camera must be similar to my viewer camera,
so i've tried to play with the matrix but without success. In fact for my
program, the texture should be use as an input of a shader.
can someone help me ? am i doing the right things ?
Thanks,
Mathieu
Here is a fragment of the code i'm using:
/////////////////////////////////////////////////////////////////////////
const unsigned int tex_depth_width = 1024;
const unsigned int tex_depth_height = 1024;
osg::Texture2D* _tex_depth = new osg::Texture2D;
_tex_depth->setTextureSize(tex_depth_width, tex_depth_height);
_tex_depth->setInternalFormat(GL_DEPTH_COMPONENT);
_tex_depth->setWrap(osg::Texture2D::WRAP_S,
osg::Texture2D::CLAMP_TO_BORDER);
_tex_depth->setWrap(osg::Texture2D::WRAP_T,
osg::Texture2D::CLAMP_TO_BORDER);
_tex_depth->setFilter(osg::Texture2D::MIN_FILTER,
osg::Texture2D::LINEAR);
_tex_depth->setFilter(osg::Texture2D::MAG_FILTER,
osg::Texture2D::LINEAR);
osg::Camera* camera = new osg::Camera;
camera->setClearMask( GL_DEPTH_BUFFER_BIT );
camera->setClearColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) );
//camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
camera->setComputeNearFarMode( osg::Camera::DO_NOT_COMPUTE_NEAR_FAR );
camera->setViewport(0, 0, tex_depth_width, tex_depth_height);
camera->setViewMatrix( osg::Matrix::identity() );
camera->setRenderOrder(osg::Camera::PRE_RENDER);
camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
camera->attach(osg::Camera::DEPTH_BUFFER, _tex_depth);
camera->addChild( _scene );
root->addChild( camera );
root->addChild( _scene );
const unsigned int tex_depth_unit = 0;
osg::StateSet* ss = new osg::StateSet;
ss->setTextureAttributeAndModes(tex_depth_unit, _tex_depth,
osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
_scene->setStateSet( ss );
///////////////////////////////////////////////////////////////////
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080612/008d3fb3/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: depthbuffer.JPG
Type: image/jpeg
Size: 32195 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080612/008d3fb3/attachment.jpeg>
More information about the osg-users
mailing list