From bbf4564103ba5fa31cab2aa5ed6ccf8cf9f3092a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 19 Mar 2008 12:09:20 +0000 Subject: [PATCH] From Sebastian Messerschimdt, Added polygon offset controls --- include/osgShadow/ShadowMap | 7 +++++++ src/osgShadow/ShadowMap.cpp | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/osgShadow/ShadowMap b/include/osgShadow/ShadowMap index ef5dd49bd..5400998ac 100644 --- a/include/osgShadow/ShadowMap +++ b/include/osgShadow/ShadowMap @@ -39,6 +39,12 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique /** Get the texture unit that the shadow texture will be applied on.*/ 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.*/ void setAmbientBias(const osg::Vec2& ambientBias ); @@ -103,6 +109,7 @@ class OSGSHADOW_EXPORT ShadowMap : public ShadowTechnique ShaderList _shaderList; unsigned int _baseTextureUnit; unsigned int _shadowTextureUnit; + osg::Vec2 _polyOffset; osg::Vec2 _ambientBias; osg::Vec2s _textureSize; diff --git a/src/osgShadow/ShadowMap.cpp b/src/osgShadow/ShadowMap.cpp index fe1796b71..6ad8719b3 100644 --- a/src/osgShadow/ShadowMap.cpp +++ b/src/osgShadow/ShadowMap.cpp @@ -81,10 +81,11 @@ static const char fragmentShaderSource_debugHUD[] = "} \n"; ShadowMap::ShadowMap(): -_baseTextureUnit(0), + _baseTextureUnit(0), _shadowTextureUnit(1), _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; } +void ShadowMap::setPolygonOffset(const osg::Vec2& polyOffset) +{ + _polyOffset = polyOffset; +} + void ShadowMap::setAmbientBias(const osg::Vec2& ambientBias) { _ambientBias = ambientBias; @@ -209,6 +215,7 @@ void ShadowMap::init() #if 1 // cull front faces so that only backfaces contribute to depth map + osg::ref_ptr cull_face = new osg::CullFace; cull_face->setMode(osg::CullFace::FRONT); @@ -217,8 +224,8 @@ void ShadowMap::init() // negative polygonoffset - move the backface nearer to the eye point so that backfaces // shadow themselves - float factor = -1.0f; - float units = -1.0f; + float factor = -_polyOffset[0]; + float units = -_polyOffset[1]; osg::ref_ptr polygon_offset = new osg::PolygonOffset; polygon_offset->setFactor(factor); @@ -231,8 +238,8 @@ void ShadowMap::init() // negative polygonoffset - move the backface nearer to the eye point // so that front faces do not shadow themselves. - float factor = 1.0f; - float units = 1.0f; + float factor = _polyOffset[0]; + float units = _polyOffset[1]; osg::ref_ptr polygon_offset = new osg::PolygonOffset; polygon_offset->setFactor(factor); @@ -327,7 +334,7 @@ void ShadowMap::cull(osgUtil::CullVisitor& cv) 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()); @@ -607,7 +614,6 @@ osg::ref_ptr ShadowMap::makeDebugHUD() stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 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); // test with regular texture