Skip to content

Commit 7aa30e3

Browse files
committed
Add LightmapGI min light setting (from godotengine#50572)
1 parent 3eeafec commit 7aa30e3

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

doc/classes/LightmapGI.xml

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<member name="environment_custom_sky" type="Sky" setter="set_environment_custom_sky" getter="get_environment_custom_sky">
4848
The sky to use as a source of environment lighting. Only effective if [member environment_mode] is [constant ENVIRONMENT_MODE_CUSTOM_SKY].
4949
</member>
50+
<member name="environment_min_light" type="Color" setter="set_environment_min_light" getter="get_environment_min_light" default="Color(0, 0, 0, 1)">
51+
The minimum ambient light to use for all the lightmap texels. This doesn't take into account any occlusion from the scene's geometry, it simply ensures a minimum amount of light on all the lightmap texels. This can be used to avoid overly dark areas or for artistic control on shadow color. However, colors that are too bright will result in dull-looking shadows.
52+
[b]Note:[/b] After changing [member environment_min_light], the lightmap must be baked again for the changes to be visible.
53+
</member>
5054
<member name="environment_mode" type="int" setter="set_environment_mode" getter="get_environment_mode" enum="LightmapGI.EnvironmentMode" default="1">
5155
The environment mode to use when baking lightmaps.
5256
</member>

scene/3d/lightmap_gi.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,20 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
11651165

11661166
config->save(texture_path + ".import");
11671167

1168+
if (!environment_min_light.is_equal_approx(Color(0, 0, 0))) {
1169+
// Apply minimum lighting to avoid overly dark areas, if requested by the user.
1170+
for (int j = 0; j < texture_image->get_height(); j++) {
1171+
for (int k = 0; k < texture_image->get_width(); k++) {
1172+
Color c = texture_image->get_pixel(k, j);
1173+
c.r = MAX(c.r, environment_min_light.r);
1174+
c.g = MAX(c.g, environment_min_light.g);
1175+
c.b = MAX(c.b, environment_min_light.b);
1176+
1177+
texture_image->set_pixel(k, j, c);
1178+
}
1179+
}
1180+
}
1181+
11681182
Error err = texture_image->save_exr(texture_path, false);
11691183
ERR_FAIL_COND_V(err, BAKE_ERROR_CANT_CREATE_IMAGE);
11701184
ResourceLoader::import(texture_path);
@@ -1517,6 +1531,14 @@ float LightmapGI::get_environment_custom_energy() const {
15171531
return environment_custom_energy;
15181532
}
15191533

1534+
void LightmapGI::set_environment_min_light(Color p_min_light) {
1535+
environment_min_light = p_min_light;
1536+
}
1537+
1538+
Color LightmapGI::get_environment_min_light() const {
1539+
return environment_min_light;
1540+
}
1541+
15201542
void LightmapGI::set_bounces(int p_bounces) {
15211543
ERR_FAIL_COND(p_bounces < 0 || p_bounces > 16);
15221544
bounces = p_bounces;
@@ -1642,6 +1664,9 @@ void LightmapGI::_bind_methods() {
16421664
ClassDB::bind_method(D_METHOD("set_texel_scale", "texel_scale"), &LightmapGI::set_texel_scale);
16431665
ClassDB::bind_method(D_METHOD("get_texel_scale"), &LightmapGI::get_texel_scale);
16441666

1667+
ClassDB::bind_method(D_METHOD("set_environment_min_light", "min_light"), &LightmapGI::set_environment_min_light);
1668+
ClassDB::bind_method(D_METHOD("get_environment_min_light"), &LightmapGI::get_environment_min_light);
1669+
16451670
ClassDB::bind_method(D_METHOD("set_max_texture_size", "max_texture_size"), &LightmapGI::set_max_texture_size);
16461671
ClassDB::bind_method(D_METHOD("get_max_texture_size"), &LightmapGI::get_max_texture_size);
16471672

@@ -1687,6 +1712,7 @@ void LightmapGI::_bind_methods() {
16871712
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "environment_custom_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_environment_custom_color", "get_environment_custom_color");
16881713
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "environment_custom_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_environment_custom_energy", "get_environment_custom_energy");
16891714
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_attributes", PROPERTY_HINT_RESOURCE_TYPE, "CameraAttributesPractical,CameraAttributesPhysical"), "set_camera_attributes", "get_camera_attributes");
1715+
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "environment_min_light", PROPERTY_HINT_COLOR_NO_ALPHA), "set_environment_min_light", "get_environment_min_light");
16901716
ADD_GROUP("Gen Probes", "generate_probes_");
16911717
ADD_PROPERTY(PropertyInfo(Variant::INT, "generate_probes_subdiv", PROPERTY_HINT_ENUM, "Disabled,4,8,16,32"), "set_generate_probes", "get_generate_probes");
16921718
ADD_GROUP("Data", "");

scene/3d/lightmap_gi.h

+5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ class LightmapGI : public VisualInstance3D {
167167
Ref<Sky> environment_custom_sky;
168168
Color environment_custom_color = Color(1, 1, 1);
169169
float environment_custom_energy = 1.0;
170+
Color environment_min_light = Color(0.0, 0.0, 0.0);
170171
bool directional = false;
171172
bool use_texture_for_bounces = true;
172173
GenerateProbes gen_probes = GENERATE_PROBES_SUBDIV_8;
@@ -281,6 +282,10 @@ class LightmapGI : public VisualInstance3D {
281282
void set_environment_custom_energy(float p_energy);
282283
float get_environment_custom_energy() const;
283284

285+
286+
void set_environment_min_light(Color p_min_light);
287+
Color get_environment_min_light() const;
288+
284289
void set_bounces(int p_bounces);
285290
int get_bounces() const;
286291

0 commit comments

Comments
 (0)