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

Restructure colormasks at higher level

This commit is contained in:
Cody Glassman 2024-03-23 21:56:30 +00:00 committed by jvoisin
parent 82bc6674dc
commit a4dd9224df
7 changed files with 17 additions and 15 deletions

View file

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

View file

@ -312,9 +312,8 @@ namespace MWRender
class DepthClearCallback : public osgUtil::RenderBin::DrawCallback
{
public:
DepthClearCallback(Resource::ResourceSystem* resourceSystem)
DepthClearCallback()
{
mPassNormals = resourceSystem->getSceneManager()->getSupportsNormalsRT();
mDepth = new SceneUtil::AutoDepth;
mDepth->setWriteMask(true);
@ -335,11 +334,6 @@ namespace MWRender
unsigned int frameId = state->getFrameStamp()->getFrameNumber() % 2;
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);
// color accumulation pass
bin->drawImplementation(renderInfo, previous);
@ -360,7 +354,6 @@ namespace MWRender
state->checkGLErrors("after DepthClearCallback::drawImplementation");
}
bool mPassNormals;
osg::ref_ptr<osg::Depth> mDepth;
osg::ref_ptr<osg::StateSet> mStateSet;
};
@ -409,7 +402,7 @@ namespace MWRender
if (!prototypeAdded)
{
osg::ref_ptr<osgUtil::RenderBin> depthClearBin(new osgUtil::RenderBin);
depthClearBin->setDrawCallback(new DepthClearCallback(mResourceSystem));
depthClearBin->setDrawCallback(new DepthClearCallback());
osgUtil::RenderBin::addRenderBinPrototype("DepthClear", depthClearBin);
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("distortionStrength", 0.f));
resourceSystem->getSceneManager()->setUpNormalsRTForStateSet(sceneRoot->getOrCreateStateSet(), true);
mFog = std::make_unique<FogManager>();
mSky = std::make_unique<SkyManager>(

View file

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

View file

@ -6,7 +6,6 @@
#include <osg/AlphaFunc>
#include <osg/BlendFunc>
#include <osg/ColorMask>
#include <osg/ColorMaski>
#include <osg/Depth>
#include <osg/Geometry>
#include <osg/Material>
@ -794,8 +793,7 @@ namespace MWRender
// 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);
stateset->setAttributeAndModes(colormask);
if (sceneManager.getSupportsNormalsRT())
stateset->setAttributeAndModes(new osg::ColorMaski(1, false, false, false, false));
sceneManager.setUpNormalsRTForStateSet(stateset, false);
mTransform->addChild(queryNode);
mOcclusionQueryVisiblePixels = createOcclusionQueryNode(queryNode, true);

View file

@ -4,6 +4,7 @@
#include <filesystem>
#include <osg/AlphaFunc>
#include <osg/ColorMaski>
#include <osg/Group>
#include <osg/Node>
#include <osg/UserDataContainer>
@ -511,6 +512,13 @@ namespace Resource
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.
class ImageReadCallback : public osgDB::ReadFileCallback
{

View file

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