diff --git a/components/sceneutil/navmesh.cpp b/components/sceneutil/navmesh.cpp index 891f1350a1..3f91d41d51 100644 --- a/components/sceneutil/navmesh.cpp +++ b/components/sceneutil/navmesh.cpp @@ -1,5 +1,6 @@ #include "navmesh.hpp" #include "detourdebugdraw.hpp" +#include "depth.hpp" #include @@ -7,6 +8,7 @@ #include #include +#include namespace { @@ -241,7 +243,14 @@ namespace SceneUtil osg::ref_ptr material = new osg::Material; material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - group->getOrCreateStateSet()->setAttribute(material); + + const float polygonOffsetFactor = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; + const float polygonOffsetUnits = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; + osg::ref_ptr polygonOffset = new osg::PolygonOffset(polygonOffsetFactor, polygonOffsetUnits); + + osg::ref_ptr stateSet = group->getOrCreateStateSet(); + stateSet->setAttribute(material); + stateSet->setAttributeAndModes(polygonOffset); return group; } diff --git a/components/sceneutil/recastmesh.cpp b/components/sceneutil/recastmesh.cpp index 5732f86959..ed40bfedf7 100644 --- a/components/sceneutil/recastmesh.cpp +++ b/components/sceneutil/recastmesh.cpp @@ -1,5 +1,6 @@ #include "recastmesh.hpp" #include "detourdebugdraw.hpp" +#include "depth.hpp" #include #include @@ -9,6 +10,7 @@ #include #include +#include #include #include @@ -69,7 +71,14 @@ namespace SceneUtil osg::ref_ptr material = new osg::Material; material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - group->getOrCreateStateSet()->setAttribute(material); + + const float polygonOffsetFactor = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; + const float polygonOffsetUnits = SceneUtil::AutoDepth::isReversed() ? 1.0 : -1.0; + osg::ref_ptr polygonOffset = new osg::PolygonOffset(polygonOffsetFactor, polygonOffsetUnits); + + osg::ref_ptr stateSet = group->getOrCreateStateSet(); + stateSet->setAttribute(material); + stateSet->setAttributeAndModes(polygonOffset); return group; }