1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-19 15:09:43 +00:00

Use polygon offset to render navmesh and recast mesh

This commit is contained in:
elsid 2021-11-01 21:52:33 +01:00
parent 0511a81baa
commit d1a1b8c01c
No known key found for this signature in database
GPG key ID: B845CB9FEE18AB40
2 changed files with 20 additions and 2 deletions

View file

@ -1,5 +1,6 @@
#include "navmesh.hpp"
#include "detourdebugdraw.hpp"
#include "depth.hpp"
#include <components/detournavigator/settings.hpp>
@ -7,6 +8,7 @@
#include <osg/Group>
#include <osg/Material>
#include <osg/PolygonOffset>
namespace
{
@ -241,7 +243,14 @@ namespace SceneUtil
osg::ref_ptr<osg::Material> 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<osg::PolygonOffset> polygonOffset = new osg::PolygonOffset(polygonOffsetFactor, polygonOffsetUnits);
osg::ref_ptr<osg::StateSet> stateSet = group->getOrCreateStateSet();
stateSet->setAttribute(material);
stateSet->setAttributeAndModes(polygonOffset);
return group;
}

View file

@ -1,5 +1,6 @@
#include "recastmesh.hpp"
#include "detourdebugdraw.hpp"
#include "depth.hpp"
#include <components/detournavigator/settings.hpp>
#include <components/detournavigator/recastmesh.hpp>
@ -9,6 +10,7 @@
#include <osg/Group>
#include <osg/Material>
#include <osg/PolygonOffset>
#include <algorithm>
#include <vector>
@ -69,7 +71,14 @@ namespace SceneUtil
osg::ref_ptr<osg::Material> 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<osg::PolygonOffset> polygonOffset = new osg::PolygonOffset(polygonOffsetFactor, polygonOffsetUnits);
osg::ref_ptr<osg::StateSet> stateSet = group->getOrCreateStateSet();
stateSet->setAttribute(material);
stateSet->setAttributeAndModes(polygonOffset);
return group;
}