[osg-users] How to render (sub-)graph only into depth buffer?

Hartwig Wiesmann hartwig.wiesmann at skywind.eu
Fri Dec 16 15:20:47 PST 2016


Hi,

I would like to fill the depth buffer with the data of a rendered subgraph. The subgraph itself should not be visible in the view. Afterwards, I want to render another - and now visible - subgraph that uses (and modifies) the previously filled depth buffer.

How can I do this?

I wrote a small program for testing but unfortunately this does not fill the depth buffer (the box is completely visible):


Code:

	osg::Geode*   geode(new osg::Geode());
		osg::Program* prog(new osg::Program());
		osg::Shader*  vshader(new osg::Shader(osg::Shader::VERTEX,  gVertexShader));
		osg::Shader*  fshader(new osg::Shader(osg::Shader::FRAGMENT,gFragmentShader));
		osg::ShapeDrawable* box(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0),100.0)));
		osg::ShapeDrawable* sphere(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(50.0,50.0,50.0),100.0)));

		prog->addShader(vshader);
		prog->addShader(fshader);
		box->getOrCreateStateSet()->setAttribute(new osg::ColorMask(true,true,true,true));
		sphere->getOrCreateStateSet()->setAttribute(new osg::ColorMask(true,false,false,true));
		sphere->getOrCreateStateSet()->setAttribute(new osg::Depth());
		geode->addDrawable(box);
		geode->addDrawable(sphere);
		geode->getOrCreateStateSet()->setAttribute(prog);
		_root->addChild(geode);




Thank you!

PS: The vertex shader just calculates the position by multiplying the view-projection matrix with the vertex vector and the fragment shader just returns a color value.

Cheers,
Hartwig

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








More information about the osg-users mailing list