1
0
Fork 0

VR: Visibility mask support

Update osgXR to 0.3.3 which provides support for visibility masks using
the depth buffer, and extend VRManager to support them.

The following properties are added:
 - /sim/vr/openxr/extensions/visibility-mask: This exposes whether
   visibility masks are supported by the current OpenXR runtime, and
   maps to osgXR::Manager::hasVisibilityMaskExtension().
 - /sim/vr/visibility-mask: This allows visibility masks to be enabled
   and disabled, and maps to osgXR::Settings::setVisibilityMask() via a
   listener.

Finally we inform osgXR that it should use SimGear's newly defined
LEFT_BIT and RIGHT_BIT NodeMask bits for the visibility masks using
osgXR::Manager::setVisibilityMaskNodeMasks(). This allows a single
stereo camera to have a visibility mask for each eye.
This commit is contained in:
James Hogan 2021-09-17 18:30:56 +01:00
parent cf4801e11c
commit bad7047c36
No known key found for this signature in database
GPG key ID: 35CEE4862B1023F2
3 changed files with 21 additions and 1 deletions

View file

@ -152,7 +152,7 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR
set(SYSTEM_HTS_ENGINE_DEFAULT 1) set(SYSTEM_HTS_ENGINE_DEFAULT 1)
endif() endif()
find_package(osgXR 0.3) find_package(osgXR 0.3.3)
if (osgXR_FOUND) if (osgXR_FOUND)
set(ENABLE_OSGXR_DEFAULT 1) set(ENABLE_OSGXR_DEFAULT 1)
endif() endif()

View file

@ -20,6 +20,7 @@
#include <osgXR/Settings> #include <osgXR/Settings>
#include <simgear/scene/util/RenderConstants.hxx>
#include <simgear/scene/viewer/CompositorPass.hxx> #include <simgear/scene/viewer/CompositorPass.hxx>
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
@ -32,6 +33,7 @@ VRManager::VRManager() :
_reloadCompositorCallback(new ReloadCompositorCallback(this)), _reloadCompositorCallback(new ReloadCompositorCallback(this)),
_propXrLayersValidation("/sim/vr/openxr/layers/validation"), _propXrLayersValidation("/sim/vr/openxr/layers/validation"),
_propXrExtensionsDepthInfo("/sim/vr/openxr/extensions/depth-info"), _propXrExtensionsDepthInfo("/sim/vr/openxr/extensions/depth-info"),
_propXrExtensionsVisibilityMask("/sim/vr/openxr/extensions/visibility-mask"),
_propXrRuntimeName("/sim/vr/openxr/runtime/name"), _propXrRuntimeName("/sim/vr/openxr/runtime/name"),
_propXrSystemName("/sim/vr/openxr/system/name"), _propXrSystemName("/sim/vr/openxr/system/name"),
_propStateString("/sim/vr/state-string"), _propStateString("/sim/vr/state-string"),
@ -39,6 +41,7 @@ VRManager::VRManager() :
_propRunning("/sim/vr/running"), _propRunning("/sim/vr/running"),
_propEnabled("/sim/vr/enabled"), _propEnabled("/sim/vr/enabled"),
_propDepthInfo("/sim/vr/depth-info"), _propDepthInfo("/sim/vr/depth-info"),
_propVisibilityMask("/sim/vr/visibility-mask"),
_propValidationLayer("/sim/vr/validation-layer"), _propValidationLayer("/sim/vr/validation-layer"),
_propMode("/sim/vr/mode"), _propMode("/sim/vr/mode"),
_propSwapchainMode("/sim/vr/swapchain-mode"), _propSwapchainMode("/sim/vr/swapchain-mode"),
@ -46,6 +49,7 @@ VRManager::VRManager() :
_propMirrorMode("/sim/vr/mirror-mode"), _propMirrorMode("/sim/vr/mirror-mode"),
_listenerEnabled(this, &osgXR::Manager::setEnabled), _listenerEnabled(this, &osgXR::Manager::setEnabled),
_listenerDepthInfo(this, &VRManager::setDepthInfo), _listenerDepthInfo(this, &VRManager::setDepthInfo),
_listenerVisibilityMask(this, &VRManager::setVisibilityMask),
_listenerValidationLayer(this, &VRManager::setValidationLayer), _listenerValidationLayer(this, &VRManager::setValidationLayer),
_listenerMode(this, &VRManager::setVRMode), _listenerMode(this, &VRManager::setVRMode),
_listenerSwapchainMode(this, &VRManager::setSwapchainMode), _listenerSwapchainMode(this, &VRManager::setSwapchainMode),
@ -57,6 +61,10 @@ VRManager::VRManager() :
_settings->setApp("FlightGear", fgVersion); _settings->setApp("FlightGear", fgVersion);
_settings->preferEnvBlendMode(osgXR::Settings::OPAQUE); _settings->preferEnvBlendMode(osgXR::Settings::OPAQUE);
// Inform osgXR what node masks to use
setVisibilityMaskNodeMasks(simgear::NodeMask::LEFT_BIT,
simgear::NodeMask::RIGHT_BIT);
// Hook into viewer, but don't enable VR just yet // Hook into viewer, but don't enable VR just yet
osgViewer::View *view = globals->get_renderer()->getView(); osgViewer::View *view = globals->get_renderer()->getView();
if (view) { if (view) {
@ -68,6 +76,7 @@ VRManager::VRManager() :
_propEnabled.node(true)->addChangeListener(&_listenerEnabled, true); _propEnabled.node(true)->addChangeListener(&_listenerEnabled, true);
_propDepthInfo.node(true)->addChangeListener(&_listenerDepthInfo, true); _propDepthInfo.node(true)->addChangeListener(&_listenerDepthInfo, true);
_propVisibilityMask.node(true)->addChangeListener(&_listenerVisibilityMask, true);
_propValidationLayer.node(true)->addChangeListener(&_listenerValidationLayer, true); _propValidationLayer.node(true)->addChangeListener(&_listenerValidationLayer, true);
_propMode.node(true)->addChangeListener(&_listenerMode, true); _propMode.node(true)->addChangeListener(&_listenerMode, true);
_propSwapchainMode.node(true)->addChangeListener(&_listenerSwapchainMode, true); _propSwapchainMode.node(true)->addChangeListener(&_listenerSwapchainMode, true);
@ -96,6 +105,7 @@ void VRManager::syncReadOnlyProperties()
{ {
_propXrLayersValidation = hasValidationLayer(); _propXrLayersValidation = hasValidationLayer();
_propXrExtensionsDepthInfo = hasDepthInfoExtension(); _propXrExtensionsDepthInfo = hasDepthInfoExtension();
_propXrExtensionsVisibilityMask = hasVisibilityMaskExtension();
_propXrRuntimeName = getRuntimeName(); _propXrRuntimeName = getRuntimeName();
_propXrSystemName = getSystemName(); _propXrSystemName = getSystemName();
@ -128,6 +138,12 @@ void VRManager::setDepthInfo(bool depthInfo)
syncSettings(); syncSettings();
} }
void VRManager::setVisibilityMask(bool visibilityMask)
{
_settings->setVisibilityMask(visibilityMask);
syncSettings();
}
void VRManager::setVRMode(const char * mode) void VRManager::setVRMode(const char * mode)
{ {
osgXR::Settings::VRMode vrMode = osgXR::Settings::VRMODE_AUTOMATIC; osgXR::Settings::VRMode vrMode = osgXR::Settings::VRMODE_AUTOMATIC;

View file

@ -78,6 +78,7 @@ class VRManager : public osgXR::Manager
void setValidationLayer(bool validationLayer); void setValidationLayer(bool validationLayer);
void setDepthInfo(bool depthInfo); void setDepthInfo(bool depthInfo);
void setVisibilityMask(bool visibilityMask);
void setVRMode(const char * mode); void setVRMode(const char * mode);
void setSwapchainMode(const char * mode); void setSwapchainMode(const char * mode);
@ -110,6 +111,7 @@ class VRManager : public osgXR::Manager
SGPropObjBool _propXrLayersValidation; SGPropObjBool _propXrLayersValidation;
SGPropObjBool _propXrExtensionsDepthInfo; SGPropObjBool _propXrExtensionsDepthInfo;
SGPropObjBool _propXrExtensionsVisibilityMask;
SGPropObjString _propXrRuntimeName; SGPropObjString _propXrRuntimeName;
SGPropObjString _propXrSystemName; SGPropObjString _propXrSystemName;
@ -119,6 +121,7 @@ class VRManager : public osgXR::Manager
SGPropObjBool _propEnabled; SGPropObjBool _propEnabled;
SGPropObjBool _propDepthInfo; SGPropObjBool _propDepthInfo;
SGPropObjBool _propVisibilityMask;
SGPropObjBool _propValidationLayer; SGPropObjBool _propValidationLayer;
SGPropObjString _propMode; SGPropObjString _propMode;
SGPropObjString _propSwapchainMode; SGPropObjString _propSwapchainMode;
@ -154,6 +157,7 @@ class VRManager : public osgXR::Manager
ListenerBool _listenerEnabled; ListenerBool _listenerEnabled;
ListenerBool _listenerDepthInfo; ListenerBool _listenerDepthInfo;
ListenerBool _listenerVisibilityMask;
ListenerBool _listenerValidationLayer; ListenerBool _listenerValidationLayer;
ListenerString _listenerMode; ListenerString _listenerMode;
ListenerString _listenerSwapchainMode; ListenerString _listenerSwapchainMode;