1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 03:32:36 +00:00

Merge branch 'render_target_fixes' into 'master'

[Postprocessing] Fix dirty flag and share luminance calculator between frames

See merge request OpenMW/openmw!3566
This commit is contained in:
jvoisin 2023-11-08 22:50:51 +00:00
commit 9fb5fe26e6
3 changed files with 23 additions and 18 deletions

View File

@ -10,9 +10,11 @@
namespace MWRender namespace MWRender
{ {
PingPongCanvas::PingPongCanvas(Shader::ShaderManager& shaderManager) PingPongCanvas::PingPongCanvas(
Shader::ShaderManager& shaderManager, const std::shared_ptr<LuminanceCalculator>& luminanceCalculator)
: mFallbackStateSet(new osg::StateSet) : mFallbackStateSet(new osg::StateSet)
, mMultiviewResolveStateSet(new osg::StateSet) , mMultiviewResolveStateSet(new osg::StateSet)
, mLuminanceCalculator(luminanceCalculator)
{ {
setUseDisplayList(false); setUseDisplayList(false);
setUseVertexBufferObjects(true); setUseVertexBufferObjects(true);
@ -26,8 +28,7 @@ namespace MWRender
addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3)); addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3));
mLuminanceCalculator = LuminanceCalculator(shaderManager); mLuminanceCalculator->disable();
mLuminanceCalculator.disable();
Shader::ShaderManager::DefineMap defines; Shader::ShaderManager::DefineMap defines;
Stereo::shaderStereoDefines(defines); Stereo::shaderStereoDefines(defines);
@ -142,7 +143,7 @@ namespace MWRender
.getTexture()); .getTexture());
} }
mLuminanceCalculator.dirty(mTextureScene->getTextureWidth(), mTextureScene->getTextureHeight()); mLuminanceCalculator->dirty(mTextureScene->getTextureWidth(), mTextureScene->getTextureHeight());
if (Stereo::getStereo()) if (Stereo::getStereo())
mRenderViewport mRenderViewport
@ -158,11 +159,11 @@ namespace MWRender
{ GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT2_EXT }, { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT2_EXT },
{ GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT } } }; { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT } } };
(mAvgLum) ? mLuminanceCalculator.enable() : mLuminanceCalculator.disable(); (mAvgLum) ? mLuminanceCalculator->enable() : mLuminanceCalculator->disable();
// A histogram based approach is superior way to calculate scene luminance. Using mipmaps is more broadly // A histogram based approach is superior way to calculate scene luminance. Using mipmaps is more broadly
// supported, so that's what we use for now. // supported, so that's what we use for now.
mLuminanceCalculator.draw(*this, renderInfo, state, ext, frameId); mLuminanceCalculator->draw(*this, renderInfo, state, ext, frameId);
auto buffer = buffers[0]; auto buffer = buffers[0];
@ -202,8 +203,8 @@ namespace MWRender
node.mRootStateSet->setTextureAttribute(PostProcessor::Unit_Depth, mTextureDepth); node.mRootStateSet->setTextureAttribute(PostProcessor::Unit_Depth, mTextureDepth);
if (mAvgLum) if (mAvgLum)
node.mRootStateSet->setTextureAttribute( node.mRootStateSet->setTextureAttribute(PostProcessor::TextureUnits::Unit_EyeAdaptation,
PostProcessor::TextureUnits::Unit_EyeAdaptation, mLuminanceCalculator.getLuminanceTexture(frameId)); mLuminanceCalculator->getLuminanceTexture(frameId));
if (mTextureNormals) if (mTextureNormals)
node.mRootStateSet->setTextureAttribute(PostProcessor::TextureUnits::Unit_Normals, mTextureNormals); node.mRootStateSet->setTextureAttribute(PostProcessor::TextureUnits::Unit_Normals, mTextureNormals);
@ -258,8 +259,6 @@ namespace MWRender
texture->setTextureSize(w, h); texture->setTextureSize(w, h);
texture->setNumMipmapLevels(pass.mRenderTexture->getNumMipmapLevels()); texture->setNumMipmapLevels(pass.mRenderTexture->getNumMipmapLevels());
texture->dirtyTextureObject(); texture->dirtyTextureObject();
mDirtyAttachments = false;
} }
pass.mRenderTarget->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER); pass.mRenderTarget->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);
@ -336,5 +335,8 @@ namespace MWRender
{ {
bindDestinationFbo(); bindDestinationFbo();
} }
if (mDirtyAttachments)
mDirtyAttachments = false;
} }
} }

View File

@ -22,7 +22,8 @@ namespace MWRender
class PingPongCanvas : public osg::Geometry class PingPongCanvas : public osg::Geometry
{ {
public: public:
PingPongCanvas(Shader::ShaderManager& shaderManager); PingPongCanvas(
Shader::ShaderManager& shaderManager, const std::shared_ptr<LuminanceCalculator>& luminanceCalculator);
void drawGeometry(osg::RenderInfo& renderInfo) const; void drawGeometry(osg::RenderInfo& renderInfo) const;
@ -72,7 +73,7 @@ namespace MWRender
mutable osg::ref_ptr<osg::FrameBufferObject> mMultiviewResolveFramebuffer; mutable osg::ref_ptr<osg::FrameBufferObject> mMultiviewResolveFramebuffer;
mutable osg::ref_ptr<osg::FrameBufferObject> mDestinationFBO; mutable osg::ref_ptr<osg::FrameBufferObject> mDestinationFBO;
mutable std::array<osg::ref_ptr<osg::FrameBufferObject>, 3> mFbos; mutable std::array<osg::ref_ptr<osg::FrameBufferObject>, 3> mFbos;
mutable LuminanceCalculator mLuminanceCalculator; mutable std::shared_ptr<LuminanceCalculator> mLuminanceCalculator;
}; };
} }

View File

@ -118,9 +118,14 @@ namespace MWRender
, mUsePostProcessing(Settings::postProcessing().mEnabled) , mUsePostProcessing(Settings::postProcessing().mEnabled)
, mSamples(Settings::video().mAntialiasing) , mSamples(Settings::video().mAntialiasing)
, mPingPongCull(new PingPongCull(this)) , mPingPongCull(new PingPongCull(this))
, mCanvases({ new PingPongCanvas(mRendering.getResourceSystem()->getSceneManager()->getShaderManager()),
new PingPongCanvas(mRendering.getResourceSystem()->getSceneManager()->getShaderManager()) })
{ {
auto& shaderManager = mRendering.getResourceSystem()->getSceneManager()->getShaderManager();
std::shared_ptr<LuminanceCalculator> luminanceCalculator = std::make_shared<LuminanceCalculator>(shaderManager);
for (auto& canvas : mCanvases)
canvas = new PingPongCanvas(shaderManager, luminanceCalculator);
mHUDCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); mHUDCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
mHUDCamera->setRenderOrder(osg::Camera::POST_RENDER); mHUDCamera->setRenderOrder(osg::Camera::POST_RENDER);
mHUDCamera->setClearColor(osg::Vec4(0.45, 0.45, 0.14, 1.0)); mHUDCamera->setClearColor(osg::Vec4(0.45, 0.45, 0.14, 1.0));
@ -139,8 +144,7 @@ namespace MWRender
if (Settings::shaders().mSoftParticles || Settings::postProcessing().mTransparentPostpass) if (Settings::shaders().mSoftParticles || Settings::postProcessing().mTransparentPostpass)
{ {
mTransparentDepthPostPass mTransparentDepthPostPass
= new TransparentDepthBinCallback(mRendering.getResourceSystem()->getSceneManager()->getShaderManager(), = new TransparentDepthBinCallback(shaderManager, Settings::postProcessing().mTransparentPostpass);
Settings::postProcessing().mTransparentPostpass);
osgUtil::RenderBin::getRenderBinPrototype("DepthSortedBin")->setDrawCallback(mTransparentDepthPostPass); osgUtil::RenderBin::getRenderBinPrototype("DepthSortedBin")->setDrawCallback(mTransparentDepthPostPass);
} }
@ -617,8 +621,6 @@ namespace MWRender
subPass.mSize = renderTarget.mSize; subPass.mSize = renderTarget.mSize;
subPass.mRenderTexture = renderTarget.mTarget; subPass.mRenderTexture = renderTarget.mTarget;
subPass.mMipMap = renderTarget.mMipMap; subPass.mMipMap = renderTarget.mMipMap;
subPass.mStateSet->setAttributeAndModes(new osg::Viewport(
0, 0, subPass.mRenderTexture->getTextureWidth(), subPass.mRenderTexture->getTextureHeight()));
subPass.mRenderTarget = new osg::FrameBufferObject; subPass.mRenderTarget = new osg::FrameBufferObject;
subPass.mRenderTarget->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0, subPass.mRenderTarget->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0,