1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:23:52 +00:00

Fix VR gui material.

This commit is contained in:
madsbuvi 2021-02-07 19:18:07 +01:00
parent 66d2912fcd
commit 00d6dc3a86
2 changed files with 54 additions and 29 deletions

View file

@ -216,22 +216,10 @@ namespace MWVR
auto texture = menuTexture(); auto texture = menuTexture();
texture->setName("diffuseMap"); texture->setName("diffuseMap");
stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); 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<osg::Fog> fog(new osg::Fog);
fog->setStart(10000000);
fog->setEnd(10000000);
stateSet->setAttributeAndModes(fog, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel; osg::ref_ptr<osg::Material> mat = new osg::Material;
lightmodel->setAmbientIntensity(osg::Vec4(1.0, 1.0, 1.0, 1.0)); mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
stateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); stateSet->setAttribute(mat);
SceneUtil::ShadowManager::disableShadowsForStateSet(stateSet);
mGeometry->setStateSet(stateSet);
// Position in the game world // Position in the game world
mTransform->setScale(osg::Vec3(extent_units.x(), 1.f, extent_units.y())); 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 gLeftHudOffsetTop = osg::Vec3(0.025f, -.05f, .066f);
static osg::Vec3 gLeftHudOffsetWrist = osg::Vec3(0.025f, -.090f, -.033f); 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( VRGUIManager::VRGUIManager(
osg::ref_ptr<osgViewer::Viewer> viewer, osg::ref_ptr<osgViewer::Viewer> viewer,
Resource::ResourceSystem* resourceSystem, Resource::ResourceSystem* resourceSystem,
osg::Group* rootNode) osg::Group* rootNode)
: mOsgViewer(viewer) : mOsgViewer(viewer)
, mResourceSystem(resourceSystem) , mResourceSystem(resourceSystem)
, mRootNode(rootNode) , mGeometriesRootNode(rootNode)
, mGUICamerasRootNode(rootNode)
{ {
mGUIGeometriesRoot->setName("VR GUI Geometry Root"); mGeometries->setName("VR GUI Geometry Root");
mGUIGeometriesRoot->setUpdateCallback(new VRGUIManagerUpdateCallback(this)); mGeometries->setUpdateCallback(new VRGUIManagerUpdateCallback(this));
mGUIGeometriesRoot->setNodeMask(MWRender::VisMask::Mask_3DGUI); mGeometries->setNodeMask(MWRender::VisMask::Mask_3DGUI);
mGUICamerasRoot->setName("VR GUI Cameras Root"); mGeometriesRootNode->addChild(mGeometries);
mGUICamerasRoot->setNodeMask(MWRender::VisMask::Mask_3DGUI);
mRootNode->asGroup()->addChild(mGUICamerasRoot); auto stateSet = mGeometries->getOrCreateStateSet();
mRootNode->asGroup()->addChild(mGUIGeometriesRoot); stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
mGUIGeometriesRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); 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<osg::Fog> fog(new osg::Fog);
fog->setStart(10000000);
fog->setEnd(10000000);
stateSet->setAttributeAndModes(fog, osg::StateAttribute::OFF);
osg::ref_ptr<osg::LightModel> 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 defaultConfig = createDefaultConfig(1);
LayerConfig loadingScreenConfig = createDefaultConfig(1, true, SizingMode::Fixed, "Menu"); LayerConfig loadingScreenConfig = createDefaultConfig(1, true, SizingMode::Fixed, "Menu");
@ -654,8 +675,8 @@ namespace MWVR
} }
auto layer = std::shared_ptr<VRGUILayer>(new VRGUILayer( auto layer = std::shared_ptr<VRGUILayer>(new VRGUILayer(
mGUIGeometriesRoot, mGeometries,
mGUICamerasRoot, mGUICameras,
name, name,
config, config,
this this

View file

@ -179,6 +179,9 @@ namespace MWVR
static void setPick(MWGui::Layout* widget, bool pick); static void setPick(MWGui::Layout* widget, bool pick);
void setGeometryRoot(osg::Group* root);
void setCameraRoot(osg::Group* root);
private: private:
void computeGuiCursor(osg::Vec3 hitPoint); void computeGuiCursor(osg::Vec3 hitPoint);
void updateSideBySideLayers(); void updateSideBySideLayers();
@ -191,9 +194,10 @@ namespace MWVR
osg::ref_ptr<osgViewer::Viewer> mOsgViewer{ nullptr }; osg::ref_ptr<osgViewer::Viewer> mOsgViewer{ nullptr };
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
osg::ref_ptr<osg::Group> mRootNode{ nullptr }; osg::ref_ptr<osg::Group> mGeometriesRootNode{ nullptr };
osg::ref_ptr<osg::Group> mGUIGeometriesRoot{ new osg::Group }; osg::ref_ptr<osg::Group> mGeometries{ new osg::Group };
osg::ref_ptr<osg::Group> mGUICamerasRoot{ new osg::Group }; osg::ref_ptr<osg::Group> mGUICamerasRootNode{ nullptr };
osg::ref_ptr<osg::Group> mGUICameras{ new osg::Group };
std::map<std::string, std::shared_ptr<VRGUILayer>> mLayers; std::map<std::string, std::shared_ptr<VRGUILayer>> mLayers;
std::vector<std::shared_ptr<VRGUILayer> > mSideBySideLayers; std::vector<std::shared_ptr<VRGUILayer> > mSideBySideLayers;