[osg-users] ClipNode / clipplane, rendering water with RTT camera

Michael Ebner Michael.Ebner at gmx.at
Thu Sep 27 03:56:04 PDT 2007


Hello,

could anyone give me a hint on my problem described below? I cannot 
figure out how to setup a clipplane for the reflection camera correctly.

thanks,
Michael.


Michael Ebner wrote:
> Hello OSG users,
> 
> i'm trying to render a water surface with reflections. Rendering the 
> reflected scene into a texture and projecting it on a water plane 
> already works.
> What i need is a clipplane at water height to avoid rendering anything 
> below the water surface. I've tried to setup a ClipNode with clipplanes 
> in various ways (also activating them on different positions at the 
> scenegraph) but nothing gets clipped.
> 
> I post a code snippet below, perhaps i'm missing something obvious. I 
> tried, setting up the ClipNode at root level and activating the plane at 
> reflection cameras level. Tried adding the ClipNode above the reflection 
> camera and activating it there. And below is the code, where the 
> ClipNode is child of the RTT reflection_camera, but it doesn't work either.
> 
> 
> snippet:
> 
> //---------------- reflection texture ------------
> reflection_tex_ = new osg::Texture2D;
> reflection_tex_->setTextureSize(1024,1024);
> reflection_tex_->setInternalFormat(GL_RGBA);
> reflection_tex_->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);
> reflection_tex_->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
> reflection_tex_->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);
> reflection_tex_->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);
> reflection_tex_->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
> 
> 
> //------------ reflection camera ----------------------
> reflection_camera_ = new osg::Camera;
> reflection_camera_->setName("WaterReflectionCamera");
> 
> reflection_camera_->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));
> reflection_camera_->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
> reflection_camera_->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
> reflection_camera_->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
> reflection_camera_->setViewport(0, 0,
>                                   reflection_tex_->getTextureWidth(),
>                                   reflection_tex_->getTextureHeight());
> 
> reflection_camera_->setRenderOrder(osg::Camera::PRE_RENDER);
> reflection_camera_->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
> reflection_camera_->attach(osg::Camera::COLOR_BUFFER, 
> reflection_tex_.get());
> 
> 
> // add clip node with clip plane, to avoid rendering anything below 
> water surface
> osg::ClipNode * clip_node = new osg::ClipNode();
> clip_node->setName("Clip Node XZ plane");
> clip_node->addClipPlane(new osg::ClipPlane(0,0.0,1.0,0.0,water_height));
> 
> osg::StateSet* clip_state = clip_node->getOrCreateStateSet();
> clip_state->setMode(GL_CLIP_PLANE0, osg::StateAttribute::PROTECTED | 
> osg::StateAttribute::ON);
> 
> clip_node->addChild(reflected_nodes.get());
> 
> reflection_camera_->addChild(clip_node);
> 
> root_node->addChild(reflection_camera_.get());
> 
> 
> //-----------------------
> 
> Thanks in advance for any help,
> Michael.
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> 




More information about the osg-users mailing list