From Anders Backman, added bias and texture size methods.
From Robert Osfield, tweaks to the above for method parameters and indenting.
This commit is contained in:
parent
5fb9673382
commit
55a9ea19d7
@ -40,6 +40,27 @@ class OSGSHADOW_EXPORT SoftShadowMap : public ShadowTechnique
|
||||
/** 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.*/
|
||||
@ -87,6 +108,9 @@ class OSGSHADOW_EXPORT SoftShadowMap : public ShadowTechnique
|
||||
osg::Vec2 _ambientBias;
|
||||
float _softnesswidth;
|
||||
float _jitteringscale;
|
||||
float _bias;
|
||||
osg::Vec2s _textureSize;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -157,7 +157,9 @@ SoftShadowMap::SoftShadowMap():
|
||||
_textureUnit(1),
|
||||
_ambientBias(0.5f,0.5f),
|
||||
_softnesswidth(0.005f),
|
||||
_jitteringscale(32.f)
|
||||
_jitteringscale(32.f),
|
||||
_bias(0.0f),
|
||||
_textureSize(1024, 1024)
|
||||
{
|
||||
}
|
||||
|
||||
@ -166,7 +168,9 @@ SoftShadowMap::SoftShadowMap(const SoftShadowMap& copy, const osg::CopyOp& copyo
|
||||
_textureUnit(copy._textureUnit),
|
||||
_ambientBias(copy._ambientBias),
|
||||
_softnesswidth(copy._softnesswidth),
|
||||
_jitteringscale(copy._jitteringscale)
|
||||
_jitteringscale(copy._jitteringscale),
|
||||
_bias(copy._bias),
|
||||
_textureSize(copy._textureSize)
|
||||
{
|
||||
}
|
||||
|
||||
@ -190,16 +194,24 @@ void SoftShadowMap::setJitteringScale(const float jitteringscale )
|
||||
_jitteringscale = jitteringscale;
|
||||
}
|
||||
|
||||
void SoftShadowMap::setTextureSize(const osg::Vec2s& texsize)
|
||||
{
|
||||
_textureSize = texsize;
|
||||
|
||||
if (_texture.valid())
|
||||
{
|
||||
_texture->setTextureSize(_textureSize[0], _textureSize[1]);
|
||||
_camera->setViewport(0,0,_textureSize[0], _textureSize[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SoftShadowMap::init()
|
||||
{
|
||||
if (!_shadowedScene) return;
|
||||
|
||||
unsigned int tex_width = 1024;
|
||||
unsigned int tex_height = 1024;
|
||||
|
||||
_texture = new osg::Texture2D;
|
||||
_texture->setTextureSize(tex_width, tex_height);
|
||||
_texture->setTextureSize(_textureSize[0], _textureSize[1]);
|
||||
_texture->setInternalFormat(GL_DEPTH_COMPONENT);
|
||||
_texture->setSourceType(GL_UNSIGNED_INT);
|
||||
|
||||
@ -228,7 +240,7 @@ void SoftShadowMap::init()
|
||||
_camera->setComputeNearFarMode(osg::Camera::DO_NOT_COMPUTE_NEAR_FAR);
|
||||
|
||||
// set viewport
|
||||
_camera->setViewport(0,0,tex_width,tex_height);
|
||||
_camera->setViewport(0,0,_textureSize[0],_textureSize[1]);
|
||||
|
||||
// set the camera to render before the main camera.
|
||||
_camera->setRenderOrder(osg::Camera::PRE_RENDER);
|
||||
@ -410,7 +422,7 @@ void SoftShadowMap::cull(osgUtil::CullVisitor& cv)
|
||||
osg::Matrix MVPT = _camera->getViewMatrix() *
|
||||
_camera->getProjectionMatrix() *
|
||||
osg::Matrix::translate(1.0,1.0,1.0) *
|
||||
osg::Matrix::scale(0.5f,0.5f,0.5f);
|
||||
osg::Matrix::scale(0.5,0.5,0.5+_bias);
|
||||
|
||||
_texgen->setMode(osg::TexGen::EYE_LINEAR);
|
||||
_texgen->setPlanesFromMatrix(MVPT);
|
||||
|
Loading…
Reference in New Issue
Block a user