From eb99c7243e552cce191d18a81318ca6bca51030d Mon Sep 17 00:00:00 2001 From: needleful Date: Mon, 20 Jun 2022 16:02:22 -0700 Subject: [PATCH] Apply baked ambient light settings when baking lights with scene environment --- scene/3d/baked_lightmap.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 7927b9d660e..3b4147183b4 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -792,6 +792,20 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_data_sa if (env.is_valid()) { environment_image = _get_irradiance_map(env, Vector2i(128, 64)); environment_xform = get_global_transform().affine_inverse().basis * env->get_sky_orientation(); + + float ambient_sky = env->get_ambient_light_sky_contribution(); + float energy = env->get_ambient_light_energy(); + if (ambient_sky != 1.0 || energy != 1.0) { + Color ambient_light = env->get_ambient_light_color().to_linear() * (1.0 - ambient_sky) * energy; + environment_image->lock(); + for (int i = 0; i < 128; i++) { + for (int j = 0; j < 64; j++) { + Color c = ambient_light + environment_image->get_pixel(i, j) * ambient_sky * energy; + environment_image->set_pixel(i, j, c); + } + } + environment_image->unlock(); + } } } } break;