negative_bloom

This commit is contained in:
Green Sky 2023-05-11 02:12:05 +02:00
parent 0abb860185
commit 1722f61250
No known key found for this signature in database
5 changed files with 68 additions and 16 deletions

View File

@ -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);

View File

@ -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));
})")
}

View File

@ -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);

View File

@ -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<MM::Services::SDLService>();
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
@ -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<MM::Components::Position2D>(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<MM::Components::Position2D>(e);
p.pos.x = i * 9.f - 40;
// zoffset is created by event
auto& s = scene.emplace<MM::Components::Scale2D>(e);
s.scale = {5,5};
scene.emplace<MM::Components::Rotation2D>(e);
auto& v = scene.emplace<MM::Components::Velocity2DRotation>(e);
v.rot_vel = i * 0.3f;
auto& col = scene.emplace<MM::Components::Color>(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<MM::Components::Position2D>(e);
p.pos.y = 30.f;
p.pos.x = 25.f;
auto& s = scene.emplace<MM::Components::Scale2D>(e);
s.scale = {50,150};
auto& col = scene.emplace<MM::Components::Color>(e);
col.color = {1.f, 1.f, 1.f, 1.f};
}
engine.run();
#ifndef __EMSCRIPTEN__
engine.cleanup();
#endif
}
int main(int argc, char** argv) {

View File

@ -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