From Christopher Blaesius,

"Soft shadow mapping is basically the same as hard shadow mapping beside that
it uses a different fragment shader.
So for me it makes sense that osgShadow::SoftShadowMap is derived from
osgShadow::ShadowMap, this makes it easier to maintain the two classes.
Additional SoftShadowMap also provides the same Debug methods as ShadowMap."
This commit is contained in:
Robert Osfield
2008-09-18 14:48:28 +00:00
parent 47e07244b9
commit 1d328ba0d4
3 changed files with 139 additions and 369 deletions

View File

@@ -91,9 +91,9 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique
virtual ~ShadowMap(void) {};
/** Create the managed Uniforms */
void createUniforms();
virtual void createUniforms();
void createShaders();
virtual void createShaders();
osg::ref_ptr<osg::Camera> _camera;
osg::ref_ptr<osg::TexGen> _texgen;

View File

@@ -16,13 +16,15 @@
#include <osg/Camera>
#include <osg/Material>
#include <osg/MatrixTransform>
#include <osg/LightSource>
#include <osgShadow/ShadowTechnique>
#include <osgShadow/ShadowMap>
namespace osgShadow {
/** SoftShadowMap provides an implementation of soft shadows with shadow maps.*/
class OSGSHADOW_EXPORT SoftShadowMap : public ShadowTechnique
class OSGSHADOW_EXPORT SoftShadowMap : public ShadowMap
{
public :
SoftShadowMap();
@@ -31,85 +33,57 @@ class OSGSHADOW_EXPORT SoftShadowMap : public ShadowTechnique
META_Object(osgShadow, SoftShadowMap);
/** Set the texture unit that the shadow texture will be applied on.*/
void setTextureUnit(unsigned int unit);
/** Get the texture unit that the shadow texture will be applied on.*/
unsigned int getTextureUnit() const { return _textureUnit; }
/** Set the values for the ambient bias the shader will use.*/
void setAmbientBias(const osg::Vec2& ambientBias );
/** Set the resolution of the rendertarget texture used for shadow generation */
void setTextureSize(int width, int height) { setTextureSize(osg::Vec2s(width, height)); }
/** Set the resolution of the rendertarget texture used for shadow generation */
void setTextureSize(const osg::Vec2s&);
/** Get the resolution of the rendertarget texture used for shadow generation */
const osg::Vec2s& getTextureSize() const { return _textureSize; }
/** Add a small bias to the z-value when calculating the MVPT matrix, this can reduce
* shadow acne problem.
* Suitable values are 0-0.005
* Default is 0. */
void setBias(float bias) { _bias = bias; }
/** Return the bias value set used when calculating the MVPT matrix */
float getBias() const { return _bias; }
/** Set the values for width of the soft penumbra the shader will use.
* Zero is for hard shadow (no penumbra). 0.01 is already very soft penumbra.
* Default is 0.005.*/
void setSoftnessWidth(const float softnesswidth );
void setSoftnessWidth(const float softnessWidth);
/** Get the value used for width of the soft penumbra in the shader.*/
float getSoftnessWidth() const { return _softnessWidth; }
/** Set the values for jittering scale the shader will use.
* Zero is no jittering (i.e. see the banding in penumbra)
* High values (>64) cause 'pixelization' of the penumbra.
* Usually but not necessarily power of two number.
* Default is 32. */
void setJitteringScale(const float jitteringscale );
/** Get the values that are used for the ambient bias in the shader.*/
const osg::Vec2& getAmbientBias() const { return _ambientBias; }
/** Get the value used for width of the soft penumbra in the shader.*/
const float getSoftnessWidth() const { return _softnesswidth; }
void setJitteringScale(const float jitteringScale);
/** Get the value used for jittering scale in the shader.*/
const float getJitteringScale() const { return _jitteringscale; }
float getJitteringScale() const { return _jitteringScale; }
/** initialize the ShadowedScene and local cached data structures.*/
virtual void init();
/** Set the texture unit that the jitter texture will be applied on.*/
void setJitterTextureUnit(unsigned int jitterTextureUnit);
/** run the update traversal of the ShadowedScene and update any loca chached data structures.*/
virtual void update(osg::NodeVisitor& nv);
/** run the cull traversal of the ShadowedScene and set up the rendering for this ShadowTechnique.*/
virtual void cull(osgUtil::CullVisitor& cv);
/** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
virtual void cleanSceneGraph();
/** Get the texture unit that the jitter texture will be applied on.*/
unsigned int getJitterTextureUnit() const { return _jitterTextureUnit; }
protected :
/** Add a small bias to the z-value, this can reduce
* shadow acne problem.
* This is the same as calling setPolygonOffset(osg::Vec2(bias,0));
* Suitable values are 0-0.005
* Default is 0. */
void setBias(float bias) { setPolygonOffset(osg::Vec2(bias,0)); }
/** Return the bias value */
float getBias() const { return getPolygonOffset().x(); }
virtual ~SoftShadowMap() {}
void initJittering(osg::StateSet *);
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::Vec2 _ambientBias;
float _softnesswidth;
float _jitteringscale;
float _bias;
osg::Vec2s _textureSize;
protected:
virtual ~SoftShadowMap(void) {};
/** Create the managed Uniforms */
void createUniforms();
void createShaders();
void initJittering(osg::StateSet *ss);
osg::ref_ptr<osg::Uniform> _softnessWidthUniform;
osg::ref_ptr<osg::Uniform> _jitteringScaleUniform;
float _softnessWidth;
float _jitteringScale;
unsigned int _jitterTextureUnit;
};