OpenSceneGraph 3.6.5
ParallelSplitShadowMap
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14/* ParallelSplitShadowMap written by Adrian Egli
15 *
16 * this version has still a bug in mutli-thread application (flickering problem)
17 * to avoid the flickering problem try osgShadow --pssm --SingleThreaded your_scene.ive
18 *
19 * The Parallel Split Shadow Map only supports directional light for simulating the shadow.
20 * It's one of the most robust algorithm for huge terrain sun light's shadow simulation, if
21 * you need to shadow a terrain, or another huge scene, you should use Parallel Split Shadow Map
22 * or at least test it against your scene. Have fun.
23 *
24 */
25
26#ifndef OSGSHADOW_ParallelSplitShadowMap
27#define OSGSHADOW_ParallelSplitShadowMap 1
28
29#include <osg/Camera>
30#include <osg/Material>
31#include <osg/Depth>
32#include <osg/ClipPlane>
33
35
36namespace osgShadow {
37
39{
40 public:
41 ParallelSplitShadowMap(osg::Geode** debugGroup=NULL, int icountplanes=3);
42
44
46
47
49 virtual void init();
50
52 virtual void update(osg::NodeVisitor& nv);
53
55 virtual void cull(osgUtil::CullVisitor& cv);
56
58 virtual void cleanSceneGraph();
59
61 inline void setDebugColorOn() { _debug_color_in_GLSL = true; }
62
64 inline void setPolygonOffset(const osg::Vec2f& p) { _polgyonOffset = p;_user_polgyonOffset_set=true;}
65
67 inline const osg::Vec2f& getPolygonOffset() const { return _polgyonOffset;}
68
70 inline void setTextureResolution(unsigned int resolution) { _resolution = resolution; }
71
73 inline unsigned int getTextureResolution() const { return _resolution; }
74
76 inline void setMaxFarDistance(double farDist) { _setMaxFarDistance = farDist; _isSetMaxFarDistance = true; }
77
79 inline double getMaxFarDistance() const { return _setMaxFarDistance; }
80
82 inline void setMoveVCamBehindRCamFactor(double distFactor ) { _move_vcam_behind_rcam_factor = distFactor; }
83
85 inline double getMoveVCamBehindRCamFactor() const { return _move_vcam_behind_rcam_factor; }
86
88 inline void setMinNearDistanceForSplits(double nd){ _split_min_near_dist=nd; }
89
91 inline double getMinNearDistanceForSplits() const { return _split_min_near_dist; }
92
97 inline void setUserLight(osg::Light* light) { _userLight = light; }
98
100 inline const osg::Light* getUserLight() const { return _userLight.get(); }
101
103 void setAmbientBias(const osg::Vec2& ambientBias );
104
106 const osg::Vec2& getAmbientBias() const { return _ambientBias; }
107
112 public:
116 virtual std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount,double textureRes, bool filtered, unsigned int nbrSplits,unsigned int textureOffset);
117 };
118
120 inline void setFragmentShaderGenerator(FragmentShaderGenerator* fsw) { _FragmentShaderGenerator = fsw;}
121
123 inline void enableShadowGLSLFiltering(bool filtering = true) { _GLSL_shadow_filtered = filtering; }
124
129
131 inline void setSplitCalculationMode(SplitCalcMode scm=SPLIT_EXP) { _SplitCalcMode = scm; }
132
134 inline SplitCalcMode getSplitCalculationMode() const { return _SplitCalcMode; }
135
136
138 virtual void resizeGLObjectBuffers(unsigned int maxSize);
139
143 virtual void releaseGLObjects(osg::State* = 0) const;
144
145 protected :
146
148
149
186
187 typedef std::map<unsigned int,PSSMShadowSplitTexture> PSSMShadowSplitTextureMap;
189
190
191 private:
192 void calculateFrustumCorners(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
193 void calculateLightInitialPosition(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
194 void calculateLightNearFarFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
195 void calculateLightViewProjectionFormFrustum(PSSMShadowSplitTexture &pssmShadowSplitTexture,osg::Vec3d *frustumCorners);
196
197 osg::Geode** _displayTexturesGroupingNode;
198
199 unsigned int _textureUnitOffset;
200
201 unsigned int _number_of_splits;
202
203 bool _debug_color_in_GLSL;
204
205 osg::Vec2 _polgyonOffset;
206 bool _user_polgyonOffset_set;
207
208 unsigned int _resolution;
209
210 double _setMaxFarDistance;
211 bool _isSetMaxFarDistance;
212
213 double _split_min_near_dist;
214
215 double _move_vcam_behind_rcam_factor;
216
217 osg::ref_ptr<osg::Light> _userLight;
218 osg::ref_ptr<FragmentShaderGenerator> _FragmentShaderGenerator;
219
220 bool _GLSL_shadow_filtered;
221 SplitCalcMode _SplitCalcMode;
222
223 osg::Uniform* _ambientBiasUniform;
224 osg::Vec2 _ambientBias;
225
226};
227}
228#endif
Vec2f Vec2
Definition Vec2:21
Matrixd Matrix
Definition Matrix:27
The osgShadow library is a NodeKit that extends the core scene graph to add support for a range of sh...
Definition ConvexPolyhedron:33
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
Light state class which encapsulates OpenGL glLight() functionality.
Definition Light:40
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Uniform encapsulates glUniform values.
Definition Uniform:414
General purpose float pair.
Definition Vec2f:29
General purpose double triple for use as vertices, vectors and normals.
Definition Vec3d:30
void setPolygonOffset(const osg::Vec2f &p)
Set the polygon offset osg::Vec2f(factor,unit)
Definition ParallelSplitShadowMap:64
virtual void cull(osgUtil::CullVisitor &cv)
Run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.
ParallelSplitShadowMap(const ParallelSplitShadowMap &es, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
virtual void init()
Initialize the ShadowedScene and local cached data structures.
void setFragmentShaderGenerator(FragmentShaderGenerator *fsw)
set fragment shader generator
Definition ParallelSplitShadowMap:120
ParallelSplitShadowMap(osg::Geode **debugGroup=NULL, int icountplanes=3)
SplitCalcMode
Definition ParallelSplitShadowMap:125
@ SPLIT_EXP
Definition ParallelSplitShadowMap:127
@ SPLIT_LINEAR
Definition ParallelSplitShadowMap:126
PSSMShadowSplitTextureMap _PSSMShadowSplitTextureMap
Definition ParallelSplitShadowMap:188
void setMoveVCamBehindRCamFactor(double distFactor)
Set the factor for moving the virtual camera behind the real camera.
Definition ParallelSplitShadowMap:82
void setSplitCalculationMode(SplitCalcMode scm=SPLIT_EXP)
set split calculation mode
Definition ParallelSplitShadowMap:131
void setDebugColorOn()
Switch on the debug coloring in GLSL (only the first 3 texture/splits showed for visualisation.
Definition ParallelSplitShadowMap:61
META_Object(osgShadow, ParallelSplitShadowMap)
std::map< unsigned int, PSSMShadowSplitTexture > PSSMShadowSplitTextureMap
Definition ParallelSplitShadowMap:187
double getMaxFarDistance() const
Get the max far distance.
Definition ParallelSplitShadowMap:79
virtual ~ParallelSplitShadowMap()
Definition ParallelSplitShadowMap:147
void setMaxFarDistance(double farDist)
Set the max far distance.
Definition ParallelSplitShadowMap:76
double getMinNearDistanceForSplits() const
Get min near distance for splits.
Definition ParallelSplitShadowMap:91
void setTextureResolution(unsigned int resolution)
Set the texture resolution.
Definition ParallelSplitShadowMap:70
void setMinNearDistanceForSplits(double nd)
Set min near distance for splits.
Definition ParallelSplitShadowMap:88
const osg::Light * getUserLight() const
get the user defined light for shadow simulation
Definition ParallelSplitShadowMap:100
void enableShadowGLSLFiltering(bool filtering=true)
enable / disable shadow filtering
Definition ParallelSplitShadowMap:123
void setAmbientBias(const osg::Vec2 &ambientBias)
Set the values for the ambient bias the shader will use.
double getMoveVCamBehindRCamFactor() const
Get the factor for moving the virtual camera behind the real camera.
Definition ParallelSplitShadowMap:85
unsigned int getTextureResolution() const
Get the texture resolution.
Definition ParallelSplitShadowMap:73
virtual void update(osg::NodeVisitor &nv)
Run the update traversal of the ShadowedScene and update any loca chached data structures.
const osg::Vec2f & getPolygonOffset() const
Get the polygon offset osg::Vec2f(factor,unit)
Definition ParallelSplitShadowMap:67
const osg::Vec2 & getAmbientBias() const
Get the values for the ambient bias the shader will use.
Definition ParallelSplitShadowMap:106
virtual void cleanSceneGraph()
Clean scene graph from any shadow technique specific nodes, state and drawables.
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual void releaseGLObjects(osg::State *=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
void setUserLight(osg::Light *light)
set a user defined light for shadow simulation (sun light, ... ) when this light get passed to pssm,...
Definition ParallelSplitShadowMap:97
SplitCalcMode getSplitCalculationMode() const
get split calculation mode
Definition ParallelSplitShadowMap:134
you can overwrite the fragment shader if you like to modify it yourself, own fragment shader can be u...
Definition ParallelSplitShadowMap:111
virtual std::string generateGLSL_FragmentShader_BaseTex(bool debug, unsigned int splitCount, double textureRes, bool filtered, unsigned int nbrSplits, unsigned int textureOffset)
generate the GLSL fragment shader
double _lightFar
Definition ParallelSplitShadowMap:172
double _lightNear
Definition ParallelSplitShadowMap:171
osg::Vec3d _frustumSplitCenter
Definition ParallelSplitShadowMap:169
unsigned int _splitID
Definition ParallelSplitShadowMap:177
osg::ref_ptr< osg::TexGen > _texgen
Definition ParallelSplitShadowMap:153
osg::ref_ptr< osg::Texture2D > _texture
Definition ParallelSplitShadowMap:154
osg::Vec3d _lightCameraTarget
Definition ParallelSplitShadowMap:168
osg::ref_ptr< osg::Texture2D > _debug_texture
Definition ParallelSplitShadowMap:162
double _split_far
Definition ParallelSplitShadowMap:159
osg::Vec3d _lightDirection
Definition ParallelSplitShadowMap:170
osg::ref_ptr< osg::StateSet > _debug_stateset
Definition ParallelSplitShadowMap:163
unsigned int _resolution
Definition ParallelSplitShadowMap:178
osg::Matrix _cameraView
Definition ParallelSplitShadowMap:174
osg::ref_ptr< osg::Camera > _camera
Definition ParallelSplitShadowMap:152
osg::ref_ptr< osg::StateSet > _stateset
Definition ParallelSplitShadowMap:155
osg::ref_ptr< osg::Uniform > _farDistanceSplit
Definition ParallelSplitShadowMap:180
osg::Matrix _cameraProj
Definition ParallelSplitShadowMap:175
unsigned int _textureUnit
Definition ParallelSplitShadowMap:156
osg::ref_ptr< osg::Camera > _debug_camera
Definition ParallelSplitShadowMap:161
unsigned int _debug_textureUnit
Definition ParallelSplitShadowMap:164
osg::Vec3d _lightCameraSource
Definition ParallelSplitShadowMap:167
Basic NodeVisitor implementation for rendering a scene.
Definition CullVisitor:49
#define NULL
Definition Export:55
#define OSGSHADOW_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 27 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.