From b20b4218d55a3dfae56e48f375fbe727f41ccc60 Mon Sep 17 00:00:00 2001 From: Weizhen Huang Date: Wed, 2 Apr 2025 16:58:03 +0200 Subject: [PATCH] Cycles: Always add world as object but only enable the light when the world is used for NEE. World object index will be needed for volume stack. --- intern/cycles/blender/light.cpp | 84 +++++++++++++++++---------------- intern/cycles/scene/light.cpp | 4 ++ 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/intern/cycles/blender/light.cpp b/intern/cycles/blender/light.cpp index 2a552ff1c93..85e4c29826e 100644 --- a/intern/cycles/blender/light.cpp +++ b/intern/cycles/blender/light.cpp @@ -128,56 +128,58 @@ void BlenderSync::sync_background_light(BL::SpaceView3D &b_v3d) cworld, "sampling_method", SAMPLING_NUM, SAMPLING_AUTOMATIC); const bool sample_as_light = (sampling_method != SAMPLING_NONE); - if (sample_as_light || world_use_portal) { - /* Create object. */ - Object *object; - const ObjectKey object_key(b_world, nullptr, b_world, false); - bool update = object_map.add_or_update(&object, b_world, b_world, object_key); - if (update) { - /* Lights should be shadow catchers by default. */ - object->set_is_shadow_catcher(true); - object->set_lightgroup(ustring(b_world ? b_world.lightgroup() : "")); - } + /* Create object. */ + Object *object; + const ObjectKey object_key(b_world, nullptr, b_world, false); + bool update = object_map.add_or_update(&object, b_world, b_world, object_key); + if (update) { + /* Lights should be shadow catchers by default. */ + object->set_is_shadow_catcher(true); + object->set_lightgroup(ustring(b_world ? b_world.lightgroup() : "")); + } - /* Create geometry. */ - const GeometryKey geom_key{b_world.ptr.data, Geometry::LIGHT}; - Geometry *geom = geometry_map.find(geom_key); - if (geom) { - update |= geometry_map.update(geom, b_world); + /* Create geometry. */ + const GeometryKey geom_key{b_world.ptr.data, Geometry::LIGHT}; + Geometry *geom = geometry_map.find(geom_key); + if (geom) { + update |= geometry_map.update(geom, b_world); + } + else { + geom = scene->create_node(); + geometry_map.add(geom_key, geom); + object->set_geometry(geom); + update = true; + } + + if (update || world_recalc || b_world.ptr.data != world_map) { + /* Initialize light geometry. */ + Light *light = static_cast(geom); + + array used_shaders; + used_shaders.push_back_slow(scene->default_background); + light->set_used_shaders(used_shaders); + + light->set_light_type(LIGHT_BACKGROUND); + + if (sampling_method == SAMPLING_MANUAL) { + light->set_map_resolution(get_int(cworld, "sample_map_resolution")); } else { - geom = scene->create_node(); - geometry_map.add(geom_key, geom); - object->set_geometry(geom); - update = true; + light->set_map_resolution(0); } - if (update || world_recalc || b_world.ptr.data != world_map) { - /* Initialize light geometry. */ - Light *light = static_cast(geom); + light->set_use_mis(sample_as_light); + light->set_max_bounces(get_int(cworld, "max_bounces")); - light->set_light_type(LIGHT_BACKGROUND); - if (sampling_method == SAMPLING_MANUAL) { - light->set_map_resolution(get_int(cworld, "sample_map_resolution")); - } - else { - light->set_map_resolution(0); - } - array used_shaders; - used_shaders.push_back_slow(scene->default_background); - light->set_used_shaders(used_shaders); - light->set_use_mis(sample_as_light); - light->set_max_bounces(get_int(cworld, "max_bounces")); + /* Force enable light again when world is resynced. */ + light->set_is_enabled(sample_as_light || world_use_portal); - /* force enable light again when world is resynced */ - light->set_is_enabled(true); + /* Caustic light. */ + light->set_use_caustics(get_boolean(cworld, "is_caustics_light")); - /* caustic light */ - light->set_use_caustics(get_boolean(cworld, "is_caustics_light")); + light->tag_update(scene); - light->tag_update(scene); - geometry_map.set_recalc(b_world); - } + geometry_map.set_recalc(b_world); } } diff --git a/intern/cycles/scene/light.cpp b/intern/cycles/scene/light.cpp index d69f512c820..46dad00cf1d 100644 --- a/intern/cycles/scene/light.cpp +++ b/intern/cycles/scene/light.cpp @@ -264,6 +264,10 @@ void LightManager::test_enabled_lights(Scene *scene) } Light *light = static_cast(object->get_geometry()); + if (!light->is_enabled) { + continue; + } + light->is_enabled = light->has_contribution(scene, object); has_portal |= light->is_portal;