1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 21:09:42 +00:00

Merge branch 'enable_normals_for_all' into 'master'

Restructure colormasks at higher level

See merge request OpenMW/openmw!3970
This commit is contained in:
jvoisin 2024-03-23 21:56:30 +00:00
commit 79a62b3ad3
7 changed files with 17 additions and 15 deletions

View file

@ -5,7 +5,6 @@
#include <limits> #include <limits>
#include <osg/BlendFunc> #include <osg/BlendFunc>
#include <osg/ColorMaski>
#include <osg/LightModel> #include <osg/LightModel>
#include <osg/Material> #include <osg/Material>
#include <osg/MatrixTransform> #include <osg/MatrixTransform>
@ -1594,8 +1593,7 @@ namespace MWRender
// Morrowind has a white ambient light attached to the root VFX node of the scenegraph // Morrowind has a white ambient light attached to the root VFX node of the scenegraph
node->getOrCreateStateSet()->setAttributeAndModes( node->getOrCreateStateSet()->setAttributeAndModes(
getVFXLightModelInstance(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); getVFXLightModelInstance(), osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
if (mResourceSystem->getSceneManager()->getSupportsNormalsRT()) mResourceSystem->getSceneManager()->setUpNormalsRTForStateSet(node->getOrCreateStateSet(), false);
node->getOrCreateStateSet()->setAttribute(new osg::ColorMaski(1, false, false, false, false));
SceneUtil::FindMaxControllerLengthVisitor findMaxLengthVisitor; SceneUtil::FindMaxControllerLengthVisitor findMaxLengthVisitor;
node->accept(findMaxLengthVisitor); node->accept(findMaxLengthVisitor);

View file

@ -312,9 +312,8 @@ namespace MWRender
class DepthClearCallback : public osgUtil::RenderBin::DrawCallback class DepthClearCallback : public osgUtil::RenderBin::DrawCallback
{ {
public: public:
DepthClearCallback(Resource::ResourceSystem* resourceSystem) DepthClearCallback()
{ {
mPassNormals = resourceSystem->getSceneManager()->getSupportsNormalsRT();
mDepth = new SceneUtil::AutoDepth; mDepth = new SceneUtil::AutoDepth;
mDepth->setWriteMask(true); mDepth->setWriteMask(true);
@ -335,11 +334,6 @@ namespace MWRender
unsigned int frameId = state->getFrameStamp()->getFrameNumber() % 2; unsigned int frameId = state->getFrameStamp()->getFrameNumber() % 2;
postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId)->apply(*state); postProcessor->getFbo(PostProcessor::FBO_FirstPerson, frameId)->apply(*state);
if (mPassNormals)
{
state->get<osg::GLExtensions>()->glColorMaski(1, true, true, true, true);
state->haveAppliedAttribute(osg::StateAttribute::COLORMASK);
}
glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// color accumulation pass // color accumulation pass
bin->drawImplementation(renderInfo, previous); bin->drawImplementation(renderInfo, previous);
@ -360,7 +354,6 @@ namespace MWRender
state->checkGLErrors("after DepthClearCallback::drawImplementation"); state->checkGLErrors("after DepthClearCallback::drawImplementation");
} }
bool mPassNormals;
osg::ref_ptr<osg::Depth> mDepth; osg::ref_ptr<osg::Depth> mDepth;
osg::ref_ptr<osg::StateSet> mStateSet; osg::ref_ptr<osg::StateSet> mStateSet;
}; };
@ -409,7 +402,7 @@ namespace MWRender
if (!prototypeAdded) if (!prototypeAdded)
{ {
osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin); osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin);
depthClearBin->setDrawCallback(new DepthClearCallback(mResourceSystem)); depthClearBin->setDrawCallback(new DepthClearCallback());
osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin); osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin);
prototypeAdded = true; prototypeAdded = true;
} }

View file

@ -550,6 +550,8 @@ namespace MWRender
sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f)); sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("specStrength", 1.f));
sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("distortionStrength", 0.f)); sceneRoot->getOrCreateStateSet()->addUniform(new osg::Uniform("distortionStrength", 0.f));
resourceSystem->getSceneManager()->setUpNormalsRTForStateSet(sceneRoot->getOrCreateStateSet(), true);
mFog = std::make_unique<FogManager>(); mFog = std::make_unique<FogManager>();
mSky = std::make_unique<SkyManager>( mSky = std::make_unique<SkyManager>(

View file

@ -274,6 +274,7 @@ namespace MWRender
if (!mSceneManager->getForceShaders()) if (!mSceneManager->getForceShaders())
skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(), skyroot->getOrCreateStateSet()->setAttributeAndModes(new osg::Program(),
osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON); osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED | osg::StateAttribute::ON);
mSceneManager->setUpNormalsRTForStateSet(skyroot->getOrCreateStateSet(), false);
SceneUtil::ShadowManager::instance().disableShadowsForStateSet(*skyroot->getOrCreateStateSet()); SceneUtil::ShadowManager::instance().disableShadowsForStateSet(*skyroot->getOrCreateStateSet());
parentNode->addChild(skyroot); parentNode->addChild(skyroot);

View file

@ -6,7 +6,6 @@
#include <osg/AlphaFunc> #include <osg/AlphaFunc>
#include <osg/BlendFunc> #include <osg/BlendFunc>
#include <osg/ColorMask> #include <osg/ColorMask>
#include <osg/ColorMaski>
#include <osg/Depth> #include <osg/Depth>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Material> #include <osg/Material>
@ -794,8 +793,7 @@ namespace MWRender
// Disable writing to the color buffer. We are using this geometry for visibility tests only. // Disable writing to the color buffer. We are using this geometry for visibility tests only.
osg::ref_ptr<osg::ColorMask> colormask = new osg::ColorMask(0, 0, 0, 0); osg::ref_ptr<osg::ColorMask> colormask = new osg::ColorMask(0, 0, 0, 0);
stateset->setAttributeAndModes(colormask); stateset->setAttributeAndModes(colormask);
if (sceneManager.getSupportsNormalsRT()) sceneManager.setUpNormalsRTForStateSet(stateset, false);
stateset->setAttributeAndModes(new osg::ColorMaski(1, false, false, false, false));
mTransform->addChild(queryNode); mTransform->addChild(queryNode);
mOcclusionQueryVisiblePixels = createOcclusionQueryNode(queryNode, true); mOcclusionQueryVisiblePixels = createOcclusionQueryNode(queryNode, true);

View file

@ -4,6 +4,7 @@
#include <filesystem> #include <filesystem>
#include <osg/AlphaFunc> #include <osg/AlphaFunc>
#include <osg/ColorMaski>
#include <osg/Group> #include <osg/Group>
#include <osg/Node> #include <osg/Node>
#include <osg/UserDataContainer> #include <osg/UserDataContainer>
@ -511,6 +512,13 @@ namespace Resource
return mCache->checkInObjectCache(VFS::Path::normalizeFilename(name), timeStamp); return mCache->checkInObjectCache(VFS::Path::normalizeFilename(name), timeStamp);
} }
void SceneManager::setUpNormalsRTForStateSet(osg::StateSet* stateset, bool enabled)
{
if (!getSupportsNormalsRT())
return;
stateset->setAttributeAndModes(new osg::ColorMaski(1, enabled, enabled, enabled, enabled));
}
/// @brief Callback to read image files from the VFS. /// @brief Callback to read image files from the VFS.
class ImageReadCallback : public osgDB::ReadFileCallback class ImageReadCallback : public osgDB::ReadFileCallback
{ {

View file

@ -224,6 +224,8 @@ namespace Resource
void setSupportsNormalsRT(bool supports) { mSupportsNormalsRT = supports; } void setSupportsNormalsRT(bool supports) { mSupportsNormalsRT = supports; }
bool getSupportsNormalsRT() const { return mSupportsNormalsRT; } bool getSupportsNormalsRT() const { return mSupportsNormalsRT; }
void setUpNormalsRTForStateSet(osg::StateSet* stateset, bool enabled);
void setSoftParticles(bool enabled) { mSoftParticles = enabled; } void setSoftParticles(bool enabled) { mSoftParticles = enabled; }
bool getSoftParticles() const { return mSoftParticles; } bool getSoftParticles() const { return mSoftParticles; }