From Adrian Egli, improvements to ParallelSplitShadowMap implementation

This commit is contained in:
Robert Osfield
2008-05-28 14:11:22 +00:00
parent 8e91926ca5
commit 1047f970bb
3 changed files with 348 additions and 306 deletions

View File

@@ -11,13 +11,24 @@
* OpenSceneGraph Public License for more details.
*/
/* ParallelSplitShadowMap written by Adrian Egli */
/* ParallelSplitShadowMap written by Adrian Egli
*
* this version has still a bug in mutli-thread application (flickering problem)
* to avoid the flickering problem try osgShadow --pssm --SingleThreaded your_scene.ive
*
* The Parallel Split Shadow Map only supports directional light for simulating the shadow.
* It's one of the most robust algorithm for huge terrain sun light's shadow simulation, if
* you need to shadow a terrain, or another huge scene, you should use Parallel Split Shadow Map
* or at least test it against your scene. Have fun.
*
*/
#ifndef OSGSHADOW_ParallelSplitShadowMap
#define OSGSHADOW_ParallelSplitShadowMap 1
#include <osg/Camera>
#include <osg/Material>
#include <osg/Depth>
#include <osgShadow/ShadowTechnique>
@@ -32,7 +43,7 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
META_Object(osgShadow, ParallelSplitShadowMap);
/** Initialize the ShadowedScene and local cached data structures.*/
virtual void init();
@@ -63,41 +74,28 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
/** Set the factor for moving the virtual camera behind the real camera*/
inline void setMoveVCamBehindRCamFactor(double distFactor ) { _move_vcam_behind_rcam_factor = distFactor; }
/** Force to add a cull face front */
inline void forceFrontCullFace() { _useFrontCullFace = true; }
/** 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;}
/**
light / |
\ / |
min near dist / |
for splits / |
\ / <20> |
./ \ <20> |
| \ <20> |
| x <20> |
| <20> |
. | |
\ <20> |
\ <20> |
\ |
\ |
\ |
.<- max far dist. ->.
*/
/** 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 );
protected :
virtual ~ParallelSplitShadowMap() {}
std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount);
struct PSSMShadowSplitTexture {
// RTT
osg::ref_ptr<osg::Camera> _camera;
@@ -105,16 +103,15 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
osg::ref_ptr<osg::Texture2D> _texture;
osg::ref_ptr<osg::StateSet> _stateset;
unsigned int _textureUnit;
osg::Vec2d _ambientBias;
osg::ref_ptr<osg::Depth> _depth;
osg::ref_ptr<osg::Camera> _debug_camera;
osg::ref_ptr<osg::Texture2D> _debug_texture;
osg::ref_ptr<osg::StateSet> _debug_stateset;
unsigned int _debug_textureUnit;
// Light (SUN)
osg::Vec3d _lightCameraSource;
osg::Vec3d _lightCameraTarget;
@@ -123,11 +120,11 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
double _lightNear;
double _lightFar;
osg::Matrix _cameraView;
osg::Matrix _cameraProj;
osg::Matrix _cameraView;
osg::Matrix _cameraProj;
unsigned int _splitID;
unsigned int _resolution;
unsigned int _splitID;
unsigned int _resolution;
osg::Uniform* _farDistanceSplit;
@@ -158,14 +155,18 @@ class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
double _setMaxFarDistance;
bool _isSetMaxFarDistance;
bool _useFrontCullFace;
double _split_min_near_dist;
double _move_vcam_behind_rcam_factor;
bool _linearSplit;
osg::Light* _userLight;
osg::Uniform* _ambientBiasUniform;
osg::Vec2d _ambientBias;
};
}
#endif