From 00d6dc3a86a03abbbe98872d04c100dfb4414e93 Mon Sep 17 00:00:00 2001 From: madsbuvi Date: Sun, 7 Feb 2021 19:18:07 +0100 Subject: [PATCH] Fix VR gui material. --- apps/openmw/mwvr/vrgui.cpp | 73 ++++++++++++++++++++++++-------------- apps/openmw/mwvr/vrgui.hpp | 10 ++++-- 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwvr/vrgui.cpp b/apps/openmw/mwvr/vrgui.cpp index 89759a6c1..640e9cb01 100644 --- a/apps/openmw/mwvr/vrgui.cpp +++ b/apps/openmw/mwvr/vrgui.cpp @@ -216,22 +216,10 @@ namespace MWVR auto texture = menuTexture(); texture->setName("diffuseMap"); stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); - stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - stateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - // assign large value to effectively turn off fog - // shaders don't respect glDisable(GL_FOG) - osg::ref_ptr fog(new osg::Fog); - fog->setStart(10000000); - fog->setEnd(10000000); - stateSet->setAttributeAndModes(fog, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE); - osg::ref_ptr lightmodel = new osg::LightModel; - lightmodel->setAmbientIntensity(osg::Vec4(1.0, 1.0, 1.0, 1.0)); - stateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); - SceneUtil::ShadowManager::disableShadowsForStateSet(stateSet); - - mGeometry->setStateSet(stateSet); + osg::ref_ptr mat = new osg::Material; + mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); + stateSet->setAttribute(mat); // Position in the game world mTransform->setScale(osg::Vec3(extent_units.x(), 1.f, extent_units.y())); @@ -502,22 +490,55 @@ namespace MWVR static osg::Vec3 gLeftHudOffsetTop = osg::Vec3(0.025f, -.05f, .066f); static osg::Vec3 gLeftHudOffsetWrist = osg::Vec3(0.025f, -.090f, -.033f); + void VRGUIManager::setGeometryRoot(osg::Group* root) + { + mGeometriesRootNode->removeChild(mGeometries); + mGeometriesRootNode = root; + mGeometriesRootNode->addChild(mGeometries); + } + + void VRGUIManager::setCameraRoot(osg::Group* root) + { + mGUICamerasRootNode->removeChild(mGUICameras); + mGUICamerasRootNode = root; + mGUICamerasRootNode->addChild(mGUICameras); + } + VRGUIManager::VRGUIManager( osg::ref_ptr viewer, Resource::ResourceSystem* resourceSystem, osg::Group* rootNode) : mOsgViewer(viewer) , mResourceSystem(resourceSystem) - , mRootNode(rootNode) + , mGeometriesRootNode(rootNode) + , mGUICamerasRootNode(rootNode) { - mGUIGeometriesRoot->setName("VR GUI Geometry Root"); - mGUIGeometriesRoot->setUpdateCallback(new VRGUIManagerUpdateCallback(this)); - mGUIGeometriesRoot->setNodeMask(MWRender::VisMask::Mask_3DGUI); - mGUICamerasRoot->setName("VR GUI Cameras Root"); - mGUICamerasRoot->setNodeMask(MWRender::VisMask::Mask_3DGUI); - mRootNode->asGroup()->addChild(mGUICamerasRoot); - mRootNode->asGroup()->addChild(mGUIGeometriesRoot); - mGUIGeometriesRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); + mGeometries->setName("VR GUI Geometry Root"); + mGeometries->setUpdateCallback(new VRGUIManagerUpdateCallback(this)); + mGeometries->setNodeMask(MWRender::VisMask::Mask_3DGUI); + mGeometriesRootNode->addChild(mGeometries); + + auto stateSet = mGeometries->getOrCreateStateSet(); + stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + stateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + stateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); + // assign large value to effectively turn off fog + // shaders don't respect glDisable(GL_FOG) + osg::ref_ptr fog(new osg::Fog); + fog->setStart(10000000); + fog->setEnd(10000000); + stateSet->setAttributeAndModes(fog, osg::StateAttribute::OFF); + + osg::ref_ptr lightmodel = new osg::LightModel; + lightmodel->setAmbientIntensity(osg::Vec4(1.0, 1.0, 1.0, 1.0)); + stateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON); + + SceneUtil::ShadowManager::disableShadowsForStateSet(stateSet); + mGeometries->setStateSet(stateSet); + + mGUICameras->setName("VR GUI Cameras Root"); + mGUICameras->setNodeMask(MWRender::VisMask::Mask_3DGUI); + mGUICamerasRootNode->addChild(mGUICameras); LayerConfig defaultConfig = createDefaultConfig(1); LayerConfig loadingScreenConfig = createDefaultConfig(1, true, SizingMode::Fixed, "Menu"); @@ -654,8 +675,8 @@ namespace MWVR } auto layer = std::shared_ptr(new VRGUILayer( - mGUIGeometriesRoot, - mGUICamerasRoot, + mGeometries, + mGUICameras, name, config, this diff --git a/apps/openmw/mwvr/vrgui.hpp b/apps/openmw/mwvr/vrgui.hpp index b804dc4c1..9e69514c8 100644 --- a/apps/openmw/mwvr/vrgui.hpp +++ b/apps/openmw/mwvr/vrgui.hpp @@ -179,6 +179,9 @@ namespace MWVR static void setPick(MWGui::Layout* widget, bool pick); + void setGeometryRoot(osg::Group* root); + void setCameraRoot(osg::Group* root); + private: void computeGuiCursor(osg::Vec3 hitPoint); void updateSideBySideLayers(); @@ -191,9 +194,10 @@ namespace MWVR osg::ref_ptr mOsgViewer{ nullptr }; Resource::ResourceSystem* mResourceSystem; - osg::ref_ptr mRootNode{ nullptr }; - osg::ref_ptr mGUIGeometriesRoot{ new osg::Group }; - osg::ref_ptr mGUICamerasRoot{ new osg::Group }; + osg::ref_ptr mGeometriesRootNode{ nullptr }; + osg::ref_ptr mGeometries{ new osg::Group }; + osg::ref_ptr mGUICamerasRootNode{ nullptr }; + osg::ref_ptr mGUICameras{ new osg::Group }; std::map> mLayers; std::vector > mSideBySideLayers;