/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ /* ParallelSplitShadowMap written by Adrian Egli */ #ifndef OSGSHADOW_ParallelSplitShadowMap #define OSGSHADOW_ParallelSplitShadowMap 1 #include #include #include namespace osgShadow { class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique { public: ParallelSplitShadowMap(osg::Geode** debugGroup=NULL, int icountplanes=3); ParallelSplitShadowMap(const ParallelSplitShadowMap& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); META_Object(osgShadow, ParallelSplitShadowMap); /** initialize the ShadowedScene and local cached data structures.*/ virtual void init(); /** run the update traversal of the ShadowedScene and update any loca chached data structures.*/ virtual void update(osg::NodeVisitor& nv); /** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/ virtual void cull(osgUtil::CullVisitor& cv); /** Clean scene graph from any shadow technique specific nodes, state and drawables.*/ virtual void cleanSceneGraph(); protected : virtual ~ParallelSplitShadowMap() {} struct PSSMShadowSplitTexture { // RTT osg::ref_ptr _camera; osg::ref_ptr _texgen; osg::ref_ptr _texture; osg::ref_ptr _stateset; unsigned int _textureUnit; osg::Vec2d _ambientBias; osg::ref_ptr _debug_camera; osg::ref_ptr _debug_texture; osg::ref_ptr _debug_stateset; unsigned int _debug_textureUnit; // Light (SUN) osg::Vec3d _lightCameraSource; osg::Vec3d _lightCameraTarget; osg::Vec3d _frustumSplitCenter; osg::Vec3d _lightDirection; double _lightNear; double _lightFar; osg::Matrix _cameraView; osg::Matrix _cameraProj; unsigned int _splitID; unsigned int _resolution; osg::Uniform* _farDistanceSplit; }; typedef std::map PSSMShadowSplitTextureMap; PSSMShadowSplitTextureMap _PSSMShadowSplitTextureMap; private: void calculateFrustumCorners(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightInitalPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightNearFarFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); void calculateLightViewProjectionFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners); osg::Geode** _displayTexturesGroupingNode; unsigned int _textureUnitOffset; }; } #endif