Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Environment Min Light property to LightmapGI #50572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/classes/LightmapGI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<member name="environment_custom_sky" type="Sky" setter="set_environment_custom_sky" getter="get_environment_custom_sky">
The sky to use as a source of environment lighting. Only effective if [member environment_mode] is [constant ENVIRONMENT_MODE_CUSTOM_SKY].
</member>
<member name="environment_min_light" type="Color" setter="set_environment_min_light" getter="get_environment_min_light" default="Color(0, 0, 0, 1)">
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.
[b]Note:[/b] After changing [member environment_min_light], the lightmap must be baked again for the changes to be visible.
</member>
<member name="environment_mode" type="int" setter="set_environment_mode" getter="get_environment_mode" enum="LightmapGI.EnvironmentMode" default="1">
The environment mode to use when baking lightmaps.
</member>
Expand Down
26 changes: 26 additions & 0 deletions scene/3d/lightmap_gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,20 @@

config->save(config_path);

if (!environment_min_light.is_equal_approx(Color(0, 0, 0))) {
// Apply minimum lighting to avoid overly dark areas, if requested by the user.
for (int i = 0; i < texture_image->get_height(); i++) {

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

declaration of 'i' shadows a previous local [-Werror=shadow]

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

declaration of 'i' shadows a previous local [-Werror=shadow]

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

declaration of 'i' shadows a previous local [-Werror=shadow]

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

the following warning is treated as an error

Check warning on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

declaration of 'i' hides previous local declaration

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

the following warning is treated as an error

Check warning on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

declaration of 'i' hides previous local declaration

Check failure on line 794 in scene/3d/lightmap_gi.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

declaration of 'i' shadows a previous local [-Werror=shadow]
for (int j = 0; j < texture_image->get_width(); j++) {
Color c = texture_image->get_pixel(j, i);
c.r = MAX(c.r, environment_min_light.r);
c.g = MAX(c.g, environment_min_light.g);
c.b = MAX(c.b, environment_min_light.b);

texture_image->set_pixel(j, i, c);
}
}
}

// Save the file.
Error save_err = texture_image->save_exr(atlas_path, false);

Expand Down Expand Up @@ -1553,6 +1567,14 @@
return environment_custom_energy;
}

void LightmapGI::set_environment_min_light(Color p_min_light) {
environment_min_light = p_min_light;
}

Color LightmapGI::get_environment_min_light() const {
return environment_min_light;
}

void LightmapGI::set_bounces(int p_bounces) {
ERR_FAIL_COND(p_bounces < 0 || p_bounces > 16);
bounces = p_bounces;
Expand Down Expand Up @@ -1681,6 +1703,9 @@
ClassDB::bind_method(D_METHOD("set_environment_custom_energy", "energy"), &LightmapGI::set_environment_custom_energy);
ClassDB::bind_method(D_METHOD("get_environment_custom_energy"), &LightmapGI::get_environment_custom_energy);

ClassDB::bind_method(D_METHOD("set_environment_min_light", "min_light"), &LightmapGI::set_environment_min_light);
ClassDB::bind_method(D_METHOD("get_environment_min_light"), &LightmapGI::get_environment_min_light);

ClassDB::bind_method(D_METHOD("set_texel_scale", "texel_scale"), &LightmapGI::set_texel_scale);
ClassDB::bind_method(D_METHOD("get_texel_scale"), &LightmapGI::get_texel_scale);

Expand Down Expand Up @@ -1728,6 +1753,7 @@
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment_custom_sky", PROPERTY_HINT_RESOURCE_TYPE, "Sky"), "set_environment_custom_sky", "get_environment_custom_sky");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "environment_custom_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_environment_custom_color", "get_environment_custom_color");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "environment_custom_energy", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_environment_custom_energy", "get_environment_custom_energy");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "environment_min_light", PROPERTY_HINT_COLOR_NO_ALPHA), "set_environment_min_light", "get_environment_min_light");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_attributes", PROPERTY_HINT_RESOURCE_TYPE, "CameraAttributesPractical,CameraAttributesPhysical"), "set_camera_attributes", "get_camera_attributes");
ADD_GROUP("Gen Probes", "generate_probes_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "generate_probes_subdiv", PROPERTY_HINT_ENUM, "Disabled,4,8,16,32"), "set_generate_probes", "get_generate_probes");
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/lightmap_gi.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class LightmapGI : public VisualInstance3D {
Ref<Sky> environment_custom_sky;
Color environment_custom_color = Color(1, 1, 1);
float environment_custom_energy = 1.0;
Color environment_min_light = Color(0.0, 0.0, 0.0);
bool directional = false;
bool use_texture_for_bounces = true;
GenerateProbes gen_probes = GENERATE_PROBES_SUBDIV_8;
Expand Down Expand Up @@ -293,6 +294,9 @@ class LightmapGI : public VisualInstance3D {
void set_environment_custom_energy(float p_energy);
float get_environment_custom_energy() const;

void set_environment_min_light(Color p_min_light);
Color get_environment_min_light() const;

void set_bounces(int p_bounces);
int get_bounces() const;

Expand Down
Loading