do not clear depth buffer in first person

pull/3179/head
glassmancody.info 3 years ago
parent d6613d3677
commit cc009d246f

@ -67,6 +67,7 @@
Feature #5996: Support Lua scripts in OpenMW
Feature #6017: Separate persistent and temporary cell references when saving
Feature #6032: Reverse-z depth buffer
Feature #6078: First person should not clear depth buffer
Feature #6162: Refactor GUI to use shaders and to be GLES and GL3+ friendly
Feature #6199: Support FBO Rendering
Feature #6249: Alpha testing support for Collada

@ -44,6 +44,7 @@
#include "renderbin.hpp"
#include "vismask.hpp"
#include "util.hpp"
#include "postprocessor.hpp"
namespace
{
@ -330,6 +331,8 @@ void NpcAnimation::setViewMode(NpcAnimation::ViewMode viewMode)
}
/// @brief A RenderBin callback to clear the depth buffer before rendering.
/// Switches depth attachments to a proxy renderbuffer, reattaches original depth then redraws first person root.
/// This gives a complete depth buffer which can be used for postprocessing, buffer resolves as if depth was never cleared.
class DepthClearCallback : public osgUtil::RenderBin::DrawCallback
{
public:
@ -337,18 +340,49 @@ public:
{
mDepth = SceneUtil::createDepth();
mDepth->setWriteMask(true);
mStateSet = new osg::StateSet;
mStateSet->setAttributeAndModes(new osg::ColorMask(false, false, false, false), osg::StateAttribute::ON);
mStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
}
void drawImplementation(osgUtil::RenderBin* bin, osg::RenderInfo& renderInfo, osgUtil::RenderLeaf*& previous) override
{
renderInfo.getState()->applyAttribute(mDepth);
osg::State* state = renderInfo.getState();
PostProcessor* postProcessor = dynamic_cast<PostProcessor*>(renderInfo.getCurrentCamera()->getUserData());
state->applyAttribute(mDepth);
if (postProcessor && postProcessor->getFirstPersonRBProxy())
{
osg::GLExtensions* ext = state->get<osg::GLExtensions>();
osg::FrameBufferAttachment(postProcessor->getFirstPersonRBProxy()).attach(*state, GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, ext);
glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
// color accumulation pass
bin->drawImplementation(renderInfo, previous);
bin->drawImplementation(renderInfo, previous);
auto primaryFBO = postProcessor->getMsaaFbo() ? postProcessor->getMsaaFbo() : postProcessor->getFbo();
primaryFBO->getAttachment(osg::FrameBufferObject::BufferComponent::DEPTH_BUFFER).attach(*state, GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, ext);
state->pushStateSet(mStateSet);
state->apply();
// depth accumulation pass
bin->drawImplementation(renderInfo, previous);
state->popStateSet();
}
else
{
// fallback to standard depth clear when we are not rendering our main scene via an intermediate FBO
glClear(GL_DEPTH_BUFFER_BIT);
bin->drawImplementation(renderInfo, previous);
}
}
osg::ref_ptr<osg::Depth> mDepth;
osg::ref_ptr<osg::StateSet> mStateSet;
};
/// Overrides Field of View to given value for rendering the subgraph.

@ -183,6 +183,9 @@ namespace MWRender
mMsaaFbo->setAttachment(osg::Camera::DEPTH_BUFFER, osg::FrameBufferAttachment(depthRB));
}
if (const auto depthProxy = std::getenv("OPENMW_ENABLE_DEPTH_CLEAR_PROXY"))
mFirstPersonDepthRBProxy = new osg::RenderBuffer(width, height, mDepthTex->getInternalFormat(), samples);
mViewer->getCamera()->resize(width, height);
mHUDCamera->resize(width, height);
mRendering.updateProjectionMatrix();

@ -23,6 +23,7 @@ namespace MWRender
auto getMsaaFbo() { return mMsaaFbo; }
auto getFbo() { return mFbo; }
auto getFirstPersonRBProxy() { return mFirstPersonDepthRBProxy; }
int getDepthFormat() { return mDepthFormat; }
@ -37,6 +38,7 @@ namespace MWRender
osg::ref_ptr<osg::FrameBufferObject> mMsaaFbo;
osg::ref_ptr<osg::FrameBufferObject> mFbo;
osg::ref_ptr<osg::RenderBuffer> mFirstPersonDepthRBProxy;
osg::ref_ptr<osg::Texture2D> mSceneTex;
osg::ref_ptr<osg::Texture2D> mDepthTex;

Loading…
Cancel
Save