StandardShadowMap
Go to the documentation of this file.
/* -*-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.
*
* 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_STANDARDSHADOWMAP
#define OSGSHADOW_STANDARDSHADOWMAP 1
#include <osgShadow/DebugShadowMap>
namespace osgShadow {
class OSGSHADOW_EXPORT StandardShadowMap : public DebugShadowMap
{
public :
typedef StandardShadowMap ThisClass;
typedef DebugShadowMap BaseClass;
StandardShadowMap();
StandardShadowMap(const StandardShadowMap& ssm,
const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Object( osgShadow, StandardShadowMap );
void setBaseTextureUnit( unsigned int unit )
{ _baseTextureUnit = unit; dirty(); }
unsigned int getBaseTextureUnit( void ) const
{ return _baseTextureUnit; }
void setShadowTextureUnit( unsigned int unit )
{ _shadowTextureUnit = unit; dirty(); }
unsigned int getShadowTextureUnit( void ) const
{ return _shadowTextureUnit; }
// Texture Indices are changed by search and replace on shader source
// Carefully order these calls when changing both base and shadow indices
// In worst case when intend to swap indices
// one will have to call these methods more than once
// with one extra pass to change index to unused value to avoid
// unwanted superfluous replace:
//
// Example: Imagine we want to swap base(0) and shadow(1) indices:
// We have to do an extra step to make sure both do not end up as 1
//
// // initially change base to something else than 1
// setBaseTextureCoordIndex( 100 );
// // now search and replace all gl_TexCord[1] to gl_TexCord[0]
// setShadowTextureCoordIndex( 0 );
// // finally change base from 100 to 0
// setBaseTextureCoordIndex( 1 );
void setBaseTextureCoordIndex( unsigned int index )
{ updateTextureCoordIndices( _baseTextureCoordIndex, index );
_baseTextureCoordIndex = index; }
unsigned int getBaseTextureCoordIndex( void ) const
{ return _baseTextureCoordIndex; }
// Texture Indices are changed by search and replace on shader source
// Look at the comment above setBaseTextureCoordIndex
void setShadowTextureCoordIndex( unsigned int index )
{ updateTextureCoordIndices( _shadowTextureCoordIndex, index );
_shadowTextureCoordIndex = index; }
unsigned int getShadowTextureCoordIndex( void ) const
{ return _shadowTextureCoordIndex; }
void setTextureSize( const osg::Vec2s& textureSize )
{ _textureSize = textureSize; dirty(); }
const osg::Vec2s& getTextureSize() const
{ return _textureSize; }
void setLight( osg::Light* light )
{ _light = light; }
osg::Light* getLight( void )
{ return _light.get(); }
const osg::Light* getLight( void ) const
{ return _light.get(); }
osg::Shader * getShadowVertexShader()
{ return _shadowVertexShader.get(); }
osg::Shader * getShadowFragmentShader()
{ return _shadowFragmentShader.get(); }
osg::Shader * getMainVertexShader( )
{ return _mainVertexShader.get(); }
osg::Shader * getMainFragmentShader( )
{ return _mainFragmentShader.get(); }
void setShadowVertexShader( osg::Shader * shader )
{ _shadowVertexShader = shader; }
void setShadowFragmentShader( osg::Shader * shader )
{ _shadowFragmentShader = shader; }
void setMainVertexShader( osg::Shader * shader )
{ _mainVertexShader = shader; }
void setMainFragmentShader( osg::Shader * shader )
{ _mainFragmentShader = shader; }
virtual void resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~StandardShadowMap(void);
virtual void updateTextureCoordIndices
( unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex );
virtual void searchAndReplaceShaderSource
( osg::Shader*, std::string fromString, std::string toString );
osg::ref_ptr< osg::Shader > _mainVertexShader;
osg::ref_ptr< osg::Shader > _mainFragmentShader;
osg::ref_ptr< osg::Shader > _shadowVertexShader;
osg::ref_ptr< osg::Shader > _shadowFragmentShader;
osg::ref_ptr< osg::Light > _light;
float _polygonOffsetFactor;
float _polygonOffsetUnits;
osg::Vec2s _textureSize;
unsigned int _baseTextureUnit;
unsigned int _shadowTextureUnit;
unsigned int _baseTextureCoordIndex;
unsigned int _shadowTextureCoordIndex;
struct OSGSHADOW_EXPORT ViewData: public BaseClass::ViewData
{
osg::ref_ptr< osg::Light > * _lightPtr;
unsigned int * _baseTextureUnitPtr;
unsigned int * _shadowTextureUnitPtr;
// ShadowMap texture is defined by base DebugShadowMap
// osg::ref_ptr<osg::Texture2D> _texture;
// ShadowMap camera is defined by base DebugShadowMap
// osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::TexGen> _texgen;
osg::ref_ptr<osg::StateSet> _stateset;
virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
virtual void cull( );
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) );
virtual void cullShadowReceivingScene( );
virtual void cullShadowCastingScene( );
virtual void addShadowReceivingTexGen( );
virtual const osg::Light* selectLight( osg::Vec4 &viewLightPos,
osg::Vec3 &viewLightDir );
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 resizeGLObjectBuffers(unsigned int maxSize);
virtual void releaseGLObjects(osg::State* = 0) const;
};
friend struct ViewData;
META_ViewDependentShadowTechniqueData( ThisClass, ThisClass::ViewData )
};
} // namespace osgShadow
#endif
DebugShadowMap
META_ViewDependentShadowTechniqueData
#define META_ViewDependentShadowTechniqueData(ShadowTechnique, TechniqueData)
Definition ViewDependentShadowTechnique:32
osgShadow::DebugShadowMap::DebugShadowMap
DebugShadowMap()
osgShadow::StandardShadowMap::_shadowTextureCoordIndex
unsigned int _shadowTextureCoordIndex
Definition StandardShadowMap:158
osgShadow::StandardShadowMap::getShadowVertexShader
osg::Shader * getShadowVertexShader()
Definition StandardShadowMap:103
osgShadow::StandardShadowMap::getShadowFragmentShader
osg::Shader * getShadowFragmentShader()
Definition StandardShadowMap:106
osgShadow::StandardShadowMap::setTextureSize
void setTextureSize(const osg::Vec2s &textureSize)
Definition StandardShadowMap:88
osgShadow::StandardShadowMap::_light
osg::ref_ptr< osg::Light > _light
Definition StandardShadowMap:151
osgShadow::StandardShadowMap::setLight
void setLight(osg::Light *light)
Definition StandardShadowMap:94
osgShadow::StandardShadowMap::setBaseTextureUnit
void setBaseTextureUnit(unsigned int unit)
Definition StandardShadowMap:42
osgShadow::StandardShadowMap::setBaseTextureCoordIndex
void setBaseTextureCoordIndex(unsigned int index)
Definition StandardShadowMap:71
osgShadow::StandardShadowMap::getBaseTextureUnit
unsigned int getBaseTextureUnit(void) const
Definition StandardShadowMap:45
osgShadow::StandardShadowMap::_baseTextureCoordIndex
unsigned int _baseTextureCoordIndex
Definition StandardShadowMap:157
osgShadow::StandardShadowMap::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgShadow::StandardShadowMap::~StandardShadowMap
virtual ~StandardShadowMap(void)
osgShadow::StandardShadowMap::_textureSize
osg::Vec2s _textureSize
Definition StandardShadowMap:154
osgShadow::StandardShadowMap::getShadowTextureCoordIndex
unsigned int getShadowTextureCoordIndex(void) const
Definition StandardShadowMap:85
osgShadow::StandardShadowMap::getTextureSize
const osg::Vec2s & getTextureSize() const
Definition StandardShadowMap:91
osgShadow::StandardShadowMap::_shadowTextureUnit
unsigned int _shadowTextureUnit
Definition StandardShadowMap:156
osgShadow::StandardShadowMap::setShadowTextureCoordIndex
void setShadowTextureCoordIndex(unsigned int index)
Definition StandardShadowMap:81
osgShadow::StandardShadowMap::META_Object
META_Object(osgShadow, StandardShadowMap)
osgShadow::StandardShadowMap::searchAndReplaceShaderSource
virtual void searchAndReplaceShaderSource(osg::Shader *, std::string fromString, std::string toString)
osgShadow::StandardShadowMap::StandardShadowMap
StandardShadowMap(const StandardShadowMap &ssm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
osgShadow::StandardShadowMap::setMainVertexShader
void setMainVertexShader(osg::Shader *shader)
Definition StandardShadowMap:121
osgShadow::StandardShadowMap::getMainVertexShader
osg::Shader * getMainVertexShader()
Definition StandardShadowMap:109
osgShadow::StandardShadowMap::getShadowTextureUnit
unsigned int getShadowTextureUnit(void) const
Definition StandardShadowMap:51
osgShadow::StandardShadowMap::setMainFragmentShader
void setMainFragmentShader(osg::Shader *shader)
Definition StandardShadowMap:124
osgShadow::StandardShadowMap::setShadowVertexShader
void setShadowVertexShader(osg::Shader *shader)
Definition StandardShadowMap:115
osgShadow::StandardShadowMap::_mainFragmentShader
osg::ref_ptr< osg::Shader > _mainFragmentShader
Definition StandardShadowMap:147
osgShadow::StandardShadowMap::_baseTextureUnit
unsigned int _baseTextureUnit
Definition StandardShadowMap:155
osgShadow::StandardShadowMap::_mainVertexShader
osg::ref_ptr< osg::Shader > _mainVertexShader
Definition StandardShadowMap:146
osgShadow::StandardShadowMap::_polygonOffsetFactor
float _polygonOffsetFactor
Definition StandardShadowMap:152
osgShadow::StandardShadowMap::_shadowVertexShader
osg::ref_ptr< osg::Shader > _shadowVertexShader
Definition StandardShadowMap:148
osgShadow::StandardShadowMap::StandardShadowMap
StandardShadowMap()
osgShadow::StandardShadowMap::BaseClass
DebugShadowMap BaseClass
Definition StandardShadowMap:30
osgShadow::StandardShadowMap::updateTextureCoordIndices
virtual void updateTextureCoordIndices(unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex)
osgShadow::StandardShadowMap::ThisClass
StandardShadowMap ThisClass
Definition StandardShadowMap:28
osgShadow::StandardShadowMap::setShadowFragmentShader
void setShadowFragmentShader(osg::Shader *shader)
Definition StandardShadowMap:118
osgShadow::StandardShadowMap::getMainFragmentShader
osg::Shader * getMainFragmentShader()
Definition StandardShadowMap:112
osgShadow::StandardShadowMap::getLight
const osg::Light * getLight(void) const
Definition StandardShadowMap:100
osgShadow::StandardShadowMap::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::StandardShadowMap::setShadowTextureUnit
void setShadowTextureUnit(unsigned int unit)
Definition StandardShadowMap:48
osgShadow::StandardShadowMap::_polygonOffsetUnits
float _polygonOffsetUnits
Definition StandardShadowMap:153
osgShadow::StandardShadowMap::getLight
osg::Light * getLight(void)
Definition StandardShadowMap:97
osgShadow::StandardShadowMap::_shadowFragmentShader
osg::ref_ptr< osg::Shader > _shadowFragmentShader
Definition StandardShadowMap:149
osgShadow::StandardShadowMap::getBaseTextureCoordIndex
unsigned int getBaseTextureCoordIndex(void) const
Definition StandardShadowMap:75
osgShadow::ViewDependentShadowTechnique::dirty
virtual void dirty()
osgUtil::CullVisitor
Definition CullVisitor:49
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Light
Definition Light:40
osg::Shader
Definition Shader:89
osg::State
Definition State:80
osg::Vec2s
Definition Vec2s:20
osg::ref_ptr< osg::Shader >
osgShadow
Definition ConvexPolyhedron:33
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::BoundingSphere
BoundingSphered BoundingSphere
Definition BoundingSphere:314
osg::Vec4
Vec4f Vec4
Definition Vec4:21
OSGSHADOW_EXPORT
#define OSGSHADOW_EXPORT
Definition osgShadow/Export:39
osgShadow::DebugShadowMap::ViewData
Definition DebugShadowMap:109
osgShadow::StandardShadowMap::ViewData
Definition StandardShadowMap:161
osgShadow::StandardShadowMap::ViewData::cullShadowCastingScene
virtual void cullShadowCastingScene()
osgShadow::StandardShadowMap::ViewData::resizeGLObjectBuffers
virtual void resizeGLObjectBuffers(unsigned int maxSize)
osgShadow::StandardShadowMap::ViewData::_shadowTextureUnitPtr
unsigned int * _shadowTextureUnitPtr
Definition StandardShadowMap:164
osgShadow::StandardShadowMap::ViewData::init
virtual void init(ThisClass *st, osgUtil::CullVisitor *cv)
osgShadow::StandardShadowMap::ViewData::addShadowReceivingTexGen
virtual void addShadowReceivingTexGen()
osgShadow::StandardShadowMap::ViewData::_lightPtr
osg::ref_ptr< osg::Light > * _lightPtr
Definition StandardShadowMap:162
osgShadow::StandardShadowMap::ViewData::_texgen
osg::ref_ptr< osg::TexGen > _texgen
Definition StandardShadowMap:172
osgShadow::StandardShadowMap::ViewData::releaseGLObjects
virtual void releaseGLObjects(osg::State *=0) const
osgShadow::StandardShadowMap::ViewData::aimShadowCastingCamera
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))
osgShadow::StandardShadowMap::ViewData::cullShadowReceivingScene
virtual void cullShadowReceivingScene()
osgShadow::StandardShadowMap::ViewData::aimShadowCastingCamera
virtual void aimShadowCastingCamera(const osg::Light *light, const osg::Vec4 &worldLightPos, const osg::Vec3 &worldLightDir, const osg::Vec3 &worldLightUp=osg::Vec3(0, 1, 0))
osgShadow::StandardShadowMap::ViewData::_baseTextureUnitPtr
unsigned int * _baseTextureUnitPtr
Definition StandardShadowMap:163
osgShadow::StandardShadowMap::ViewData::selectLight
virtual const osg::Light * selectLight(osg::Vec4 &viewLightPos, osg::Vec3 &viewLightDir)
osgShadow::StandardShadowMap::ViewData::cull
virtual void cull()
osgShadow::StandardShadowMap::ViewData::_stateset
osg::ref_ptr< osg::StateSet > _stateset
Definition StandardShadowMap:173