2007-09-22 21:06:07 +08:00
|
|
|
|
/* -*-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.
|
2007-09-19 19:56:44 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* ParallelSplitShadowMap written by Adrian Egli */
|
|
|
|
|
|
|
|
|
|
#ifndef OSGSHADOW_ParallelSplitShadowMap
|
|
|
|
|
#define OSGSHADOW_ParallelSplitShadowMap 1
|
|
|
|
|
|
|
|
|
|
#include <osg/Camera>
|
|
|
|
|
#include <osg/Material>
|
|
|
|
|
|
|
|
|
|
#include <osgShadow/ShadowTechnique>
|
2007-09-24 23:24:23 +08:00
|
|
|
|
|
2007-09-19 19:56:44 +08:00
|
|
|
|
namespace osgShadow {
|
2007-09-24 23:24:23 +08:00
|
|
|
|
|
2007-09-22 21:06:07 +08:00
|
|
|
|
class OSGSHADOW_EXPORT ParallelSplitShadowMap : public ShadowTechnique
|
2007-09-19 19:56:44 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ParallelSplitShadowMap(osg::Geode** debugGroup=NULL, int icountplanes=3);
|
|
|
|
|
|
|
|
|
|
ParallelSplitShadowMap(const ParallelSplitShadowMap& es, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
|
|
META_Object(osgShadow, ParallelSplitShadowMap);
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
/** Initialize the ShadowedScene and local cached data structures.*/
|
2007-09-19 19:56:44 +08:00
|
|
|
|
virtual void init();
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
/** Run the update traversal of the ShadowedScene and update any loca chached data structures.*/
|
2007-09-19 19:56:44 +08:00
|
|
|
|
virtual void update(osg::NodeVisitor& nv);
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
/** Run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/
|
2007-09-19 19:56:44 +08:00
|
|
|
|
virtual void cull(osgUtil::CullVisitor& cv);
|
|
|
|
|
|
|
|
|
|
/** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
|
|
|
|
|
virtual void cleanSceneGraph();
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
/** Switch on the debug coloring in GLSL (only the first 3 texture/splits showed for visualisation */
|
|
|
|
|
inline void setDebugColorOn() { _debug_color_in_GLSL = true; }
|
|
|
|
|
|
|
|
|
|
/** Set the polygon offset osg::Vec2f(factor,unit) */
|
|
|
|
|
inline void setPolygonOffset(const osg::Vec2f& p) { _polgyonOffset = p;_user_polgyonOffset_set=true;}
|
|
|
|
|
|
|
|
|
|
/** Get the polygon offset osg::Vec2f(factor,unit) */
|
|
|
|
|
inline const osg::Vec2f& getPolygonOffset() { return _polgyonOffset;}
|
|
|
|
|
|
|
|
|
|
/** Set the texture resolution */
|
|
|
|
|
inline void setTextureResolution(unsigned int resolution) { _resolution = resolution; }
|
|
|
|
|
|
2007-09-24 23:24:23 +08:00
|
|
|
|
/** Set the max far distance */
|
|
|
|
|
inline void setMaxFarDistance(double farDist) { _setMaxFarDistance = farDist; _isSetMaxFarDistance = true; }
|
|
|
|
|
|
2007-09-27 20:47:34 +08:00
|
|
|
|
/** 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 */
|
2007-09-24 23:24:23 +08:00
|
|
|
|
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. ->.
|
|
|
|
|
*/
|
2007-09-19 19:56:44 +08:00
|
|
|
|
protected :
|
|
|
|
|
|
|
|
|
|
virtual ~ParallelSplitShadowMap() {}
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount);
|
|
|
|
|
|
2007-09-19 19:56:44 +08:00
|
|
|
|
struct PSSMShadowSplitTexture {
|
|
|
|
|
// RTT
|
|
|
|
|
osg::ref_ptr<osg::Camera> _camera;
|
|
|
|
|
osg::ref_ptr<osg::TexGen> _texgen;
|
|
|
|
|
osg::ref_ptr<osg::Texture2D> _texture;
|
|
|
|
|
osg::ref_ptr<osg::StateSet> _stateset;
|
|
|
|
|
unsigned int _textureUnit;
|
|
|
|
|
osg::Vec2d _ambientBias;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
|
2007-09-19 19:56:44 +08:00
|
|
|
|
// Light (SUN)
|
|
|
|
|
osg::Vec3d _lightCameraSource;
|
|
|
|
|
osg::Vec3d _lightCameraTarget;
|
|
|
|
|
osg::Vec3d _frustumSplitCenter;
|
|
|
|
|
osg::Vec3d _lightDirection;
|
|
|
|
|
double _lightNear;
|
|
|
|
|
double _lightFar;
|
|
|
|
|
|
|
|
|
|
osg::Matrix _cameraView;
|
|
|
|
|
osg::Matrix _cameraProj;
|
|
|
|
|
|
|
|
|
|
unsigned int _splitID;
|
|
|
|
|
unsigned int _resolution;
|
|
|
|
|
|
|
|
|
|
osg::Uniform* _farDistanceSplit;
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
typedef std::map<unsigned int,PSSMShadowSplitTexture> PSSMShadowSplitTextureMap;
|
|
|
|
|
PSSMShadowSplitTextureMap _PSSMShadowSplitTextureMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void calculateFrustumCorners(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
|
|
|
|
|
void calculateLightInitalPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
|
|
|
|
|
void calculateLightNearFarFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
|
|
|
|
|
void calculateLightViewProjectionFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
|
|
|
|
|
|
|
|
|
|
osg::Geode** _displayTexturesGroupingNode;
|
|
|
|
|
|
|
|
|
|
unsigned int _textureUnitOffset;
|
|
|
|
|
|
2007-09-23 00:46:38 +08:00
|
|
|
|
unsigned int _number_of_splits;
|
|
|
|
|
|
|
|
|
|
bool _debug_color_in_GLSL;
|
|
|
|
|
|
|
|
|
|
osg::Vec2f _polgyonOffset;
|
|
|
|
|
bool _user_polgyonOffset_set;
|
|
|
|
|
|
|
|
|
|
unsigned int _resolution;
|
|
|
|
|
|
2007-09-24 23:24:23 +08:00
|
|
|
|
double _setMaxFarDistance;
|
|
|
|
|
bool _isSetMaxFarDistance;
|
|
|
|
|
|
|
|
|
|
bool _useFrontCullFace;
|
|
|
|
|
|
|
|
|
|
double _split_min_near_dist;
|
2007-09-27 20:47:34 +08:00
|
|
|
|
|
|
|
|
|
double _move_vcam_behind_rcam_factor;
|
|
|
|
|
|
2007-09-24 23:24:23 +08:00
|
|
|
|
bool _linearSplit;
|
|
|
|
|
|
2007-09-19 19:56:44 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
#endif
|