diff --git a/pipeline/glow-extras/pipeline/RenderPass.hh b/pipeline/glow-extras/pipeline/RenderPass.hh index 26af14ed5d170a54ec7f2f6f9e2a01070f09802c..b97a52f1989fa452588da5b71ae8e1840f809e98 100644 --- a/pipeline/glow-extras/pipeline/RenderPass.hh +++ b/pipeline/glow-extras/pipeline/RenderPass.hh @@ -35,6 +35,9 @@ struct RenderPass SharedTextureRectangle depthTarget = nullptr; /// Currently bound framebuffer SharedFramebuffer framebuffer = nullptr; + + /// Current color texture (different from the bound one in destructive PostProcess) + SharedTextureRectangle colorTexture = nullptr; }; } } diff --git a/pipeline/glow-extras/pipeline/RenderingPipeline.cc b/pipeline/glow-extras/pipeline/RenderingPipeline.cc index 6ad0342a58d673fb26a11f9b05c0093bc3b20434..f5fa5d66ff9cecff72edd67df92acacd320a5a0f 100644 --- a/pipeline/glow-extras/pipeline/RenderingPipeline.cc +++ b/pipeline/glow-extras/pipeline/RenderingPipeline.cc @@ -180,11 +180,20 @@ void RenderingPipeline::render(const std::function<void(RenderPass const& pass)> rp.pipeline = this; rp.camera = &cam; rp.depthTarget = mTargetDepth; - rp.framebuffer = (toColorTmp ? mFboToColor : mFboToColorTmp); + rp.colorTexture = (toColorTmp ? mTargetColor : mTargetColorTmp); - auto fbo = (toColorTmp ? mFboToColor : mFboToColorTmp)->bind(); + // For destructive postprocess, bind the other framebuffer + rp.framebuffer = ((toColorTmp != mDestructivePostprocess) + ? mFboToColor + : mFboToColorTmp); + + if (mDestructivePostprocess) glClear(GL_COLOR_BUFFER_BIT); + + auto fbo = rp.framebuffer->bind(); renderFunc(rp); + + if (mDestructivePostprocess) toColorTmp = !toColorTmp; } // Transparency resolve diff --git a/pipeline/glow-extras/pipeline/RenderingPipeline.hh b/pipeline/glow-extras/pipeline/RenderingPipeline.hh index bc37433388876e219395ab66e59db51877fd4948..35b2c48b1b5c3cdb8100a9730215eef143e2e8ff 100644 --- a/pipeline/glow-extras/pipeline/RenderingPipeline.hh +++ b/pipeline/glow-extras/pipeline/RenderingPipeline.hh @@ -96,6 +96,10 @@ private: float mDitheringStrength = 1 / 256.f; glm::vec3 mClearColor; + // true if the postprocess should use the color target as an input + // instead of blending to it + bool mDestructivePostprocess = false; + public: // getter, setter GLOW_PROPERTY(Camera); @@ -106,6 +110,7 @@ public: // getter, setter GLOW_PROPERTY(DitheringStrength); GLOW_PROPERTY(TransparentPass); GLOW_PROPERTY(ClearColor); + GLOW_PROPERTY(DestructivePostprocess); int getOutputWidth() const; int getOutputHeight() const;