From 4194977df54029c68bb5b201a9d29a3bdd400e52 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 13 Jan 2018 15:38:52 +0800 Subject: [PATCH] Fix shadow visualization --- src/graphics/lighting_passes.cpp | 6 +++--- src/graphics/lighting_passes.hpp | 2 +- src/graphics/rtts.hpp | 2 +- src/graphics/shader_based_renderer.cpp | 4 ++-- src/graphics/shadow_matrices.cpp | 11 +++++------ src/graphics/shadow_matrices.hpp | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/graphics/lighting_passes.cpp b/src/graphics/lighting_passes.cpp index 07979b178..b58f2f3b1 100644 --- a/src/graphics/lighting_passes.cpp +++ b/src/graphics/lighting_passes.cpp @@ -209,13 +209,13 @@ public: // ------------------------------------------------------------------------ void render(GLuint normal_depth_texture, GLuint depth_stencil_texture, - const FrameBuffer& shadow_framebuffer, + const FrameBuffer* shadow_framebuffer, const core::vector3df &direction, const video::SColorf &col) { setTextureUnits(normal_depth_texture, depth_stencil_texture, - shadow_framebuffer.getDepthTexture() ); + shadow_framebuffer->getDepthTexture() ); drawFullScreenEffect(ShadowMatrices::m_shadow_split[1], ShadowMatrices::m_shadow_split[2], ShadowMatrices::m_shadow_split[3], @@ -418,7 +418,7 @@ void LightingPasses::updateLightsInfo(scene::ICameraSceneNode * const camnode, void LightingPasses::renderLights( bool has_shadow, GLuint normal_depth_texture, GLuint depth_stencil_texture, - const FrameBuffer& shadow_framebuffer, + const FrameBuffer* shadow_framebuffer, GLuint specular_probe) { { diff --git a/src/graphics/lighting_passes.hpp b/src/graphics/lighting_passes.hpp index 34e61fe08..4fd6bab43 100644 --- a/src/graphics/lighting_passes.hpp +++ b/src/graphics/lighting_passes.hpp @@ -50,7 +50,7 @@ public: void renderLights( bool has_shadow, GLuint normal_depth_texture, GLuint depth_stencil_texture, - const FrameBuffer& shadow_framebuffer, + const FrameBuffer* shadow_framebuffer, GLuint specular_probe); void renderLightsScatter(GLuint depth_stencil_texture, const FrameBuffer& half1_framebuffer, diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index d7d2d1684..66ec08628 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -149,7 +149,7 @@ public: unsigned int getWidth () const { return m_width ; } unsigned int getHeight() const { return m_height; } - FrameBufferLayer &getShadowFrameBuffer() { return *m_shadow_FBO; } + FrameBufferLayer* getShadowFrameBuffer() { return m_shadow_FBO; } unsigned getDepthStencilTexture() const { return DepthStencilTexture; } unsigned getRenderTarget(enum TypeRTT target) const { return RenderTargetTextures[target]; } FrameBuffer& getFBO(enum TypeFBO fbo) { return FrameBuffers[fbo]; } diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index 53c28211f..1bee9a130 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -187,7 +187,7 @@ void ShaderBasedRenderer::renderShadows() glClearColor(1.0f, 1.0f, 1.0f, 1.0f); for (unsigned cascade = 0; cascade < 4; cascade++) { - m_rtts->getShadowFrameBuffer().bindLayerDepthOnly(cascade); + m_rtts->getShadowFrameBuffer()->bindLayerDepthOnly(cascade); glClear(GL_DEPTH_BUFFER_BIT); SP::sp_cur_shadow_cascade = cascade; ScopedGPUTimer Timer(irr_driver->getGPUTimer(Q_SHADOWS_CASCADE0 + cascade)); @@ -596,7 +596,7 @@ void ShaderBasedRenderer::renderPostProcessing(Camera * const camera) camera->activate(); m_post_processing->renderPassThrough(m_rtts->getFBO(FBO_HALF1_R).getRTT()[0], viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X, viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y); } - else if (irr_driver->getShadowViz()) + else if (irr_driver->getShadowViz() && m_rtts->getShadowFrameBuffer()) { m_shadow_matrices.renderShadowsDebug(m_rtts->getShadowFrameBuffer(), m_post_processing); } diff --git a/src/graphics/shadow_matrices.cpp b/src/graphics/shadow_matrices.cpp index d5599ac23..390807258 100644 --- a/src/graphics/shadow_matrices.cpp +++ b/src/graphics/shadow_matrices.cpp @@ -22,7 +22,6 @@ #include "config/user_config.hpp" #include "graphics/central_settings.hpp" #include "graphics/frame_buffer.hpp" -#include "graphics/glwrap.hpp" #include "graphics/irr_driver.hpp" #include "graphics/post_processing.hpp" #include "graphics/rtts.hpp" @@ -320,24 +319,24 @@ void ShadowMatrices::renderWireFrameFrustrum(float *tmp, unsigned i) glDrawElements(GL_LINES, 24, GL_UNSIGNED_INT, 0); } // ---------------------------------------------------------------------------- -void ShadowMatrices::renderShadowsDebug(const FrameBuffer &shadow_framebuffer, +void ShadowMatrices::renderShadowsDebug(const FrameBuffer* shadow_framebuffer, const PostProcessing *post_processing) { glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, UserConfigParams::m_height / 2, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); - post_processing->renderTextureLayer(shadow_framebuffer.getRTT()[0], 0); + post_processing->renderTextureLayer(shadow_framebuffer->getDepthTexture(), 0); renderWireFrameFrustrum(m_shadows_cam[0], 0); glViewport(UserConfigParams::m_width / 2, UserConfigParams::m_height / 2, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); - post_processing->renderTextureLayer(shadow_framebuffer.getRTT()[0], 1); + post_processing->renderTextureLayer(shadow_framebuffer->getDepthTexture(), 1); renderWireFrameFrustrum(m_shadows_cam[1], 1); glViewport(0, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); - post_processing->renderTextureLayer(shadow_framebuffer.getRTT()[0], 2); + post_processing->renderTextureLayer(shadow_framebuffer->getDepthTexture(), 2); renderWireFrameFrustrum(m_shadows_cam[2], 2); glViewport(UserConfigParams::m_width / 2, 0, UserConfigParams::m_width / 2, UserConfigParams::m_height / 2); - post_processing->renderTextureLayer(shadow_framebuffer.getRTT()[0], 3); + post_processing->renderTextureLayer(shadow_framebuffer->getDepthTexture(), 3); renderWireFrameFrustrum(m_shadows_cam[3], 3); glViewport(0, 0, UserConfigParams::m_width, UserConfigParams::m_height); } diff --git a/src/graphics/shadow_matrices.hpp b/src/graphics/shadow_matrices.hpp index aa9fc9a69..a7ad04134 100644 --- a/src/graphics/shadow_matrices.hpp +++ b/src/graphics/shadow_matrices.hpp @@ -66,7 +66,7 @@ public: GLuint depth_stencil_texture); void addLight(const core::vector3df &pos); void updateSunOrthoMatrices(); - void renderShadowsDebug(const FrameBuffer &shadow_framebuffer, + void renderShadowsDebug(const FrameBuffer* shadow_framebuffer, const PostProcessing *post_processing); // ------------------------------------------------------------------------