@@ -1165,6 +1165,20 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
1165
1165
1166
1166
config->save (texture_path + " .import" );
1167
1167
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
+
1168
1182
Error err = texture_image->save_exr (texture_path, false );
1169
1183
ERR_FAIL_COND_V (err, BAKE_ERROR_CANT_CREATE_IMAGE);
1170
1184
ResourceLoader::import (texture_path);
@@ -1517,6 +1531,14 @@ float LightmapGI::get_environment_custom_energy() const {
1517
1531
return environment_custom_energy;
1518
1532
}
1519
1533
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
+
1520
1542
void LightmapGI::set_bounces (int p_bounces) {
1521
1543
ERR_FAIL_COND (p_bounces < 0 || p_bounces > 16 );
1522
1544
bounces = p_bounces;
@@ -1642,6 +1664,9 @@ void LightmapGI::_bind_methods() {
1642
1664
ClassDB::bind_method (D_METHOD (" set_texel_scale" , " texel_scale" ), &LightmapGI::set_texel_scale);
1643
1665
ClassDB::bind_method (D_METHOD (" get_texel_scale" ), &LightmapGI::get_texel_scale);
1644
1666
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
+
1645
1670
ClassDB::bind_method (D_METHOD (" set_max_texture_size" , " max_texture_size" ), &LightmapGI::set_max_texture_size);
1646
1671
ClassDB::bind_method (D_METHOD (" get_max_texture_size" ), &LightmapGI::get_max_texture_size);
1647
1672
@@ -1687,6 +1712,7 @@ void LightmapGI::_bind_methods() {
1687
1712
ADD_PROPERTY (PropertyInfo (Variant::COLOR, " environment_custom_color" , PROPERTY_HINT_COLOR_NO_ALPHA), " set_environment_custom_color" , " get_environment_custom_color" );
1688
1713
ADD_PROPERTY (PropertyInfo (Variant::FLOAT, " environment_custom_energy" , PROPERTY_HINT_RANGE, " 0,64,0.01" ), " set_environment_custom_energy" , " get_environment_custom_energy" );
1689
1714
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" );
1690
1716
ADD_GROUP (" Gen Probes" , " generate_probes_" );
1691
1717
ADD_PROPERTY (PropertyInfo (Variant::INT, " generate_probes_subdiv" , PROPERTY_HINT_ENUM, " Disabled,4,8,16,32" ), " set_generate_probes" , " get_generate_probes" );
1692
1718
ADD_GROUP (" Data" , " " );
0 commit comments