mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Fix bloom with post_processing_texture_bits < 16
This commit is contained in:
		@@ -6,6 +6,7 @@
 | 
			
		||||
#include "client/client.h"
 | 
			
		||||
#include "client/hud.h"
 | 
			
		||||
#include "IRenderTarget.h"
 | 
			
		||||
#include "SColor.h"
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <memory>
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user