OpenSceneGraph 3.6.5
StandardShadowMap
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 * ViewDependentShadow codes Copyright (C) 2008 Wojciech Lewandowski
14 * Thanks to to my company http://www.ai.com.pl for allowing me free this work.
15*/
16
17#ifndef OSGSHADOW_STANDARDSHADOWMAP
18#define OSGSHADOW_STANDARDSHADOWMAP 1
19
21
22namespace osgShadow {
23
25{
26 public :
31
34
38
41
42 void setBaseTextureUnit( unsigned int unit )
43 { _baseTextureUnit = unit; dirty(); }
44
45 unsigned int getBaseTextureUnit( void ) const
46 { return _baseTextureUnit; }
47
48 void setShadowTextureUnit( unsigned int unit )
49 { _shadowTextureUnit = unit; dirty(); }
50
51 unsigned int getShadowTextureUnit( void ) const
52 { return _shadowTextureUnit; }
53
54 // Texture Indices are changed by search and replace on shader source
55 // Carefully order these calls when changing both base and shadow indices
56 // In worst case when intend to swap indices
57 // one will have to call these methods more than once
58 // with one extra pass to change index to unused value to avoid
59 // unwanted superfluous replace:
60 //
61 // Example: Imagine we want to swap base(0) and shadow(1) indices:
62 // We have to do an extra step to make sure both do not end up as 1
63 //
64 // // initially change base to something else than 1
65 // setBaseTextureCoordIndex( 100 );
66 // // now search and replace all gl_TexCord[1] to gl_TexCord[0]
67 // setShadowTextureCoordIndex( 0 );
68 // // finally change base from 100 to 0
69 // setBaseTextureCoordIndex( 1 );
70
74
75 unsigned int getBaseTextureCoordIndex( void ) const
76 { return _baseTextureCoordIndex; }
77
78 // Texture Indices are changed by search and replace on shader source
79 // Look at the comment above setBaseTextureCoordIndex
80
84
85 unsigned int getShadowTextureCoordIndex( void ) const
86 { return _shadowTextureCoordIndex; }
87
88 void setTextureSize( const osg::Vec2s& textureSize )
89 { _textureSize = textureSize; dirty(); }
90
92 { return _textureSize; }
93
94 void setLight( osg::Light* light )
95 { _light = light; }
96
98 { return _light.get(); }
99
100 const osg::Light* getLight( void ) const
101 { return _light.get(); }
102
105
108
111
114
116 { _shadowVertexShader = shader; }
117
120
122 { _mainVertexShader = shader; }
123
125 { _mainFragmentShader = shader; }
126
127
129 virtual void resizeGLObjectBuffers(unsigned int maxSize);
130
134 virtual void releaseGLObjects(osg::State* = 0) const;
135
136protected:
138 virtual ~StandardShadowMap(void);
139
141 ( unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex );
142
144 ( osg::Shader*, std::string fromString, std::string toString );
145
150
155 unsigned int _baseTextureUnit;
156 unsigned int _shadowTextureUnit;
159
161 {
163 unsigned int * _baseTextureUnitPtr;
164 unsigned int * _shadowTextureUnitPtr;
165
166 // ShadowMap texture is defined by base DebugShadowMap
167 // osg::ref_ptr<osg::Texture2D> _texture;
168
169 // ShadowMap camera is defined by base DebugShadowMap
170 // osg::ref_ptr<osg::Camera> _camera;
171
174
175 virtual void init( ThisClass * st, osgUtil::CullVisitor * cv );
176
177 virtual void cull( );
178
180 const osg::BoundingSphere &bounds,
181 const osg::Light *light,
182 const osg::Vec4 &worldLightPos,
183 const osg::Vec3 &worldLightDir,
184 const osg::Vec3 &worldLightUp = osg::Vec3(0,1,0) );
185
187
188 virtual void cullShadowCastingScene( );
189
191
192 virtual const osg::Light* selectLight( osg::Vec4 &viewLightPos,
193 osg::Vec3 &viewLightDir );
194
195 virtual void aimShadowCastingCamera( const osg::Light *light,
196 const osg::Vec4 &worldLightPos,
197 const osg::Vec3 &worldLightDir,
198 const osg::Vec3 &worldLightUp
199 = osg::Vec3(0,1,0) );
200
201 virtual void resizeGLObjectBuffers(unsigned int maxSize);
202 virtual void releaseGLObjects(osg::State* = 0) const;
203 };
204
205 friend struct ViewData;
206
208};
209
210} // namespace osgShadow
211
212#endif
#define META_ViewDependentShadowTechniqueData(ShadowTechnique, TechniqueData)
META_ViewDependentShadowTechniqueData macro defines initViewDependentData method used by derived shad...
Definition ViewDependentShadowTechnique:32
Vec3f Vec3
Definition Vec3:21
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Vec4f Vec4
Definition Vec4:21
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
Light state class which encapsulates OpenGL glLight() functionality.
Definition Light:40
osg::Shader is an application-level abstraction of an OpenGL glShader.
Definition Shader:89
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Definition Vec2s:20
DebugShadowMap()
Classic OSG constructor.
Definition DebugShadowMap:109
unsigned int _shadowTextureCoordIndex
Definition StandardShadowMap:158
osg::Shader * getShadowVertexShader()
Definition StandardShadowMap:103
osg::Shader * getShadowFragmentShader()
Definition StandardShadowMap:106
void setTextureSize(const osg::Vec2s &textureSize)
Definition StandardShadowMap:88
osg::ref_ptr< osg::Light > _light
Definition StandardShadowMap:151
void setLight(osg::Light *light)
Definition StandardShadowMap:94
void setBaseTextureUnit(unsigned int unit)
Definition StandardShadowMap:42
void setBaseTextureCoordIndex(unsigned int index)
Definition StandardShadowMap:71
unsigned int getBaseTextureUnit(void) const
Definition StandardShadowMap:45
unsigned int _baseTextureCoordIndex
Definition StandardShadowMap:157
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
virtual ~StandardShadowMap(void)
Classic protected OSG destructor.
osg::Vec2s _textureSize
Definition StandardShadowMap:154
unsigned int getShadowTextureCoordIndex(void) const
Definition StandardShadowMap:85
const osg::Vec2s & getTextureSize() const
Definition StandardShadowMap:91
unsigned int _shadowTextureUnit
Definition StandardShadowMap:156
void setShadowTextureCoordIndex(unsigned int index)
Definition StandardShadowMap:81
META_Object(osgShadow, StandardShadowMap)
Declaration of standard OSG object methods.
virtual void searchAndReplaceShaderSource(osg::Shader *, std::string fromString, std::string toString)
StandardShadowMap(const StandardShadowMap &ssm, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Classic OSG cloning constructor.
void setMainVertexShader(osg::Shader *shader)
Definition StandardShadowMap:121
osg::Shader * getMainVertexShader()
Definition StandardShadowMap:109
unsigned int getShadowTextureUnit(void) const
Definition StandardShadowMap:51
void setMainFragmentShader(osg::Shader *shader)
Definition StandardShadowMap:124
void setShadowVertexShader(osg::Shader *shader)
Definition StandardShadowMap:115
osg::ref_ptr< osg::Shader > _mainFragmentShader
Definition StandardShadowMap:147
unsigned int _baseTextureUnit
Definition StandardShadowMap:155
osg::ref_ptr< osg::Shader > _mainVertexShader
Definition StandardShadowMap:146
float _polygonOffsetFactor
Definition StandardShadowMap:152
osg::ref_ptr< osg::Shader > _shadowVertexShader
Definition StandardShadowMap:148
StandardShadowMap()
Classic OSG constructor.
DebugShadowMap BaseClass
Convenient typedef used in definition of ViewData struct and methods.
Definition StandardShadowMap:30
virtual void updateTextureCoordIndices(unsigned int baseTexCoordIndex, unsigned int shadowTexCoordIndex)
StandardShadowMap ThisClass
Convenient typedef used in definition of ViewData struct and methods.
Definition StandardShadowMap:28
void setShadowFragmentShader(osg::Shader *shader)
Definition StandardShadowMap:118
osg::Shader * getMainFragmentShader()
Definition StandardShadowMap:112
const osg::Light * getLight(void) const
Definition StandardShadowMap:100
virtual void releaseGLObjects(osg::State *=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
void setShadowTextureUnit(unsigned int unit)
Definition StandardShadowMap:48
float _polygonOffsetUnits
Definition StandardShadowMap:153
osg::Light * getLight(void)
Definition StandardShadowMap:97
osg::ref_ptr< osg::Shader > _shadowFragmentShader
Definition StandardShadowMap:149
unsigned int getBaseTextureCoordIndex(void) const
Definition StandardShadowMap:75
Definition StandardShadowMap:161
virtual void resizeGLObjectBuffers(unsigned int maxSize)
unsigned int * _shadowTextureUnitPtr
Definition StandardShadowMap:164
virtual void init(ThisClass *st, osgUtil::CullVisitor *cv)
osg::ref_ptr< osg::Light > * _lightPtr
Definition StandardShadowMap:162
osg::ref_ptr< osg::TexGen > _texgen
Definition StandardShadowMap:172
virtual void releaseGLObjects(osg::State *=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
virtual void aimShadowCastingCamera(const osg::BoundingSphere &bounds, const osg::Light *light, const osg::Vec4 &worldLightPos, const osg::Vec3 &worldLightDir, const osg::Vec3 &worldLightUp=osg::Vec3(0, 1, 0))
virtual void aimShadowCastingCamera(const osg::Light *light, const osg::Vec4 &worldLightPos, const osg::Vec3 &worldLightDir, const osg::Vec3 &worldLightUp=osg::Vec3(0, 1, 0))
unsigned int * _baseTextureUnitPtr
Definition StandardShadowMap:163
virtual const osg::Light * selectLight(osg::Vec4 &viewLightPos, osg::Vec3 &viewLightDir)
virtual void cull()
Method called by ViewDependentShadowTechnique to allow ViewData do the hard work computing shadows fo...
osg::ref_ptr< osg::StateSet > _stateset
Definition StandardShadowMap:173
virtual void dirty()
Dirty view data bits and force update of view data resources.
Basic NodeVisitor implementation for rendering a scene.
Definition CullVisitor:49
#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.