From Sebastian Messerschimdt, Added polygon offset controls

This commit is contained in:
Robert Osfield 2008-03-19 12:09:20 +00:00
parent 5746c4ce89
commit bbf4564103
2 changed files with 21 additions and 8 deletions

View File

@ -39,6 +39,12 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique
/** Get the texture unit that the shadow texture will be applied on.*/ /** Get the texture unit that the shadow texture will be applied on.*/
unsigned int getTextureUnit() const { return _shadowTextureUnit; } unsigned int getTextureUnit() const { return _shadowTextureUnit; }
/** set the polygon offset used initially */
void setPolygonOffset(const osg::Vec2& polyOffset);
/** get the used polygon offset */
const osg::Vec2& getPolygonOffset() const { return _polyOffset; }
/** Set the values for the ambient bias the shader will use.*/ /** Set the values for the ambient bias the shader will use.*/
void setAmbientBias(const osg::Vec2& ambientBias ); void setAmbientBias(const osg::Vec2& ambientBias );
@ -103,6 +109,7 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique
ShaderList _shaderList; ShaderList _shaderList;
unsigned int _baseTextureUnit; unsigned int _baseTextureUnit;
unsigned int _shadowTextureUnit; unsigned int _shadowTextureUnit;
osg::Vec2 _polyOffset;
osg::Vec2 _ambientBias; osg::Vec2 _ambientBias;
osg::Vec2s _textureSize; osg::Vec2s _textureSize;

View File

@ -84,7 +84,8 @@ ShadowMap::ShadowMap():
_baseTextureUnit(0), _baseTextureUnit(0),
_shadowTextureUnit(1), _shadowTextureUnit(1),
_ambientBias(0.5f,0.5f), _ambientBias(0.5f,0.5f),
_textureSize(1024,1024) _textureSize(1024,1024),
_polyOffset(1.0,1.0)
{ {
} }
@ -102,6 +103,11 @@ void ShadowMap::setTextureUnit(unsigned int unit)
_shadowTextureUnit = unit; _shadowTextureUnit = unit;
} }
void ShadowMap::setPolygonOffset(const osg::Vec2& polyOffset)
{
_polyOffset = polyOffset;
}
void ShadowMap::setAmbientBias(const osg::Vec2& ambientBias) void ShadowMap::setAmbientBias(const osg::Vec2& ambientBias)
{ {
_ambientBias = ambientBias; _ambientBias = ambientBias;
@ -210,6 +216,7 @@ void ShadowMap::init()
#if 1 #if 1
// cull front faces so that only backfaces contribute to depth map // cull front faces so that only backfaces contribute to depth map
osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace; osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace;
cull_face->setMode(osg::CullFace::FRONT); cull_face->setMode(osg::CullFace::FRONT);
stateset->setAttribute(cull_face.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); stateset->setAttribute(cull_face.get(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
@ -217,8 +224,8 @@ void ShadowMap::init()
// negative polygonoffset - move the backface nearer to the eye point so that backfaces // negative polygonoffset - move the backface nearer to the eye point so that backfaces
// shadow themselves // shadow themselves
float factor = -1.0f; float factor = -_polyOffset[0];
float units = -1.0f; float units = -_polyOffset[1];
osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset; osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset;
polygon_offset->setFactor(factor); polygon_offset->setFactor(factor);
@ -231,8 +238,8 @@ void ShadowMap::init()
// negative polygonoffset - move the backface nearer to the eye point // negative polygonoffset - move the backface nearer to the eye point
// so that front faces do not shadow themselves. // so that front faces do not shadow themselves.
float factor = 1.0f; float factor = _polyOffset[0];
float units = 1.0f; float units = _polyOffset[1];
osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset; osg::ref_ptr<osg::PolygonOffset> polygon_offset = new osg::PolygonOffset;
polygon_offset->setFactor(factor); polygon_offset->setFactor(factor);
@ -327,7 +334,7 @@ void ShadowMap::cull(osgUtil::CullVisitor& cv)
osgUtil::RenderStage* orig_rs = cv.getRenderStage(); osgUtil::RenderStage* orig_rs = cv.getRenderStage();
// do traversal of shadow receiving scene which does need to be decorated by the shadow map // do traversal of shadow recieving scene which does need to be decorated by the shadow map
{ {
cv.pushStateSet(_stateset.get()); cv.pushStateSet(_stateset.get());
@ -607,7 +614,6 @@ osg::ref_ptr<osg::Camera> ShadowMap::makeDebugHUD()
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON);
//stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
// test with regular texture // test with regular texture