mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +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:
commit
9fb5fe26e6
@ -10,9 +10,11 @@
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
PingPongCanvas::PingPongCanvas(Shader::ShaderManager& shaderManager)
|
||||
PingPongCanvas::PingPongCanvas(
|
||||
Shader::ShaderManager& shaderManager, const std::shared_ptr<LuminanceCalculator>& luminanceCalculator)
|
||||
: mFallbackStateSet(new osg::StateSet)
|
||||
, mMultiviewResolveStateSet(new osg::StateSet)
|
||||
, mLuminanceCalculator(luminanceCalculator)
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
setUseVertexBufferObjects(true);
|
||||
@ -26,8 +28,7 @@ namespace MWRender
|
||||
|
||||
addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 3));
|
||||
|
||||
mLuminanceCalculator = LuminanceCalculator(shaderManager);
|
||||
mLuminanceCalculator.disable();
|
||||
mLuminanceCalculator->disable();
|
||||
|
||||
Shader::ShaderManager::DefineMap defines;
|
||||
Stereo::shaderStereoDefines(defines);
|
||||
@ -142,7 +143,7 @@ namespace MWRender
|
||||
.getTexture());
|
||||
}
|
||||
|
||||
mLuminanceCalculator.dirty(mTextureScene->getTextureWidth(), mTextureScene->getTextureHeight());
|
||||
mLuminanceCalculator->dirty(mTextureScene->getTextureWidth(), mTextureScene->getTextureHeight());
|
||||
|
||||
if (Stereo::getStereo())
|
||||
mRenderViewport
|
||||
@ -158,11 +159,11 @@ namespace MWRender
|
||||
{ GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT2_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
|
||||
// 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];
|
||||
|
||||
@ -202,8 +203,8 @@ namespace MWRender
|
||||
node.mRootStateSet->setTextureAttribute(PostProcessor::Unit_Depth, mTextureDepth);
|
||||
|
||||
if (mAvgLum)
|
||||
node.mRootStateSet->setTextureAttribute(
|
||||
PostProcessor::TextureUnits::Unit_EyeAdaptation, mLuminanceCalculator.getLuminanceTexture(frameId));
|
||||
node.mRootStateSet->setTextureAttribute(PostProcessor::TextureUnits::Unit_EyeAdaptation,
|
||||
mLuminanceCalculator->getLuminanceTexture(frameId));
|
||||
|
||||
if (mTextureNormals)
|
||||
node.mRootStateSet->setTextureAttribute(PostProcessor::TextureUnits::Unit_Normals, mTextureNormals);
|
||||
@ -258,8 +259,6 @@ namespace MWRender
|
||||
texture->setTextureSize(w, h);
|
||||
texture->setNumMipmapLevels(pass.mRenderTexture->getNumMipmapLevels());
|
||||
texture->dirtyTextureObject();
|
||||
|
||||
mDirtyAttachments = false;
|
||||
}
|
||||
|
||||
pass.mRenderTarget->apply(state, osg::FrameBufferObject::DRAW_FRAMEBUFFER);
|
||||
@ -336,5 +335,8 @@ namespace MWRender
|
||||
{
|
||||
bindDestinationFbo();
|
||||
}
|
||||
|
||||
if (mDirtyAttachments)
|
||||
mDirtyAttachments = false;
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ namespace MWRender
|
||||
class PingPongCanvas : public osg::Geometry
|
||||
{
|
||||
public:
|
||||
PingPongCanvas(Shader::ShaderManager& shaderManager);
|
||||
PingPongCanvas(
|
||||
Shader::ShaderManager& shaderManager, const std::shared_ptr<LuminanceCalculator>& luminanceCalculator);
|
||||
|
||||
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> mDestinationFBO;
|
||||
mutable std::array<osg::ref_ptr<osg::FrameBufferObject>, 3> mFbos;
|
||||
mutable LuminanceCalculator mLuminanceCalculator;
|
||||
mutable std::shared_ptr<LuminanceCalculator> mLuminanceCalculator;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -118,9 +118,14 @@ namespace MWRender
|
||||
, mUsePostProcessing(Settings::postProcessing().mEnabled)
|
||||
, mSamples(Settings::video().mAntialiasing)
|
||||
, 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->setRenderOrder(osg::Camera::POST_RENDER);
|
||||
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)
|
||||
{
|
||||
mTransparentDepthPostPass
|
||||
= new TransparentDepthBinCallback(mRendering.getResourceSystem()->getSceneManager()->getShaderManager(),
|
||||
Settings::postProcessing().mTransparentPostpass);
|
||||
= new TransparentDepthBinCallback(shaderManager, Settings::postProcessing().mTransparentPostpass);
|
||||
osgUtil::RenderBin::getRenderBinPrototype("DepthSortedBin")->setDrawCallback(mTransparentDepthPostPass);
|
||||
}
|
||||
|
||||
@ -617,8 +621,6 @@ namespace MWRender
|
||||
subPass.mSize = renderTarget.mSize;
|
||||
subPass.mRenderTexture = renderTarget.mTarget;
|
||||
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->setAttachment(osg::FrameBufferObject::BufferComponent::COLOR_BUFFER0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user