Skip to content

Commit ea0ab44

Browse files
committed
Merge pull request #83861 from Calinou/lightmapgi-fix-editor-only-sky-only
Fix LightmapGI taking editor-only and sky-only lights into account
2 parents 2dc932e + e4d8463 commit ea0ab44

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/classes/Light3D.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
[b]Note:[/b] Only effective for [OmniLight3D] and [SpotLight3D], and only when [member shadow_enabled] is [code]true[/code].
5353
</member>
5454
<member name="editor_only" type="bool" setter="set_editor_only" getter="is_editor_only" default="false">
55-
If [code]true[/code], the light only appears in the editor and will not be visible at runtime.
55+
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].
5656
</member>
5757
<member name="light_angular_distance" type="float" setter="set_param" getter="get_param" default="0.0">
5858
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 @@
203203
</constant>
204204
<constant name="BAKE_STATIC" value="1" enum="BakeMode">
205205
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.
206+
[b]Note:[/b] The light is not baked in [LightmapGI] if [member editor_only] is [code]true[/code].
206207
</constant>
207208
<constant name="BAKE_DYNAMIC" value="2" enum="BakeMode">
208209
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].

doc/classes/LightmapGI.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
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.
3333
</member>
3434
<member name="directional" type="bool" setter="set_directional" getter="is_directional" default="false">
35-
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.
35+
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.
3636
[b]Note:[/b] The property's name has no relationship with [DirectionalLight3D]. [member directional] works with all light types.
3737
</member>
3838
<member name="environment_custom_color" type="Color" setter="set_environment_custom_color" getter="get_environment_custom_color">

scene/3d/lightmap_gi.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,12 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
995995
}
996996
for (int i = 0; i < lights_found.size(); i++) {
997997
Light3D *light = lights_found[i].light;
998+
if (light->is_editor_only()) {
999+
// Don't include editor-only lights in the lightmap bake,
1000+
// as this results in inconsistent visuals when running the project.
1001+
continue;
1002+
}
1003+
9981004
Transform3D xf = lights_found[i].xform;
9991005

10001006
// 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
10081014

10091015
if (Object::cast_to<DirectionalLight3D>(light)) {
10101016
DirectionalLight3D *l = Object::cast_to<DirectionalLight3D>(light);
1011-
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));
1017+
if (l->get_sky_mode() != DirectionalLight3D::SKY_MODE_SKY_ONLY) {
1018+
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));
1019+
}
10121020
} else if (Object::cast_to<OmniLight3D>(light)) {
10131021
OmniLight3D *l = Object::cast_to<OmniLight3D>(light);
10141022
if (use_physical_light_units) {

0 commit comments

Comments
 (0)