From e4d846378b0159016b207bcb0f73e5a2e700c858 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 23 Oct 2023 22:56:17 +0200 Subject: [PATCH] Fix LightmapGI taking editor-only and sky-only lights into account These lights are not visible when running the project (or at all), so they shouldn't affect the lightmap baking process. --- doc/classes/Light3D.xml | 3 ++- doc/classes/LightmapGI.xml | 2 +- scene/3d/lightmap_gi.cpp | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/classes/Light3D.xml b/doc/classes/Light3D.xml index ebb36ba92bee..d0bc7926ca55 100644 --- a/doc/classes/Light3D.xml +++ b/doc/classes/Light3D.xml @@ -52,7 +52,7 @@ [b]Note:[/b] Only effective for [OmniLight3D] and [SpotLight3D], and only when [member shadow_enabled] is [code]true[/code]. - If [code]true[/code], the light only appears in the editor and will not be visible at runtime. + If [code]true[/code], the light only appears in the editor and will not be visible at runtime. If [code]true[/code], the light will never be baked in [LightmapGI] regardless of its [member light_bake_mode]. The light's angular size in degrees. Increasing this will make shadows softer at greater distances (also called percentage-closer soft shadows, or PCSS). Only available for [DirectionalLight3D]s. For reference, the Sun from the Earth is approximately [code]0.5[/code]. Increasing this value above [code]0.0[/code] for lights with shadows enabled will have a noticeable performance cost due to PCSS. @@ -203,6 +203,7 @@ Light is taken into account in static baking ([VoxelGI], [LightmapGI], SDFGI ([member Environment.sdfgi_enabled])). The light can be moved around or modified, but its global illumination will not update in real-time. This is suitable for subtle changes (such as flickering torches), but generally not large changes such as toggling a light on and off. + [b]Note:[/b] The light is not baked in [LightmapGI] if [member editor_only] is [code]true[/code]. Light is taken into account in dynamic baking ([VoxelGI] and SDFGI ([member Environment.sdfgi_enabled]) only). The light can be moved around or modified with global illumination updating in real-time. The light's global illumination appearance will be slightly different compared to [constant BAKE_STATIC]. This has a greater performance cost compared to [constant BAKE_STATIC]. When using SDFGI, the update speed of dynamic lights is affected by [member ProjectSettings.rendering/global_illumination/sdfgi/frames_to_update_lights]. diff --git a/doc/classes/LightmapGI.xml b/doc/classes/LightmapGI.xml index e11125133675..ec75d85898f7 100644 --- a/doc/classes/LightmapGI.xml +++ b/doc/classes/LightmapGI.xml @@ -32,7 +32,7 @@ The strength of denoising step applied to the generated lightmaps. Only effective if [member use_denoiser] is [code]true[/code] and [member ProjectSettings.rendering/lightmapping/denoising/denoiser] is set to JNLM. - If [code]true[/code], bakes lightmaps to contain directional information as spherical harmonics. This results in more realistic lighting appearance, especially with normal mapped materials and for lights that have their direct light baked ([member Light3D.light_bake_mode] set to [constant Light3D.BAKE_STATIC]). The directional information is also used to provide rough reflections for static and dynamic objects. This has a small run-time performance cost as the shader has to perform more work to interpret the direction information from the lightmap. Directional lightmaps also take longer to bake and result in larger file sizes. + If [code]true[/code], bakes lightmaps to contain directional information as spherical harmonics. This results in more realistic lighting appearance, especially with normal mapped materials and for lights that have their direct light baked ([member Light3D.light_bake_mode] set to [constant Light3D.BAKE_STATIC] and with [member Light3D.editor_only] set to [code]false[/code]). The directional information is also used to provide rough reflections for static and dynamic objects. This has a small run-time performance cost as the shader has to perform more work to interpret the direction information from the lightmap. Directional lightmaps also take longer to bake and result in larger file sizes. [b]Note:[/b] The property's name has no relationship with [DirectionalLight3D]. [member directional] works with all light types. diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index fe1b10a31f35..5175363538f0 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -995,6 +995,12 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa } for (int i = 0; i < lights_found.size(); i++) { Light3D *light = lights_found[i].light; + if (light->is_editor_only()) { + // Don't include editor-only lights in the lightmap bake, + // as this results in inconsistent visuals when running the project. + continue; + } + Transform3D xf = lights_found[i].xform; // For the lightmapper, the indirect energy represents the multiplier for the indirect bounces caused by the light, so the value is not converted when using physical units. @@ -1008,7 +1014,9 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa if (Object::cast_to(light)) { DirectionalLight3D *l = Object::cast_to(light); - lightmapper->add_directional_light(light->get_bake_mode() == Light3D::BAKE_STATIC, -xf.basis.get_column(Vector3::AXIS_Z).normalized(), linear_color, energy, indirect_energy, l->get_param(Light3D::PARAM_SIZE), l->get_param(Light3D::PARAM_SHADOW_BLUR)); + if (l->get_sky_mode() != DirectionalLight3D::SKY_MODE_SKY_ONLY) { + lightmapper->add_directional_light(light->get_bake_mode() == Light3D::BAKE_STATIC, -xf.basis.get_column(Vector3::AXIS_Z).normalized(), linear_color, energy, indirect_energy, l->get_param(Light3D::PARAM_SIZE), l->get_param(Light3D::PARAM_SHADOW_BLUR)); + } } else if (Object::cast_to(light)) { OmniLight3D *l = Object::cast_to(light); if (use_physical_light_units) {