From Adrian Egli, "Improvements to the PSSM implementation"

This commit is contained in:
Robert Osfield
2008-06-19 14:45:54 +00:00
parent cc9d12f34f
commit 0faaf93dc2
2 changed files with 211 additions and 174 deletions

View File

@@ -29,6 +29,7 @@
#include <osg/Camera>
#include <osg/Material>
#include <osg/Depth>
#include <osg/ClipPlane>
#include <osgShadow/ShadowTechnique>
@@ -77,24 +78,45 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
/** Set min near distance for splits */
inline void setMinNearDistanceForSplits(double nd){ _split_min_near_dist=nd; }
/** use linear split (default: linear) */
inline void useLinearSplit(bool flag) { _linearSplit = flag;}
/** set a user defined light for shadow simulation (sun light, ... )
* when this light get passed to pssm, the scene's light are no longer collected
* and simulated. just this user passed light, it needs to be a directional light.
*/
inline void setUserLight(osg::Light* light) { _userLight = light; }
/** Set the values for the ambient bias the shader will use.*/
void setAmbientBias(const osg::Vec2& ambientBias );
/**
* you can overwrite the fragment shader if you like to modify it yourself, own fragment shader can be used
*/
class FragmentShaderGenerator : public osg::Referenced {
public:
/**
* generate the GLSL fragement shader
*/
virtual std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount,double textureRes, bool filtered, unsigned int nbrSplits,unsigned int textureOffset);
};
/** set fragment shader generator */
inline void setFragmentShaderGenerator(FragmentShaderGenerator* fsw) { _FragmentShaderGenerator = fsw;}
/** enable / disable shadow filtering */
inline void enableShadowGLSLFiltering(bool filtering = true) { _GLSL_shadow_filtered = filtering; }
enum SplitCalcMode {
SPLIT_LINEAR,
SPLIT_EXP
};
/** set split calculation mode */
inline void setSplitCalculationMode(SplitCalcMode scm=SPLIT_EXP) { _SplitCalcMode = scm; }
protected :
virtual ~ParallelSplitShadowMap() {}
std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount);
struct PSSMShadowSplitTexture {
// RTT
@@ -105,7 +127,7 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
unsigned int _textureUnit;
osg::ref_ptr<osg::Depth> _depth;
double _split_far;
osg::ref_ptr<osg::Camera> _debug_camera;
osg::ref_ptr<osg::Texture2D> _debug_texture;
@@ -127,8 +149,8 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
unsigned int _resolution;
osg::Uniform* _farDistanceSplit;
};
typedef std::map<unsigned int,PSSMShadowSplitTexture> PSSMShadowSplitTextureMap;
PSSMShadowSplitTextureMap _PSSMShadowSplitTextureMap;
@@ -158,11 +180,12 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
double _split_min_near_dist;
double _move_vcam_behind_rcam_factor;
osg::ref_ptr<osg::Light> _userLight;
osg::ref_ptr<FragmentShaderGenerator> _FragmentShaderGenerator;
bool _linearSplit;
osg::Light* _userLight;
bool _GLSL_shadow_filtered;
SplitCalcMode _SplitCalcMode;
osg::Uniform* _ambientBiasUniform;
osg::Vec2d _ambientBias;