From ff38cb6423c019d8788b8d7001863e3051bab1e7 Mon Sep 17 00:00:00 2001 From: Benau Date: Thu, 25 Jan 2018 15:36:34 +0800 Subject: [PATCH] Clean up advanced pipeline off code Don't use RTT at all in game when it's off --- data/shaders/simple_particle.frag | 6 +- src/graphics/cpu_particle_manager.cpp | 3 +- src/graphics/rtts.cpp | 361 +++++++++++++------------ src/graphics/rtts.hpp | 45 +-- src/graphics/shader_based_renderer.cpp | 32 +-- src/graphics/shadow_matrices.cpp | 3 +- src/graphics/shadow_matrices.hpp | 3 +- 7 files changed, 224 insertions(+), 229 deletions(-) diff --git a/data/shaders/simple_particle.frag b/data/shaders/simple_particle.frag index 144f42dac..89748d6c4 100644 --- a/data/shaders/simple_particle.frag +++ b/data/shaders/simple_particle.frag @@ -10,12 +10,16 @@ out vec4 FragColor; void main(void) { + float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix); +#if defined(Advanced_Lighting_Enabled) vec2 xy = gl_FragCoord.xy / u_screen; float FragZ = gl_FragCoord.z; vec4 FragmentPos = getPosFromUVDepth(vec3(xy, FragZ), u_inverse_projection_matrix); float EnvZ = texture(dtex, xy).x; vec4 EnvPos = getPosFromUVDepth(vec3(xy, EnvZ), u_inverse_projection_matrix); float alpha = clamp((EnvPos.z - FragmentPos.z) * 0.3, 0., 1.); - float billboard_alpha = mix(1.0, texture(tex, tc).a, billboard_mix); +#else + float alpha = 1.0; +#endif FragColor = texture(tex, tc) * billboard_alpha * pc * alpha; } diff --git a/src/graphics/cpu_particle_manager.cpp b/src/graphics/cpu_particle_manager.cpp index f856ffcd1..47da73c30 100644 --- a/src/graphics/cpu_particle_manager.cpp +++ b/src/graphics/cpu_particle_manager.cpp @@ -297,7 +297,8 @@ void CPUParticleManager::drawAll() { ParticleRenderer::getInstance()->setTextureUnits (cur_mat->getTexture()->getOpenGLTextureName(), - irr_driver->getDepthStencilTexture()); + CVS->isDefferedEnabled() ? + irr_driver->getDepthStencilTexture() : 0); ParticleRenderer::getInstance()->setUniforms(flips, billboard); } else diff --git a/src/graphics/rtts.cpp b/src/graphics/rtts.cpp index 1eb0e929d..d5b6df480 100644 --- a/src/graphics/rtts.cpp +++ b/src/graphics/rtts.cpp @@ -53,11 +53,12 @@ static GLuint generateRTT(const core::dimension2du &res, GLint internalFormat, G return result; } -RTT::RTT(unsigned int width, unsigned int height, float rtt_scale) +RTT::RTT(unsigned int width, unsigned int height, float rtt_scale, + bool use_default_fbo_only) { m_width = (unsigned int)(width * rtt_scale); - m_height = (unsigned int)(height * rtt_scale); - m_shadow_FBO = NULL; + m_height = (unsigned int)(height * rtt_scale); + m_shadow_fbo = NULL; using namespace video; using namespace core; @@ -75,7 +76,10 @@ RTT::RTT(unsigned int width, unsigned int height, float rtt_scale) unsigned linear_depth_mip_levels = int(ceilf(log2f( float(max_(res.Width, res.Height)) ))); - DepthStencilTexture = generateRTT(res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + if (!use_default_fbo_only) + { + m_depth_stencil_tex = generateRTT(res, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + } // All RTTs are currently RGBA16F mostly with stencil. The four tmp RTTs are the same size // as the screen, for use in post-processing. @@ -89,7 +93,7 @@ RTT::RTT(unsigned int width, unsigned int height, float rtt_scale) GLint diffuse_specular_internal_format = GL_R11F_G11F_B10F; GLint type = GL_FLOAT; GLint rgb_internal_format = GL_RGBA8; - + #if defined(USE_GLES2) if (!CVS->isEXTColorBufferFloatUsable()) { @@ -103,190 +107,193 @@ RTT::RTT(unsigned int width, unsigned int height, float rtt_scale) type = GL_UNSIGNED_BYTE; } #endif - - RenderTargetTextures[RTT_TMP1] = generateRTT(res, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_TMP2] = generateRTT(res, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_TMP3] = generateRTT(res, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_TMP4] = generateRTT(res, red_internal_format, red_format, type); - RenderTargetTextures[RTT_LINEAR_DEPTH] = generateRTT(res, red32_internal_format, red_format, type, linear_depth_mip_levels); - RenderTargetTextures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV); - RenderTargetTextures[RTT_COLOR] = generateRTT(res, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_MLAA_COLORS] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); - RenderTargetTextures[RTT_MLAA_TMP] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); - RenderTargetTextures[RTT_MLAA_BLEND] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); - RenderTargetTextures[RTT_SSAO] = generateRTT(res, red_internal_format, red_format, type); - RenderTargetTextures[RTT_DISPLACE] = generateRTT(res, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_DIFFUSE] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); - RenderTargetTextures[RTT_SPECULAR] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); - - RenderTargetTextures[RTT_HALF1] = generateRTT(half, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_QUARTER1] = generateRTT(quarter, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_EIGHTH1] = generateRTT(eighth, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_HALF1_R] = generateRTT(half, red_internal_format, red_format, type); - - RenderTargetTextures[RTT_HALF2] = generateRTT(half, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_QUARTER2] = generateRTT(quarter, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_EIGHTH2] = generateRTT(eighth, rgba_internal_format, rgba_format, type); - RenderTargetTextures[RTT_HALF2_R] = generateRTT(half, red_internal_format, red_format, type); - - RenderTargetTextures[RTT_BLOOM_1024] = generateRTT(shadowsize0, rgba_internal_format, rgb_format, type); - - RenderTargetTextures[RTT_BLOOM_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_TMP_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_LENS_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); - - RenderTargetTextures[RTT_BLOOM_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_TMP_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_LENS_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); - - RenderTargetTextures[RTT_BLOOM_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_TMP_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); - RenderTargetTextures[RTT_LENS_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); - - RenderTargetTextures[RTT_SP_GLOSS] = generateRTT(res, GL_RG8, GL_RG, GL_UNSIGNED_BYTE); - RenderTargetTextures[RTT_SP_DIFF_COLOR] = generateRTT(res, GL_RGBA8, rgb_format, GL_UNSIGNED_BYTE); - - std::vector somevector; - somevector.push_back(RenderTargetTextures[RTT_SSAO]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_NORMAL_AND_DEPTH]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_DIFFUSE]); - somevector.push_back(RenderTargetTextures[RTT_SPECULAR]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_COLOR]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_DIFFUSE]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_SPECULAR]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_MLAA_COLORS]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_MLAA_BLEND]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_MLAA_TMP]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP1]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP2]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP4]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_LINEAR_DEPTH]); - FrameBuffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); - somevector.clear(); - - somevector.push_back(RenderTargetTextures[RTT_HALF1]); - FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_HALF1_R]); - FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_HALF2]); - FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_HALF2_R]); - FrameBuffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_QUARTER1]); - FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_QUARTER2]); - FrameBuffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_EIGHTH1]); - FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_EIGHTH2]); - FrameBuffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_DISPLACE]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - somevector.clear(); - - somevector.push_back(RenderTargetTextures[RTT_BLOOM_1024]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize0.Width, shadowsize0.Height)); - somevector.clear(); - - somevector.push_back(RenderTargetTextures[RTT_BLOOM_512]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP_512]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_LENS_512]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); - somevector.clear(); - - somevector.push_back(RenderTargetTextures[RTT_BLOOM_256]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP_256]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_LENS_256]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); - somevector.clear(); - - somevector.push_back(RenderTargetTextures[RTT_BLOOM_128]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_TMP_128]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_LENS_128]); - FrameBuffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); - - somevector.clear(); - somevector.push_back(RenderTargetTextures[RTT_SP_DIFF_COLOR]); - somevector.push_back(RenderTargetTextures[RTT_NORMAL_AND_DEPTH]); - somevector.push_back(RenderTargetTextures[RTT_SP_GLOSS]); - FrameBuffers.push_back(new FrameBuffer(somevector, DepthStencilTexture, res.Width, res.Height)); - - if (CVS->isShadowEnabled()) + if (!CVS->isDefferedEnabled()) { - shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); - somevector.clear(); - m_shadow_FBO = new FrameBufferLayer(somevector, shadowDepthTex, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4); + // RTT is used in only deferred shading which need hdr framebuffer + rgba_internal_format = GL_RGBA8; + type = GL_UNSIGNED_BYTE; } - // Clear this FBO to 1s so that if no SSAO is computed we can still use it. - getFBO(FBO_HALF1_R).bind(); - glClearColor(1., 1., 1., 1.); - glClear(GL_COLOR_BUFFER_BIT); + if (!use_default_fbo_only) + { + m_render_target_textures[RTT_COLOR] = generateRTT(res, rgba_internal_format, rgba_format, type); + } + if (CVS->isDefferedEnabled()) + { + m_render_target_textures[RTT_NORMAL_AND_DEPTH] = generateRTT(res, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV); + m_render_target_textures[RTT_TMP1] = generateRTT(res, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_TMP2] = generateRTT(res, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_TMP3] = generateRTT(res, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_TMP4] = generateRTT(res, red_internal_format, red_format, type); + m_render_target_textures[RTT_LINEAR_DEPTH] = generateRTT(res, red32_internal_format, red_format, type, linear_depth_mip_levels); + m_render_target_textures[RTT_MLAA_COLORS] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); + m_render_target_textures[RTT_MLAA_TMP] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); + m_render_target_textures[RTT_MLAA_BLEND] = generateRTT(res, rgb_internal_format, rgb_format, GL_UNSIGNED_BYTE); + m_render_target_textures[RTT_SSAO] = generateRTT(res, red_internal_format, red_format, type); + m_render_target_textures[RTT_DISPLACE] = generateRTT(res, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_DIFFUSE] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); + m_render_target_textures[RTT_SPECULAR] = generateRTT(res, diffuse_specular_internal_format, rgb_format, type); - getFBO(FBO_COMBINED_DIFFUSE_SPECULAR).bind(); - float color = 0.5; -#if defined(USE_GLES2) - if (!CVS->isDefferedEnabled()) - color = pow(color, 1. / 2.2); -#endif - glClearColor(color, color, color, color); - glClear(GL_COLOR_BUFFER_BIT); + m_render_target_textures[RTT_HALF1] = generateRTT(half, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_QUARTER1] = generateRTT(quarter, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_EIGHTH1] = generateRTT(eighth, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_HALF1_R] = generateRTT(half, red_internal_format, red_format, type); + + m_render_target_textures[RTT_HALF2] = generateRTT(half, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_QUARTER2] = generateRTT(quarter, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_EIGHTH2] = generateRTT(eighth, rgba_internal_format, rgba_format, type); + m_render_target_textures[RTT_HALF2_R] = generateRTT(half, red_internal_format, red_format, type); + + m_render_target_textures[RTT_BLOOM_1024] = generateRTT(shadowsize0, rgba_internal_format, rgb_format, type); + + m_render_target_textures[RTT_BLOOM_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_TMP_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_LENS_512] = generateRTT(shadowsize1, rgba_internal_format, rgb_format, type); + + m_render_target_textures[RTT_BLOOM_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_TMP_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_LENS_256] = generateRTT(shadowsize2, rgba_internal_format, rgb_format, type); + + m_render_target_textures[RTT_BLOOM_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_TMP_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); + m_render_target_textures[RTT_LENS_128] = generateRTT(shadowsize3, rgba_internal_format, rgb_format, type); + + m_render_target_textures[RTT_SP_GLOSS] = generateRTT(res, GL_RG8, GL_RG, GL_UNSIGNED_BYTE); + m_render_target_textures[RTT_SP_DIFF_COLOR] = generateRTT(res, GL_RGBA8, rgb_format, GL_UNSIGNED_BYTE); + } + + std::vector somevector; + if (!use_default_fbo_only) + { + somevector.push_back(m_render_target_textures[RTT_COLOR]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + } + + if (CVS->isDefferedEnabled()) + { + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_NORMAL_AND_DEPTH]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_SSAO]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_DIFFUSE]); + somevector.push_back(m_render_target_textures[RTT_SPECULAR]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_MLAA_COLORS]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_MLAA_BLEND]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_MLAA_TMP]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP1]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP2]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP4]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_LINEAR_DEPTH]); + m_frame_buffers.push_back(new FrameBuffer(somevector, res.Width, res.Height)); + somevector.clear(); + + somevector.push_back(m_render_target_textures[RTT_HALF1]); + m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_HALF1_R]); + m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_HALF2]); + m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_HALF2_R]); + m_frame_buffers.push_back(new FrameBuffer(somevector, half.Width, half.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_QUARTER1]); + m_frame_buffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_QUARTER2]); + m_frame_buffers.push_back(new FrameBuffer(somevector, quarter.Width, quarter.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_EIGHTH1]); + m_frame_buffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_EIGHTH2]); + m_frame_buffers.push_back(new FrameBuffer(somevector, eighth.Width, eighth.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_DISPLACE]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + somevector.clear(); + + somevector.push_back(m_render_target_textures[RTT_BLOOM_1024]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize0.Width, shadowsize0.Height)); + somevector.clear(); + + somevector.push_back(m_render_target_textures[RTT_BLOOM_512]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP_512]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_LENS_512]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize1.Width, shadowsize1.Height)); + somevector.clear(); + + somevector.push_back(m_render_target_textures[RTT_BLOOM_256]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP_256]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_LENS_256]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize2.Width, shadowsize2.Height)); + somevector.clear(); + + somevector.push_back(m_render_target_textures[RTT_BLOOM_128]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_TMP_128]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_LENS_128]); + m_frame_buffers.push_back(new FrameBuffer(somevector, shadowsize3.Width, shadowsize3.Height)); + + somevector.clear(); + somevector.push_back(m_render_target_textures[RTT_SP_DIFF_COLOR]); + somevector.push_back(m_render_target_textures[RTT_NORMAL_AND_DEPTH]); + somevector.push_back(m_render_target_textures[RTT_SP_GLOSS]); + m_frame_buffers.push_back(new FrameBuffer(somevector, m_depth_stencil_tex, res.Width, res.Height)); + + if (CVS->isShadowEnabled()) + { + m_shadow_depth_tex = generateRTT3D(GL_TEXTURE_2D_ARRAY, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1); + somevector.clear(); + m_shadow_fbo = new FrameBufferLayer(somevector, m_shadow_depth_tex, UserConfigParams::m_shadows_resolution, UserConfigParams::m_shadows_resolution, 4); + } + // Clear this FBO to 1s so that if no SSAO is computed we can still use it. + getFBO(FBO_HALF1_R).bind(); + glClearColor(1., 1., 1., 1.); + glClear(GL_COLOR_BUFFER_BIT); + } glBindFramebuffer(GL_FRAMEBUFFER, 0); } RTT::~RTT() { glBindFramebuffer(GL_FRAMEBUFFER, 0); - glDeleteTextures(RTT_COUNT, RenderTargetTextures); - glDeleteTextures(1, &DepthStencilTexture); + glDeleteTextures(RTT_COUNT, m_render_target_textures); + glDeleteTextures(1, &m_depth_stencil_tex); if (CVS->isShadowEnabled()) { - delete m_shadow_FBO; - glDeleteTextures(1, &shadowDepthTex); + delete m_shadow_fbo; + glDeleteTextures(1, &m_shadow_depth_tex); } } diff --git a/src/graphics/rtts.hpp b/src/graphics/rtts.hpp index 66ec08628..f8493d342 100644 --- a/src/graphics/rtts.hpp +++ b/src/graphics/rtts.hpp @@ -39,12 +39,10 @@ using irr::video::ITexture; enum TypeFBO { - FBO_SSAO, - FBO_NORMAL_AND_DEPTHS, - FBO_COMBINED_DIFFUSE_SPECULAR, FBO_COLORS, - FBO_DIFFUSE, - FBO_SPECULAR, + FBO_NORMAL_AND_DEPTHS, + FBO_SSAO, + FBO_COMBINED_DIFFUSE_SPECULAR, FBO_MLAA_COLORS, FBO_MLAA_BLEND, FBO_MLAA_TMP, @@ -79,13 +77,13 @@ enum TypeFBO enum TypeRTT : unsigned int { - RTT_TMP1 = 0, + RTT_COLOR = 0, + RTT_NORMAL_AND_DEPTH, + RTT_TMP1, RTT_TMP2, RTT_TMP3, RTT_TMP4, RTT_LINEAR_DEPTH, - RTT_NORMAL_AND_DEPTH, - RTT_COLOR, RTT_DIFFUSE, RTT_SPECULAR, @@ -143,27 +141,36 @@ enum TypeRTT : unsigned int class RTT { public: - RTT(unsigned int width, unsigned int height, float rtt_scale = 1.0f); + RTT(unsigned int width, unsigned int height, float rtt_scale = 1.0f, + bool use_default_fbo_only = false); ~RTT(); - + unsigned int getWidth () const { return m_width ; } unsigned int getHeight() const { return m_height; } - 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]; } + FrameBufferLayer* getShadowFrameBuffer() { return m_shadow_fbo; } + unsigned getDepthStencilTexture() const + { + assert(m_depth_stencil_tex != 0); + return m_depth_stencil_tex; + } + unsigned getRenderTarget(enum TypeRTT target) const + { + assert(m_render_target_textures[target] != 0); + return m_render_target_textures[target]; + } + FrameBuffer& getFBO(enum TypeFBO fbo) { return m_frame_buffers[fbo]; } private: - unsigned RenderTargetTextures[RTT_COUNT]; - PtrVector FrameBuffers; - unsigned DepthStencilTexture; + unsigned m_render_target_textures[RTT_COUNT] = {}; + PtrVector m_frame_buffers; + unsigned m_depth_stencil_tex = 0; unsigned int m_width; unsigned int m_height; - unsigned shadowDepthTex; - FrameBufferLayer* m_shadow_FBO; + unsigned m_shadow_depth_tex = 0; + FrameBufferLayer* m_shadow_fbo; LEAK_CHECK(); }; diff --git a/src/graphics/shader_based_renderer.cpp b/src/graphics/shader_based_renderer.cpp index d64bed82c..7ec9a8945 100644 --- a/src/graphics/shader_based_renderer.cpp +++ b/src/graphics/shader_based_renderer.cpp @@ -50,9 +50,6 @@ #include // ---------------------------------------------------------------------------- - - - void ShaderBasedRenderer::setRTT(RTT* rtts) { m_rtts = rtts; @@ -111,8 +108,7 @@ void ShaderBasedRenderer::computeMatrixesAndCameras(scene::ICameraSceneNode *con unsigned int width, unsigned int height) { m_current_screen_size = core::vector2df((float)width, (float)height); - m_shadow_matrices.computeMatrixesAndCameras(camnode, width, height, - m_rtts->getDepthStencilTexture()); + m_shadow_matrices.computeMatrixesAndCameras(camnode, width, height); } // computeMatrixesAndCameras // ---------------------------------------------------------------------------- @@ -440,27 +436,6 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, glDisable(GL_BLEND); glEnable(GL_CULL_FACE); - if (!forceRTT) - { - // We need a cleared depth buffer for some effect (eg particles depth blending) - m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).bind(); - // Bind() modifies the viewport. In order not to affect anything else, - // the viewport is just reset here and not removed in Bind(). - const core::recti &vp = Camera::getActiveCamera()->getViewport(); - glViewport(vp.UpperLeftCorner.X, - irr_driver->getActualScreenSize().Height - vp.LowerRightCorner.Y, - vp.LowerRightCorner.X - vp.UpperLeftCorner.X, - vp.LowerRightCorner.Y - vp.UpperLeftCorner.Y); - glClear(GL_DEPTH_BUFFER_BIT); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } - else - { - m_rtts->getFBO(FBO_NORMAL_AND_DEPTHS).bind(); - glClearColor(0., 0., 0., 0.); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } - if (forceRTT) { m_rtts->getFBO(FBO_COLORS).bind(); @@ -471,6 +446,8 @@ void ShaderBasedRenderer::renderScene(scene::ICameraSceneNode * const camnode, glClearColor(clearColor.getRed() / 255.f, clearColor.getGreen() / 255.f, clearColor.getBlue() / 255.f, clearColor.getAlpha() / 255.f); glClear(GL_COLOR_BUFFER_BIT); + glClearColor(0.0f, 0.0f, 0.0f, 0.0f); + glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } { @@ -651,7 +628,8 @@ void ShaderBasedRenderer::onLoadWorld() unsigned int width = viewport.LowerRightCorner.X - viewport.UpperLeftCorner.X; unsigned int height = viewport.LowerRightCorner.Y - viewport.UpperLeftCorner.Y; RTT* rtts = new RTT(width, height, CVS->isDefferedEnabled() ? - UserConfigParams::m_scale_rtts_factor : 1.0f); + UserConfigParams::m_scale_rtts_factor : 1.0f, + !CVS->isDefferedEnabled()); setRTT(rtts); } diff --git a/src/graphics/shadow_matrices.cpp b/src/graphics/shadow_matrices.cpp index 390807258..949804694 100644 --- a/src/graphics/shadow_matrices.cpp +++ b/src/graphics/shadow_matrices.cpp @@ -193,8 +193,7 @@ core::matrix4 ShadowMatrices::getTighestFitOrthoProj(const core::matrix4 &transf * \param height of the rendering viewport */ void ShadowMatrices::computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode, - unsigned int width, unsigned int height, - GLuint depth_stencil_texture) + unsigned int width, unsigned int height) { camnode->render(); irr_driver->setProjMatrix(irr_driver->getVideoDriver() diff --git a/src/graphics/shadow_matrices.hpp b/src/graphics/shadow_matrices.hpp index a7ad04134..793107977 100644 --- a/src/graphics/shadow_matrices.hpp +++ b/src/graphics/shadow_matrices.hpp @@ -62,8 +62,7 @@ public: ~ShadowMatrices(); void computeMatrixesAndCameras(scene::ICameraSceneNode *const camnode, - unsigned int width, unsigned int height, - GLuint depth_stencil_texture); + unsigned int width, unsigned int height); void addLight(const core::vector3df &pos); void updateSunOrthoMatrices(); void renderShadowsDebug(const FrameBuffer* shadow_framebuffer,