From eb8beb335e30ba6e3a35a56ace665ec59cd840dd Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 13 Dec 2024 13:49:49 +0100 Subject: [PATCH] Fix bloom with post_processing_texture_bits < 16 --- src/client/render/pipeline.cpp | 21 +++++++++++++++++---- src/client/render/secondstage.cpp | 13 ++++++++----- src/defaultsettings.cpp | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/client/render/pipeline.cpp b/src/client/render/pipeline.cpp index d24aa3ce8..33b3e78e2 100644 --- a/src/client/render/pipeline.cpp +++ b/src/client/render/pipeline.cpp @@ -6,6 +6,7 @@ #include "client/client.h" #include "client/hud.h" #include "IRenderTarget.h" +#include "SColor.h" #include #include @@ -122,10 +123,19 @@ bool TextureBuffer::ensureTexture(video::ITexture **texture, const TextureDefini if (!modify) return false; - if (*texture) + if (*texture) { m_driver->removeTexture(*texture); + *texture = nullptr; + } if (definition.valid) { + if (!m_driver->queryTextureFormat(definition.format)) { + errorstream << "Failed to create texture \"" << definition.name + << "\": unsupported format " << video::ColorFormatNames[definition.format] + << std::endl; + return false; + } + if (definition.clear) { // We're not able to clear a render target texture // We're not able to create a normal texture with MSAA @@ -142,9 +152,12 @@ bool TextureBuffer::ensureTexture(video::ITexture **texture, const TextureDefini } else { *texture = m_driver->addRenderTargetTexture(size, definition.name.c_str(), definition.format); } - } - else { - *texture = nullptr; + + if (!*texture) { + errorstream << "Failed to create texture \"" << definition.name + << "\"" << std::endl; + return false; + } } return true; diff --git a/src/client/render/secondstage.cpp b/src/client/render/secondstage.cpp index f6a0cf78e..35ebe8110 100644 --- a/src/client/render/secondstage.cpp +++ b/src/client/render/secondstage.cpp @@ -165,6 +165,9 @@ RenderStep *addPostProcessing(RenderPipeline *pipeline, RenderStep *previousStep // Number of mipmap levels of the bloom downsampling texture const u8 MIPMAP_LEVELS = 4; + // color_format can be a normalized integer format, but bloom requires + // values outside of [0,1] so this needs to be a different one. + const auto bloom_format = video::ECF_A16B16G16R16F; // post-processing stage @@ -173,16 +176,16 @@ RenderStep *addPostProcessing(RenderPipeline *pipeline, RenderStep *previousStep // common downsampling step for bloom or autoexposure if (enable_bloom || enable_auto_exposure) { - v2f downscale = scale * 0.5; + v2f downscale = scale * 0.5f; for (u8 i = 0; i < MIPMAP_LEVELS; i++) { - buffer->setTexture(TEXTURE_SCALE_DOWN + i, downscale, std::string("downsample") + std::to_string(i), color_format); + buffer->setTexture(TEXTURE_SCALE_DOWN + i, downscale, std::string("downsample") + std::to_string(i), bloom_format); if (enable_bloom) - buffer->setTexture(TEXTURE_SCALE_UP + i, downscale, std::string("upsample") + std::to_string(i), color_format); - downscale *= 0.5; + buffer->setTexture(TEXTURE_SCALE_UP + i, downscale, std::string("upsample") + std::to_string(i), bloom_format); + downscale *= 0.5f; } if (enable_bloom) { - buffer->setTexture(TEXTURE_BLOOM, scale, "bloom", color_format); + buffer->setTexture(TEXTURE_BLOOM, scale, "bloom", bloom_format); // get bright spots u32 shader_id = client->getShaderSource()->getShader("extract_bloom", TILE_MATERIAL_PLAIN, NDT_MESH); diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 674442469..b1094be2d 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -571,7 +571,9 @@ void set_default_settings() // Note: OpenGL ES 2.0 is not guaranteed to provide depth textures, // which we would need for PP. settings->setDefault("enable_post_processing", "false"); + // still set these two settings in case someone wants to enable it settings->setDefault("debanding", "false"); + settings->setDefault("post_processing_texture_bits", "8"); settings->setDefault("curl_verify_cert", "false"); // Apply settings according to screen size