Sky dome: Enable depth test but mask depth changes

On VR with visibility masking the depth buffer is first set to the
nearest possible value in parts of the frame that won't be visible
through the VR headset's lenses. This is meant to reduce GPU fragment
load.

The sky dome however is rendered with depth testing disabled which
bypasses the visibility masking. To allow invisible parts of the sky
dome to be culled, enable depth testing but set the depth mask to false
to prevent modification of the depth buffer.
This commit is contained in:
James Hogan 2021-10-08 19:55:57 +01:00
parent f7e378a05a
commit 0c4c092b9f
No known key found for this signature in database
GPG Key ID: 35CEE4862B1023F2

View File

@ -29,6 +29,7 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <osg/Array> #include <osg/Array>
#include <osg/Depth>
#include <osg/Geode> #include <osg/Geode>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Node> #include <osg/Node>
@ -143,11 +144,12 @@ SGSkyDome::build( double hscale, double vscale, simgear::SGReaderWriterOptions *
stateSet->setAttributeAndModes(shadeModel); stateSet->setAttributeAndModes(shadeModel);
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateSet->setMode(GL_FOG, osg::StateAttribute::OFF); stateSet->setMode(GL_FOG, osg::StateAttribute::OFF);
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON); stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF); stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF);
stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
stateSet->setAttribute(new osg::Depth(osg::Depth::LESS, 0, 1, false));
stateSet->setAttribute(new osg::CullFace(osg::CullFace::BACK)); stateSet->setAttribute(new osg::CullFace(osg::CullFace::BACK));
osg::Material* material = new osg::Material; osg::Material* material = new osg::Material;