From 1722f6125096223a83910d46076b0db74ad02f20 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 11 May 2023 02:12:05 +0200 Subject: [PATCH] negative_bloom --- .../opengl_renderer/src/mm/opengl/bloom.cpp | 24 +++++++---- .../opengl/render_tasks/bloom_extraction.cpp | 10 ++++- .../mm/opengl/render_tasks/composition.cpp | 2 +- .../test/hdr_bloom_pipeline_example.cpp | 41 ++++++++++++++++++- .../src/mm/services/sdl_service.cpp | 7 ++-- 5 files changed, 68 insertions(+), 16 deletions(-) diff --git a/framework/opengl_renderer/src/mm/opengl/bloom.cpp b/framework/opengl_renderer/src/mm/opengl/bloom.cpp index a99017d..77a01f8 100644 --- a/framework/opengl_renderer/src/mm/opengl/bloom.cpp +++ b/framework/opengl_renderer/src/mm/opengl/bloom.cpp @@ -29,14 +29,20 @@ void setup_bloom( const auto bloom_internal_format = GL_RGB565; // prolly fine. NOPE its not. it causes green pixely halos const auto bloom_format_type = GL_UNSIGNED_BYTE; #else - //const auto bloom_internal_format = GL_RGBA16F; - const auto bloom_internal_format = GL_R11F_G11F_B10F; - const auto bloom_format_type = GL_FLOAT; + const auto bloom_format_type = GL_RGBA; + const auto bloom_internal_format = GL_RGBA16F; + //const auto bloom_internal_format = GL_R11F_G11F_B10F; + const auto bloom_data_type = GL_FLOAT; + + //const auto bloom_format_type = GL_RGBA_INTEGER; + //const auto bloom_internal_format = GL_RGBA16I; + //const auto bloom_data_type = GL_SHORT; #endif #else - //const auto bloom_internal_format = GL_RGB16F; - const auto bloom_internal_format = GL_R11F_G11F_B10F; - const auto bloom_format_type = GL_FLOAT; + const auto bloom_format_type = GL_RGB; + const auto bloom_internal_format = GL_RGB16F; // opengl silently upgrades to RGBA + //const auto bloom_internal_format = GL_R11F_G11F_B10F; // no sign + const auto bloom_data_type = GL_FLOAT; #endif { // bloom in (bloom extraction) @@ -44,7 +50,7 @@ void setup_bloom( "bloom_in", bloom_internal_format, w * bloom_in_scale, h * bloom_in_scale, - GL_RGB, bloom_format_type + bloom_format_type, bloom_data_type ); { // filter rm_t.get("bloom_in"_hs)->bind(0); @@ -72,7 +78,7 @@ void setup_bloom( tex_out_id, bloom_internal_format, w * bloom_in_scale * glm::pow(bloom_phase_scale, i), h * bloom_in_scale * glm::pow(bloom_phase_scale, i), - GL_RGB, bloom_format_type + bloom_format_type, bloom_data_type ); { // filter rm_t.get(tex_out_id)->bind(0); @@ -89,7 +95,7 @@ void setup_bloom( tex_tmp_id, bloom_internal_format, w * bloom_in_scale * glm::pow(bloom_phase_scale, i), h * bloom_in_scale * glm::pow(bloom_phase_scale, i), - GL_RGB, bloom_format_type + bloom_format_type, bloom_data_type ); { // filter rm_t.get(tex_tmp_id)->bind(0); diff --git a/framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_extraction.cpp b/framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_extraction.cpp index 3975a62..2e33e47 100644 --- a/framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_extraction.cpp +++ b/framework/opengl_renderer/src/mm/opengl/render_tasks/bloom_extraction.cpp @@ -106,7 +106,15 @@ void main() { vec3 color = texture(color_tex, _uv).rgb; // TODO: expose threshold - _out_color = max(vec3(0.0), color - vec3(1.0)); + //_out_color = max(vec3(0.0), color - vec3(1.0)); + + //_out_color = mix( + //color, // < 0.0 + //max(vec3(0.0), color - vec3(1.0)), // > 0.0 + //step(vec3(0.0), color) + //); + + _out_color = max(min(color, vec3(0.0)), color - vec3(1.0)); })") } diff --git a/framework/opengl_renderer/src/mm/opengl/render_tasks/composition.cpp b/framework/opengl_renderer/src/mm/opengl/render_tasks/composition.cpp index 6fed3d9..cce11a2 100644 --- a/framework/opengl_renderer/src/mm/opengl/render_tasks/composition.cpp +++ b/framework/opengl_renderer/src/mm/opengl/render_tasks/composition.cpp @@ -141,7 +141,7 @@ void main() { vec3 color = texture(color_tex, _uv).rgb; vec3 bloom = texture(bloom_tex, _uv).rgb; - vec3 comp = color + bloom * vec3(bloom_factor); + vec3 comp = max(vec3(0.0), color + bloom * vec3(bloom_factor)); #if 0 const vec3 tint = vec3(1.5, 0.8, 1.1); diff --git a/framework/opengl_renderer/test/hdr_bloom_pipeline_example.cpp b/framework/opengl_renderer/test/hdr_bloom_pipeline_example.cpp index dfd0b88..f47dd7d 100644 --- a/framework/opengl_renderer/test/hdr_bloom_pipeline_example.cpp +++ b/framework/opengl_renderer/test/hdr_bloom_pipeline_example.cpp @@ -129,8 +129,9 @@ static void setup_fbos(MM::Engine& engine) { assert(rs.targets["game_view"]); } +static MM::Engine engine; + TEST(hdr_bloom_pipeline, it) { - MM::Engine engine; auto& sdl_ss = engine.addService(); ASSERT_TRUE(engine.enableService()); @@ -228,7 +229,7 @@ TEST(hdr_bloom_pipeline, it) { col.color = {3.f, 3.f, 3.f, 1.f}; } - for (int i = 0; i < 10; i++) { + for (int i = 0; i < 5; i++) { auto e = scene.create(); auto& p = scene.emplace(e); p.pos.x = i * 9.f - 40; @@ -247,7 +248,43 @@ TEST(hdr_bloom_pipeline, it) { col.color = {rng.zeroToOne()*2.f, rng.zeroToOne()*2.f, rng.zeroToOne()*2.f, 1.f}; } + for (int i = 5; i < 10; i++) { + auto e = scene.create(); + auto& p = scene.emplace(e); + p.pos.x = i * 9.f - 40; + + // zoffset is created by event + + auto& s = scene.emplace(e); + s.scale = {5,5}; + + scene.emplace(e); + + auto& v = scene.emplace(e); + v.rot_vel = i * 0.3f; + + auto& col = scene.emplace(e); + col.color = {rng.zeroToOne()*-2.f, rng.zeroToOne()*-2.f, rng.zeroToOne()*-2.f, 1.f}; + } + + { // white background for negatives + auto e = scene.create(); + auto& p = scene.emplace(e); + p.pos.y = 30.f; + p.pos.x = 25.f; + + auto& s = scene.emplace(e); + s.scale = {50,150}; + + auto& col = scene.emplace(e); + col.color = {1.f, 1.f, 1.f, 1.f}; + } + engine.run(); + +#ifndef __EMSCRIPTEN__ + engine.cleanup(); +#endif } int main(int argc, char** argv) { diff --git a/framework/sdl_service/src/mm/services/sdl_service.cpp b/framework/sdl_service/src/mm/services/sdl_service.cpp index 103a80a..f936591 100644 --- a/framework/sdl_service/src/mm/services/sdl_service.cpp +++ b/framework/sdl_service/src/mm/services/sdl_service.cpp @@ -31,9 +31,10 @@ namespace MM::Services { SDLService::SDLService(uint32_t _sdl_init_flags) { MM::Logger::initSectionLogger("SDLService"); -//#ifdef __EMSCRIPTEN__ - //_sdl_init_flags &= ~SDL_INIT_HAPTIC; -//#endif +#ifdef __EMSCRIPTEN__ + _sdl_init_flags &= ~SDL_INIT_HAPTIC; +#endif + #if 1 // hack for mingw + wine _sdl_init_flags &= ~SDL_INIT_SENSOR; #endif