Re: [osg-users] [Depth Buffer rendering]
Hi Wojtek, it works ! thanks a lot for your precious answear. For those who will be interrested, i'll post later the complete source code with corrections. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [Depth Buffer rendering]
In fact i've got a new problem (perhaps it's normal), the transformations applied with texgen are not take into account when i use my shader. Do you have any idea of how to proceed ? I attach a screen capture of my problem. Thanks On Fri, Jun 13, 2008 at 4:53 PM, Mathieu Schoutteten [EMAIL PROTECTED] wrote: Hi Wojtek, it works ! thanks a lot for your precious answear. For those who will be interrested, i'll post later the complete source code with corrections. attachment: capture.JPG___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [Depth Buffer rendering]
Hi Mathieu, Good ;-). Regarding your question, I am no sure what can be an issue now. Maybe if I saw your shader it could be simpler ;-) I will try to guess then. If you use vertex shader then you need to replicate texgen computations. Once again I recommend Emulating OpenGL functionality from OpenGL Shading Language book. This is an excerpt replicating texgen in vertex shader: vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex; gl_TexCoord[i].s = dot(ecPosition, gl_EyePlaneS[i]); gl_TexCoord[i].t = dot(ecPosition, gl_EyePlaneT[i]); gl_TexCoord[i].p = dot(ecPosition, gl_EyePlaneR[i]); gl_TexCoord[i].q = dot(ecPosition, gl_EyePlaneQ[i]); But if you only use fragment shader then maybe the reason is that you use uniform texture2D function but need to use projective texturing ie texture2DProj: vec4 tex = texture2DProj( depthTexture, gl_TexCoord[i] ); I am leaving for one week. I hope it helps. If not maybe others on this forum will offer some assistance. Cheers, Wojtek - Original Message - From: Mathieu Schoutteten To: OpenSceneGraph Users Sent: Friday, June 13, 2008 5:42 PM Subject: Re: [osg-users] [Depth Buffer rendering] In fact i've got a new problem (perhaps it's normal), the transformations applied with texgen are not take into account when i use my shader. Do you have any idea of how to proceed ? I attach a screen capture of my problem. Thanks On Fri, Jun 13, 2008 at 4:53 PM, Mathieu Schoutteten [EMAIL PROTECTED] wrote: Hi Wojtek, it works ! thanks a lot for your precious answear. For those who will be interrested, i'll post later the complete source code with corrections. -- ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] [Depth Buffer rendering]
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 ); /// attachment: depthbuffer.JPG___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] [Depth Buffer rendering]
i post my source code for more clarity.. Maybe someone already try to have the same effect. DepthBuffer.cpp include a main method for test. #include DepthBuffer.h #include osgFX/Registry #include osgViewer/Viewer #include osgDB/ReadFile namespace { osgFX::Registry::Proxy proxy(new osgFX::DepthBuffer); class DefaultTechnique: public osgFX::Technique { public: DefaultTechnique(osg::Texture2D* tex_depth) : osgFX::Technique(), _tex_depth(tex_depth) {} META_Technique(GLSL Depth Buffer, GLSL Depth Buffer); void getRequiredExtensions(std::vectorstd::string extensions) const { //extensions.push_back( GL_ARB_shader_objects ); //extensions.push_back( GL_ARB_vertex_shader ); //extensions.push_back( GL_ARB_fragment_shader ); } protected: void define_passes() { const unsigned int tex_depth_unit = 0; osg::ref_ptrosg::StateSet ss = new osg::StateSet; ss-setTextureAttributeAndModes(tex_depth_unit, _tex_depth.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); /* ss-setTextureMode(tex_depth_unit, GL_TEXTURE_GEN_S, osg::StateAttribute::ON); ss-setTextureMode(tex_depth_unit, GL_TEXTURE_GEN_T, osg::StateAttribute::ON); ss-setTextureMode(tex_depth_unit, GL_TEXTURE_GEN_R, osg::StateAttribute::ON); ss-setTextureMode(tex_depth_unit, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON); */ addPass(ss.get()); } private: osg::ref_ptrosg::Texture2D _tex_depth; }; } /// osgFX::DepthBuffer::DepthBuffer() : Effect() { } osgFX::DepthBuffer::DepthBuffer(const DepthBuffer copy, const osg::CopyOp copyop) : Effect(copy, copyop), _tex_depth(static_castosg::Texture2D* (copyop(copy._tex_depth.get( { } void osgFX::DepthBuffer::setUpEffect(osg::Group* root, osg::Node* object) { const unsigned int tex_depth_width = 1024; const unsigned int tex_depth_height = 1024; _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_R, osg::Texture2D::CLAMP_TO_BORDER); //_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-setName(DepthBufferCamera); camera-setClearColor( osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); camera-setClearMask( GL_DEPTH_BUFFER_BIT ); camera-setReferenceFrame(osg::Camera::RELATIVE_RF); camera-setComputeNearFarMode( osg::Camera::DO_NOT_COMPUTE_NEAR_FAR ); camera-setViewport(0, 0, tex_depth_width, tex_depth_height); camera-setProjectionMatrix( osg::Matrix::identity() ); 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.get()); camera-addChild( object ); root-addChild( camera ); dirtyTechniques(); } bool osgFX::DepthBuffer::define_techniques() { addTechnique( new DefaultTechnique(_tex_depth.get()) ); return true; } int main(int argc, char *argv[]) { osgViewer::Viewer viewer; osg::ref_ptrosg::Group rootNode = new osg::Group; osg::ref_ptrosg::Node objectNode = osgDB::readNodeFile(cow.osg); osg::ref_ptrosgFX::DepthBuffer effect = new osgFX::DepthBuffer; effect-setUpEffect(rootNode.get(), objectNode.get()); effect-addChild( objectNode.get() ); rootNode-addChild( effect.get() ); viewer.setSceneData( rootNode.get() ); return viewer.run(); }#ifndef _DEPTHBUFFER_HPP_ #define _DEPTHBUFFER_HPP_ #include osgFX/Export #include osgFX/Effect #include osg/Texture2D namespace osgFX { class DepthBuffer : public osgFX::Effect { public: DepthBuffer(); DepthBuffer(const DepthBuffer copy, const osg::CopyOp copyop = osg::CopyOp::SHALLOW_COPY); // effect class informations
Re: [osg-users] [Depth Buffer rendering]
Hi Mathieu, Sorry I don't have the time to compile and test your code, but I saw the screenshot and it looks like your depth texture gets rendered and applied to the object. What you may need to do is to make sure you set up RTT camera transform exactly as main camera transforms, and texture coordinates are properly generated to span the whole window. In other words I guess that you want to have texcoords match pixel locations in the final output screen. Ie you want texcorrds on the objects to span -1..1x-1..1 range on the output window. Right ? If yes, then you could use simple shader, or add a texgen node to produce proper texcoords for the output scene. This texgen should use EYE_LINEAR coords and its transform should be set to projection matrix of RTT camera and main camera. I am also not sure if seeting your effect camera to RELATIVE_RF gurantees using the same projection for RTT camera as for main camera. One could be sure if he forces this explicitly eg: camera-setProjectionMatrix( viewer-getCamera()-getProjectionMatrix() ); To add texgen node try adding following lines to your code: camera-setProjectionMatrix( viewer-getCamera()-getProjectionMatrix() ); osg::TexGenNode * texGenNode = new osg::TexGenNode; _scene-addChild( texGenNode ); texGenNode-setTextureUnit( 0 ); texGenNode-getTexGen()-setMode( osg::TexGen::EYE_LINEAR ); texGenNode-getTexGen()-setPlanesFromMatrix ( camera-getProjectionMatrix() * osg::Matrix::translate(1,1,1) * // remap -1..1x-1..1 range osg::Matrix::scale(0.5,0.5,0.5) // to 0..1 x 0..1 range ); One final note, it looks like you use cow.osg model. AFAIK this model already contains texgen using SPHERE mapping mode. To avoid conflicts for tests I suggest you use other model. Hope it helps, and no guarrantees, I have no time to verify if everything what I wrote is 100% correct. Cheers, Wojtek - Original Message - From: Mathieu Schoutteten To: osg-users@lists.openscenegraph.org Sent: Thursday, June 12, 2008 4:35 PM Subject: Re: [osg-users] [Depth Buffer rendering] i post my source code for more clarity.. Maybe someone already try to have the same effect. DepthBuffer.cpp include a main method for test. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org