rendertotexturecallback.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************
00022  *                                                                         *
00023  *  DESCRIPTION                                                            *
00024  *                                                                         *
00025  *   $Log: rendertotexturecallback.cpp,v $
00026  *   Revision 1.1.2.2  2006/01/17 09:11:29  martius
00027  *   commented since not compileable with OSG 1.0
00028  *
00029  *   Revision 1.1.2.1  2006/01/12 14:22:37  martius
00030  *   deep shadow implementation
00031  *
00032  *   Revision 1.1.2.1  2005/12/06 17:38:21  martius
00033  *   *** empty log message ***
00034  *
00035  *                                                                 *
00036  ***************************************************************************/
00037 
00038 // #include "rendertotexturecallback.h"
00039 // #include <osg/Node>
00040 // #include <osg/PolygonOffset>
00041 // #include <osg/CullFace>
00042 // #include <osg/Texture2D>
00043 // #include <osg/TexEnv>
00044 // #include <osg/TexGen>
00045 // #include <osg/Depth>
00046 // #include <osg/StateSet>
00047 // #include <osg/ClearNode>
00048 // #include <osg/Transform>
00049 // #include <osg/MatrixTransform>
00050 // #include <osg/Light>
00051 // #include <osg/LightSource>
00052 // #include <osg/ShapeDrawable>
00053 // #include <osgUtil/RenderToTextureStage>
00054 
00055 
00056 // namespace lpzrobots {
00057 
00058 //   using namespace osg;
00059 
00060 //   const int depth_texture_height = 512;
00061 //   const int depth_texture_width  = 512;
00062 //   ref_ptr<RefMatrix> bias = new RefMatrix(0.5f, 0.0f, 0.0f, 0.0f,
00063 //                                        0.0f, 0.5f, 0.0f, 0.0f,
00064 //                                        0.0f, 0.0f, 0.5f, 0.0f,
00065 //                                        0.5f, 0.5f, 0.5f, 1.0f);
00066 
00067 
00068 //   RenderToTextureCallback::RenderToTextureCallback(osg::Node* subgraph, 
00069 //                                                 osg::Texture2D* texture, 
00070 //                                                 osg::LightSource* light_source,
00071 //                                                 osg::TexGen* tex_gen):
00072 //     _subgraph(subgraph),
00073 //     _texture(texture),
00074 //     _local_stateset(new StateSet),
00075 //     _viewport(new Viewport),
00076 //     _light_projection(new RefMatrix),
00077 //     _light_source(light_source),
00078 //     _tex_gen(tex_gen)
00079 //   {
00080 //     _local_stateset->setAttribute(_viewport.get());
00081 //     _local_stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
00082     
00083 //     ref_ptr<PolygonOffset> polygon_offset = new PolygonOffset;
00084 //     polygon_offset->setFactor(1.1f);
00085 //     polygon_offset->setUnits(4.0f);
00086 //     _local_stateset->setAttribute(polygon_offset.get(), StateAttribute::ON | StateAttribute::OVERRIDE);
00087 //     _local_stateset->setMode(GL_POLYGON_OFFSET_FILL, StateAttribute::ON | StateAttribute::OVERRIDE);
00088           
00089 //     ref_ptr<CullFace> cull_face = new CullFace;
00090 //     cull_face->setMode(CullFace::FRONT);
00091 //     _local_stateset->setAttribute(cull_face.get(), StateAttribute::ON | StateAttribute::OVERRIDE);
00092 //     _local_stateset->setMode(GL_CULL_FACE, StateAttribute::ON | StateAttribute::OVERRIDE);
00093           
00094 //     _viewport->setViewport(0, 0, depth_texture_width, depth_texture_height);
00095           
00096 //     float znear = 1.0f * _subgraph->getBound().radius();
00097 //     float zfar  = 3.0f * _subgraph->getBound().radius();
00098 //     float top   = 0.5f * _subgraph->getBound().radius();
00099 //     float right = 0.5f * _subgraph->getBound().radius();
00100 //     znear *= 0.8f;
00101 //     zfar *= 1.2f;
00102 //     _light_projection->makeFrustum(-right, right, -top, top, znear, zfar);
00103 //   }
00104 
00105 
00106 //   void RenderToTextureCallback::_request_render_to_depth_texture(osg::Node&, osgUtil::CullVisitor& cv)
00107 //   {   
00108 //     // create the render to texture stage.
00109 //     osg::ref_ptr<osgUtil::RenderToTextureStage> rtts = new osgUtil::RenderToTextureStage;
00110 
00111 //     // set up lighting.
00112 //     // currently ignore lights in the scene graph itself..
00113 //     // will do later.
00114 //     osgUtil::RenderStage* previous_stage = cv.getCurrentRenderBin()->getStage();
00115 
00116 //     // set up the background color and clear mask.
00117 //     rtts->setClearMask(GL_DEPTH_BUFFER_BIT);
00118 //     rtts->setColorMask(new ColorMask(false, false, false, false));
00119 
00120 //     // set up to charge the same RenderStageLighting is the parent previous stage.
00121 //     rtts->setRenderStageLighting(previous_stage->getRenderStageLighting());
00122 
00123 
00124 //     // record the render bin, to be restored after creation
00125 //     // of the render to text
00126 //     osgUtil::RenderBin* previousRenderBin = cv.getCurrentRenderBin();
00127 
00128 //     osgUtil::CullVisitor::ComputeNearFarMode saved_compute_near_far_mode = cv.getComputeNearFarMode();
00129 //     cv.setComputeNearFarMode(osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR);
00130 
00131 //     // set the current renderbin to be the newly created stage.
00132 //     cv.setCurrentRenderBin(rtts.get());
00133 
00134 //     ref_ptr<RefMatrix> light_view = new RefMatrix;
00135 //     Vec4 lpos = _light_source->getLight()->getPosition();    
00136 //     light_view->makeLookAt(Vec3(lpos.x(), lpos.y(), lpos.z()), Vec3(0, 0, 0), Z_AXIS);
00137 //     Matrix texture_matrix = (*light_view.get()) * (*_light_projection.get()) * (*bias.get());
00138 //     _tex_gen->setPlane(TexGen::S, Vec4(texture_matrix(0, 0), 
00139 //                                     texture_matrix(1, 0), 
00140 //                                     texture_matrix(2, 0), 
00141 //                                     texture_matrix(3, 0))); 
00142 //     _tex_gen->setPlane(TexGen::T, Vec4(texture_matrix(0, 1), 
00143 //                                     texture_matrix(1, 1), 
00144 //                                     texture_matrix(2, 1), 
00145 //                                     texture_matrix(3, 1))); 
00146 //     _tex_gen->setPlane(TexGen::R, Vec4(texture_matrix(0, 2), 
00147 //                                     texture_matrix(1, 2), 
00148 //                                     texture_matrix(2, 2), 
00149 //                                     texture_matrix(3, 2))); 
00150 //     _tex_gen->setPlane(TexGen::Q, Vec4(texture_matrix(0, 3), 
00151 //                                     texture_matrix(1, 3), 
00152 //                                     texture_matrix(2, 3), 
00153 //                                     texture_matrix(3, 3))); 
00154 
00155 //     cv.pushProjectionMatrix(_light_projection.get());
00156 //     cv.pushModelViewMatrix(light_view.get());
00157 //     cv.pushStateSet(_local_stateset.get());
00158 
00159 //     // traverse the subgraph
00160 //     _subgraph->accept(cv);
00161 
00162 //     cv.popStateSet();
00163 //     cv.popModelViewMatrix();
00164 //     cv.popProjectionMatrix();
00165 
00166 //     cv.setComputeNearFarMode(saved_compute_near_far_mode);
00167 
00168 //     // restore the previous renderbin.
00169 //     cv.setCurrentRenderBin(previousRenderBin);
00170 
00171 //     if (rtts->getRenderGraphList().size()==0 && rtts->getRenderBinList().size()==0)
00172 //       {
00173 //      // getting to this point means that all the subgraph has been
00174 //      // culled by small feature culling or is beyond LOD ranges.
00175 //      return;
00176 //       }
00177 
00178 //     rtts->setViewport(_viewport.get());
00179     
00180 //     // and the render to texture stage to the current stages
00181 //     // dependancy list.
00182 //     cv.getCurrentRenderBin()->getStage()->addToDependencyList(rtts.get());
00183 
00184 //     // if one exist attach texture to the RenderToTextureStage.
00185 //     rtts->setTexture(_texture.get());
00186 //   }
00187 
00188 // }

Generated on Tue Apr 4 19:05:04 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5