Moved ViewDependetShadowMap parameter settings into a dedicated ShadowSettings object in prep for making it possible to scale the API to handle multiple lights and multiple shadow maps per light.
This commit is contained in:
96
include/osgShadow/ShadowSettings
Normal file
96
include/osgShadow/ShadowSettings
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-20 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGSHADOW_SHADOWSETTINGS
|
||||
#define OSGSHADOW_SHADOWSETTINGS 1
|
||||
|
||||
#include <osg/Uniform>
|
||||
#include <osgShadow/Export>
|
||||
|
||||
namespace osgShadow {
|
||||
|
||||
/** ShadowSettings provides the parameters that the ShadowTechnique should use as a guide for setting up shadowing.*/
|
||||
class OSGSHADOW_EXPORT ShadowSettings : public osg::Object
|
||||
{
|
||||
public:
|
||||
ShadowSettings();
|
||||
ShadowSettings(const ShadowSettings& ss, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osgShadow, ShadowSettings);
|
||||
|
||||
void setLightNum(unsigned int lightNum) { _lightNum = lightNum; }
|
||||
unsigned int getLightNum() const { return _lightNum; }
|
||||
|
||||
void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; }
|
||||
unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; }
|
||||
|
||||
|
||||
/** Set the size of the shadow map textures.*/
|
||||
void setTextureSize(const osg::Vec2s& textureSize) { _textureSize = textureSize; }
|
||||
|
||||
/** Get the size of the shadow map textures.*/
|
||||
const osg::Vec2s& getTextureSize() const { return _textureSize; }
|
||||
|
||||
void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; }
|
||||
double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; }
|
||||
|
||||
enum ShadowMapProjectionHint
|
||||
{
|
||||
ORTHOGRAPHIC_SHADOW_MAP,
|
||||
PERSPECTIVE_SHADOW_MAP
|
||||
};
|
||||
|
||||
void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; }
|
||||
ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; }
|
||||
|
||||
/** Set the cut off angle, in degrees, between the light direction and the view direction
|
||||
* that determines whether perspective shadow mapping is appropriate, or thar orthographic shadow
|
||||
* map should be used instead. Default is 2 degrees so that for any angle greater than 2 degrees
|
||||
* perspective shadow map will be used, and any angle less than 2 degrees orthographic shadow map
|
||||
* will be used. Note, if ShadowMapProjectionHint is set to ORTHOGRAPHIC_SHADOW_MAP then an
|
||||
* orthographic shadow map will always be used.*/
|
||||
void setPerspectiveShadowMapCutOffAngle(double angle) { _perspectiveShadowMapCutOffAngle = angle; }
|
||||
double getPerspectiveShadowMapCutOffAngle() const { return _perspectiveShadowMapCutOffAngle; }
|
||||
|
||||
enum ShaderHint
|
||||
{
|
||||
NO_SHADERS,
|
||||
PROVIDE_FRAGMENT_SHADER,
|
||||
PROVIDE_VERTEX_AND_FRAGMENT_SHADER
|
||||
};
|
||||
|
||||
void setShaderHint(ShaderHint shaderHint) { _shaderHint = shaderHint; }
|
||||
ShaderHint getShaderHint() const { return _shaderHint; }
|
||||
|
||||
void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }
|
||||
bool getDebugDraw() const { return _debugDraw; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~ShadowSettings();
|
||||
|
||||
unsigned int _lightNum;
|
||||
unsigned int _baseShadowTextureUnit;
|
||||
osg::Vec2s _textureSize;
|
||||
|
||||
double _minimumShadowMapNearFarRatio;
|
||||
ShadowMapProjectionHint _shadowMapProjectionHint;
|
||||
double _perspectiveShadowMapCutOffAngle;
|
||||
ShaderHint _shaderHint;
|
||||
bool _debugDraw;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -38,6 +38,8 @@ class OSGSHADOW_EXPORT ShadowTechnique : public osg::Object
|
||||
META_Object(osgShadow, ShadowTechnique);
|
||||
|
||||
ShadowedScene* getShadowedScene() { return _shadowedScene; }
|
||||
|
||||
const ShadowedScene* getShadowedScene() const { return _shadowedScene; }
|
||||
|
||||
/** initialize the ShadowedScene and local cached data structures.*/
|
||||
virtual void init();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <osg/TexGenNode>
|
||||
|
||||
#include <osgShadow/ShadowTechnique>
|
||||
#include <osgShadow/ShadowSettings>
|
||||
|
||||
namespace osgShadow {
|
||||
|
||||
@@ -42,6 +43,10 @@ class OSGSHADOW_EXPORT ShadowedScene : public osg::Group
|
||||
void setCastsShadowTraversalMask(unsigned int mask) { _castsShadowTraversalMask = mask; }
|
||||
unsigned int getCastsShadowTraversalMask() const { return _castsShadowTraversalMask; }
|
||||
|
||||
void setShadowSettings(ShadowSettings* ss);
|
||||
ShadowSettings* getShadowSettings() { return _shadowSettings.get(); }
|
||||
const ShadowSettings* getShadowSettings() const { return _shadowSettings.get(); }
|
||||
|
||||
void setShadowTechnique(ShadowTechnique* technique);
|
||||
ShadowTechnique* getShadowTechnique() { return _shadowTechnique.get(); }
|
||||
const ShadowTechnique* getShadowTechnique() const { return _shadowTechnique.get(); }
|
||||
@@ -66,8 +71,9 @@ protected:
|
||||
|
||||
unsigned int _receivesShadowTraversalMask;
|
||||
unsigned int _castsShadowTraversalMask;
|
||||
|
||||
osg::ref_ptr<ShadowTechnique> _shadowTechnique;
|
||||
|
||||
osg::ref_ptr<ShadowSettings> _shadowSettings;
|
||||
osg::ref_ptr<ShadowTechnique> _shadowTechnique;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-20011 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
|
||||
@@ -152,49 +152,6 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
|
||||
ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv);
|
||||
|
||||
|
||||
/** Set the texture unit that the first shadow map will be placed on, if mulitple shadow maps are
|
||||
* required then each shadow map will use a allocated a unit relative to this base texture unit.*/
|
||||
void setBaseShadowTextureUnit(unsigned int unit) { _baseShadowTextureUnit = unit; }
|
||||
|
||||
/** Get the texture unit that the first shadow map will be placed on.*/
|
||||
unsigned int getBaseShadowTextureUnit() const { return _baseShadowTextureUnit; }
|
||||
|
||||
/** Set the size of the shadow map textures.*/
|
||||
void setTextureSize(const osg::Vec2s& textureSize) { _textureSize = textureSize; }
|
||||
|
||||
/** Get the size of the shadow map textures.*/
|
||||
const osg::Vec2s& getTextureSize() const { return _textureSize; }
|
||||
|
||||
void setMinimumShadowMapNearFarRatio(double ratio) { _minimumShadowMapNearFarRatio = ratio; }
|
||||
double getMinimumShadowMapNearFarRatio() const { return _minimumShadowMapNearFarRatio; }
|
||||
|
||||
enum ShadowMapProjectionHint
|
||||
{
|
||||
ORTHOGRAPHIC_SHADOW_MAP,
|
||||
PERSPECTIVE_SHADOW_MAP
|
||||
};
|
||||
|
||||
void setShadowMapProjectionHint(ShadowMapProjectionHint hint) { _shadowMapProjectionHint = hint; }
|
||||
ShadowMapProjectionHint getShadowMapProjectionHint() const { return _shadowMapProjectionHint; }
|
||||
|
||||
/** Set the cut off angle, in degrees, between the light direction and the view direction
|
||||
* that determines whether perspective shadow mapping is appropriate, or thar orthographic shadow
|
||||
* map should be used instead. Default is 2 degrees so that for any angle greater than 2 degrees
|
||||
* perspective shadow map will be used, and any angle less than 2 degrees orthographic shadow map
|
||||
* will be used. Note, if ShadowMapProjectionHint is set to ORTHOGRAPHIC_SHADOW_MAP then an
|
||||
* orthographic shadow map will always be used.*/
|
||||
void setPerspectiveShadowMapCutOffAngle(double angle) { _perspectiveShadowMapCutOffAngle = angle; }
|
||||
double getPerspectiveShadowMapCutOffAngle() const { return _perspectiveShadowMapCutOffAngle; }
|
||||
|
||||
enum ShaderHint
|
||||
{
|
||||
NO_SHADERS,
|
||||
PROVIDE_FRAGMENT_SHADER,
|
||||
PROVIDE_VERTEX_AND_FRAGMENT_SHADER
|
||||
};
|
||||
|
||||
void setShaderHint(ShaderHint shaderHint) { _shaderHint = shaderHint; }
|
||||
ShaderHint getShaderHint() const { return _shaderHint; }
|
||||
|
||||
virtual void createShaders();
|
||||
|
||||
@@ -214,10 +171,6 @@ class OSGSHADOW_EXPORT ViewDependentShadowMap : public ShadowTechnique
|
||||
|
||||
virtual osg::StateSet* selectStateSetForRenderingShadow(ViewDependentData& vdd) const;
|
||||
|
||||
|
||||
void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }
|
||||
bool getDebugDraw() const { return _debugDraw; }
|
||||
|
||||
|
||||
protected:
|
||||
virtual ~ViewDependentShadowMap();
|
||||
@@ -226,9 +179,6 @@ protected:
|
||||
mutable OpenThreads::Mutex _viewDependentDataMapMutex;
|
||||
ViewDependentDataMap _viewDependentDataMap;
|
||||
|
||||
unsigned int _baseShadowTextureUnit;
|
||||
osg::Vec2s _textureSize;
|
||||
|
||||
osg::ref_ptr<osg::StateSet> _shadowRecievingPlaceholderStateSet;
|
||||
|
||||
osg::ref_ptr<osg::StateSet> _shadowCastingStateSet;
|
||||
@@ -239,13 +189,6 @@ protected:
|
||||
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
|
||||
Uniforms _uniforms;
|
||||
osg::ref_ptr<osg::Program> _program;
|
||||
|
||||
double _minimumShadowMapNearFarRatio;
|
||||
ShadowMapProjectionHint _shadowMapProjectionHint;
|
||||
double _perspectiveShadowMapCutOffAngle;
|
||||
ShaderHint _shaderHint;
|
||||
bool _debugDraw;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user