OpenSceneGraph/include/osgShadow/MinimalShadowMap

165 lines
6.5 KiB
Plaintext
Raw Normal View History

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2008-10-06 16:53:54 +08:00
*
* 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
2008-10-06 16:53:54 +08:00
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
2008-10-06 16:53:54 +08:00
* 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
2008-10-06 16:53:54 +08:00
* OpenSceneGraph Public License for more details.
*
* ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
* Thanks to to my company http://www.ai.com.pl for allowing me free this work.
*/
#ifndef OSGSHADOW_MINIMALSHADOWMAP
#define OSGSHADOW_MINIMALSHADOWMAP 1
#include <osgShadow/StandardShadowMap>
namespace osgShadow {
class OSGSHADOW_EXPORT MinimalShadowMap : public StandardShadowMap
2008-10-06 16:53:54 +08:00
{
public :
/** Convenient typedef used in definition of ViewData struct and methods */
typedef MinimalShadowMap ThisClass;
/** Convenient typedef used in definition of ViewData struct and methods */
typedef StandardShadowMap BaseClass;
/** Classic OSG constructor */
MinimalShadowMap();
/** Classic OSG cloning constructor */
MinimalShadowMap(
const MinimalShadowMap& msm,
2008-10-06 16:53:54 +08:00
const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
/** Declaration of standard OSG object methods */
META_Object( osgShadow, MinimalShadowMap );
2008-10-06 16:53:54 +08:00
void setModellingSpaceToWorldTransform( const osg::Matrix & modellingSpaceToWorld )
{ _modellingSpaceToWorld = modellingSpaceToWorld; }
const osg::Matrix & getModellingSpaceToWorldTransform( void ) const
2008-10-06 16:53:54 +08:00
{ return _modellingSpaceToWorld; }
float getMaxFarPlane( ) const
2008-10-06 16:53:54 +08:00
{ return _maxFarPlane; }
void setMaxFarPlane( float maxFarPlane )
{ _maxFarPlane = maxFarPlane; }
float getMinLightMargin( ) const
2008-10-06 16:53:54 +08:00
{ return _minLightMargin; }
void setMinLightMargin( float minLightMargin )
{ _minLightMargin = minLightMargin; }
enum ShadowReceivingCoarseBoundAccuracy {
EMPTY_BOX,
BOUNDING_SPHERE,
BOUNDING_BOX,
2008-10-07 20:31:42 +08:00
DEFAULT_ACCURACY = BOUNDING_BOX
2008-10-06 16:53:54 +08:00
};
void setShadowReceivingCoarseBoundAccuracy
( ShadowReceivingCoarseBoundAccuracy accuracy )
{ _shadowReceivingCoarseBoundAccuracy = accuracy; }
ShadowReceivingCoarseBoundAccuracy
getShadowReceivingCoarseBoundAccuracy() const
2008-10-06 16:53:54 +08:00
{ return _shadowReceivingCoarseBoundAccuracy; }
protected:
/** Classic protected OSG destructor */
virtual ~MinimalShadowMap(void);
protected:
2008-10-06 16:53:54 +08:00
// Matrix modellingSpaceToWorld and its inverse
// are used to define Modelling Space where shadowed scene drawables
// have minimal (smallest possible extent) bounding boxes.
// Computing visible shadow range in this space
2008-10-06 16:53:54 +08:00
// allows for optimal use of ShadowMap resolution.
// By default it is set to identity ie computations are in world space.
// But it should be set to ElipsoidModel::localToWorld
2008-10-06 16:53:54 +08:00
// when scene objects are put on earth ellipsoid surface.
// Other scenarios are also possible for example when models are
2008-10-06 16:53:54 +08:00
// built in XZY space which would require identity matrix with swapped colums
osg::Matrix _modellingSpaceToWorld;
float _maxFarPlane;
float _minLightMargin;
ShadowReceivingCoarseBoundAccuracy _shadowReceivingCoarseBoundAccuracy;
2008-10-06 16:53:54 +08:00
struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
2008-10-06 16:53:54 +08:00
{
osg::Matrix *_modellingSpaceToWorldPtr;
float *_maxFarPlanePtr;
float *_minLightMarginPtr;
int _frameShadowCastingCameraPasses;
2008-10-06 16:53:54 +08:00
ConvexPolyhedron _sceneReceivingShadowPolytope;
2008-10-06 16:53:54 +08:00
std::vector< osg::Vec3d > _sceneReceivingShadowPolytopePoints;
osg::Matrixd _clampedProjection;
2008-10-06 16:53:54 +08:00
virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
virtual osg::BoundingBox computeShadowReceivingCoarseBounds( );
virtual void cullShadowReceivingScene( );
virtual void aimShadowCastingCamera(
const osg::BoundingSphere &bounds,
const osg::Light *light,
const osg::Vec4 &worldLightPos,
const osg::Vec3 &worldLightDir,
const osg::Vec3 &worldLightUp = osg::Vec3(0,1,0) );
2008-10-06 16:53:54 +08:00
virtual void aimShadowCastingCamera( const osg::Light *light,
const osg::Vec4 &worldLightPos,
const osg::Vec3 &worldLightDir,
const osg::Vec3 &worldLightUp
= osg::Vec3(0,1,0) );
virtual void frameShadowCastingCamera
( const osg::Camera* cameraMain, osg::Camera* cameraShadow, int pass = 1 );
void cutScenePolytope( const osg::Matrix & matrix,
2008-10-06 16:53:54 +08:00
const osg::Matrix & inverse,
const osg::BoundingBox &bb =
2008-10-06 16:53:54 +08:00
osg::BoundingBox(-1,-1,-1,1,1,1) );
osg::BoundingBox computeScenePolytopeBounds();
osg::BoundingBox computeScenePolytopeBounds(const osg::Matrix& m);
2008-10-06 16:53:54 +08:00
// Utility methods for adjusting projection matrices
// Modify projection matrix so that some output subrange
// is remapped to whole clip space (-1..1,-1..1,-1..1).
// Bit mask can be used to limit remaping to selected bounds only.
static void trimProjection
( osg::Matrixd & projection, osg::BoundingBox subrange,
2008-10-06 16:53:54 +08:00
unsigned int trimMask = (1|2|4|8|16|32)
/*1=left|2=right|4=bottom|8=top|16=near|32=far*/);
static void clampProjection
( osg::Matrixd & projection, float n = 0, float f = FLT_MAX );
2008-10-06 16:53:54 +08:00
static void extendProjection
( osg::Matrixd & projection, osg::Viewport * viewport, const osg::Vec2& margin );
2008-10-06 16:53:54 +08:00
};
META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData )
};
} // namespace osgShadow
#endif