From Sebastian Messerschimdt, Added polygon offset controls
This commit is contained in:
parent
5746c4ce89
commit
bbf4564103
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
@ -210,6 +216,7 @@ void ShadowMap::init()
|
||||
#if 1
|
||||
// cull front faces so that only backfaces contribute to depth map
|
||||
|
||||
|
||||
osg::ref_ptr<osg::CullFace> cull_face = new osg::CullFace;
|
||||
cull_face->setMode(osg::CullFace::FRONT);
|
||||
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
|
||||
// shadow themselves
|
||||
float factor = -1.0f;
|
||||
float units = -1.0f;
|
||||
float factor = -_polyOffset[0];
|
||||
float units = -_polyOffset[1];
|
||||
|
||||
osg::ref_ptr<osg::PolygonOffset> 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<osg::PolygonOffset> 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<osg::Camera> 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
|
||||
|
Loading…
Reference in New Issue
Block a user