Changeset 13041 for OpenSceneGraph/trunk/src/osgShadow/ShadowTexture.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgShadow/ShadowTexture.cpp
r11137 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 42 42 unsigned int tex_width = 512; 43 43 unsigned int tex_height = 512; 44 44 45 45 _texture = new osg::Texture2D; 46 46 _texture->setTextureSize(tex_width, tex_height); … … 58 58 59 59 _camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); 60 60 61 61 _camera->setCullCallback(new CameraCullCallback(this)); 62 62 … … 82 82 osg::StateSet* stateset = _camera->getOrCreateStateSet(); 83 83 stateset->setAttribute(_material.get(),osg::StateAttribute::OVERRIDE); 84 85 } 86 87 { 88 _stateset = new osg::StateSet; 84 85 } 86 87 { 88 _stateset = new osg::StateSet; 89 89 _stateset->setTextureAttributeAndModes(_textureUnit,_texture.get(),osg::StateAttribute::ON); 90 90 _stateset->setTextureMode(_textureUnit,GL_TEXTURE_GEN_S,osg::StateAttribute::ON); … … 92 92 _stateset->setTextureMode(_textureUnit,GL_TEXTURE_GEN_R,osg::StateAttribute::ON); 93 93 _stateset->setTextureMode(_textureUnit,GL_TEXTURE_GEN_Q,osg::StateAttribute::ON); 94 94 95 95 _texgen = new osg::TexGen; 96 96 } 97 97 98 98 _dirty = false; 99 99 } … … 114 114 // do traversal of shadow casting scene which does not need to be decorated by the shadow texture 115 115 { 116 cv.setTraversalMask( traversalMask & 116 cv.setTraversalMask( traversalMask & 117 117 getShadowedScene()->getCastsShadowTraversalMask() ); 118 118 … … 123 123 { 124 124 cv.pushStateSet(_stateset.get()); 125 126 cv.setTraversalMask( traversalMask & 125 126 cv.setTraversalMask( traversalMask & 127 127 getShadowedScene()->getReceivesShadowTraversalMask() ); 128 128 129 129 _shadowedScene->osg::Group::traverse(cv); 130 130 131 131 cv.popStateSet(); 132 132 133 133 } 134 134 135 135 // need to compute view frustum for RTT camera. 136 136 // 1) get the light position … … 155 155 } 156 156 } 157 157 158 158 osg::Matrix eyeToWorld; 159 159 eyeToWorld.invert(*cv.getModelViewMatrix()); 160 160 161 161 lightpos = lightpos * eyeToWorld; 162 162 … … 164 164 { 165 165 166 // get the bounds of the model. 166 // get the bounds of the model. 167 167 osg::ComputeBoundsVisitor cbbv(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN); 168 168 cbbv.setTraversalMask(getShadowedScene()->getCastsShadowTraversalMask()); 169 169 170 170 _shadowedScene->osg::Group::traverse(cbbv); 171 171 172 172 osg::BoundingBox bb = cbbv.getBoundingBox(); 173 173 174 174 if (lightpos[3]!=0.0) 175 175 { … … 189 189 _camera->setProjectionMatrixAsFrustum(-right,right,-top,top,znear,zfar); 190 190 _camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(bb.center()-position)); 191 191 192 192 193 193 // compute the matrix which takes a vertex from local coords into tex coords 194 194 // will use this later to specify osg::TexGen.. 195 osg::Matrix MVPT = _camera->getViewMatrix() * 195 osg::Matrix MVPT = _camera->getViewMatrix() * 196 196 _camera->getProjectionMatrix() * 197 197 osg::Matrix::translate(1.0,1.0,1.0) * 198 198 osg::Matrix::scale(0.5f,0.5f,0.5f); 199 199 200 200 _texgen->setMode(osg::TexGen::EYE_LINEAR); 201 201 _texgen->setPlanesFromMatrix(MVPT); … … 223 223 _camera->setProjectionMatrixAsOrtho(-right, right, -top, top, znear, zfar); 224 224 _camera->setViewMatrixAsLookAt(position,bb.center(),computeOrthogonalVector(lightDir)); 225 225 226 226 227 227 // compute the matrix which takes a vertex from local coords into tex coords 228 228 // will use this later to specify osg::TexGen.. 229 osg::Matrix MVPT = _camera->getViewMatrix() * 229 osg::Matrix MVPT = _camera->getViewMatrix() * 230 230 _camera->getProjectionMatrix() * 231 231 osg::Matrix::translate(1.0,1.0,1.0) * 232 232 osg::Matrix::scale(0.5f,0.5f,0.5f); 233 233 234 234 _texgen->setMode(osg::TexGen::EYE_LINEAR); 235 235 _texgen->setPlanesFromMatrix(MVPT); … … 237 237 238 238 239 cv.setTraversalMask( traversalMask & 239 cv.setTraversalMask( traversalMask & 240 240 getShadowedScene()->getCastsShadowTraversalMask() ); 241 241 … … 245 245 orig_rs->getPositionalStateContainer()->addPositionedTextureAttribute(_textureUnit, cv.getModelViewMatrix(), _texgen.get()); 246 246 } 247 248 249 247 248 249 250 250 251 251
