55bool is_valid_input_id(
const ID &
id)
77class LightSetIDManager {
81 explicit LightSetIDManager(
const Scene &scene) : scene_(scene) {}
91 const uint64_t light_set_id = light_set_id_map_.lookup_or_add_cb(light_set, [&]() {
92 const uint64_t new_light_set_id = next_light_set_id_++;
95 printf(
"Maximum number of light linking sets (%d) exceeded scene \"%s\".\n",
100 return new_light_set_id;
147 emitter_data_map_.clear();
148 next_collection_id_ = 0;
155 const Collection *collection = get_collection(emitter);
167 EmitterData &emitter_data = emitter_data_map_.lookup_or_add_cb(collection, [&]() {
168 const uint64_t collection_id = next_collection_id_++;
174 printf(
"Maximum number of light linking collections (%d) exceeded in scene \"%s\".\n",
184 return new_emitter_data;
191 return &emitter_data;
196 const Collection *collection_eval = get_collection(emitter);
198 if (!collection_eval) {
204 return emitter_data_map_.lookup_ptr(collection_orig);
211 const Collection *collection = get_collection(emitter);
217 return emitter_data_map_.contains(collection);
224 light_linked_sets_.clear();
225 object_light_sets_.clear();
232 LightSet &light_set = ensure_light_set_for(
object);
234 switch (link_state) {
251 return light_linked_sets_.lookup_or_add_as(&
object);
254void LinkingData::clear_after_build()
256 light_linked_sets_.clear();
261 LightSetIDManager light_set_id_manager(scene);
263 for (
const auto it : light_linked_sets_.items()) {
264 const Object *receiver = it.key;
268 if (!light_set_id_manager.get(light_set, light_set_id)) {
274 object_light_sets_.add(receiver, light_set_id);
276 update_emitters_membership(emitter_data_map, light_set, light_set_mask);
282void LinkingData::update_emitters_membership(
EmitterDataMap &emitter_data_map,
319 foreach_light_collection_object_inner(
320 collection_light_linking, *collection_child.
collection, callback);
324 callback(collection_light_linking, *collection_object.
ob);
337void foreach_light_collection_object(
const Collection &collection, Proc &&callback)
339 for (
const CollectionChild &collection_child : collection.children) {
340 foreach_light_collection_object_inner(
341 collection_child.light_linking, *collection_child.collection, callback);
344 for (
const CollectionObject &collection_object : collection.gobject) {
345 callback(collection_object.light_linking, *collection_object.ob);
353 light_emitter_data_map_.clear();
354 shadow_emitter_data_map_.clear();
356 light_linking_.clear();
357 shadow_linking_.clear();
364 add_light_linking_emitter(scene, emitter);
365 add_shadow_linking_emitter(scene, emitter);
368void Cache::add_light_linking_emitter(
const Scene &scene,
const Object &emitter)
378 if (light_emitter_data) {
379 foreach_light_collection_object(
382 add_receiver_object(*light_emitter_data, collection_light_linking, receiver);
387void Cache::add_shadow_linking_emitter(
const Scene &scene,
const Object &emitter)
395 const EmitterData *shadow_emitter_data = shadow_emitter_data_map_.ensure_data_if_possible(
397 if (shadow_emitter_data) {
398 foreach_light_collection_object(
399 *emitter.light_linking->blocker_collection,
400 [&](
const CollectionLightLinking &collection_light_linking,
const Object &receiver) {
401 add_blocker_object(*shadow_emitter_data, collection_light_linking, receiver);
406void Cache::add_receiver_object(
const EmitterData &emitter_data,
407 const CollectionLightLinking &collection_light_linking,
408 const Object &receiver)
412 light_linking_.link_object(
416void Cache::add_blocker_object(
const EmitterData &emitter_data,
417 const CollectionLightLinking &collection_light_linking,
418 const Object &blocker)
422 shadow_linking_.link_object(
428 if (!has_light_linking()) {
432 light_linking_.end_build(scene, light_emitter_data_map_);
433 shadow_linking_.end_build(scene, shadow_emitter_data_map_);
441 if (!has_light_linking()) {
457 const EmitterData *light_emitter_data = light_emitter_data_map_.get_data(object_eval);
458 if (light_emitter_data) {
465 const EmitterData *shadow_emitter_data = shadow_emitter_data_map_.get_data(object_eval);
466 if (shadow_emitter_data) {
473 const bool need_runtime = (memcmp(&runtime, &runtime_no_links,
sizeof(runtime)) != 0);
484 else if (need_runtime) {
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
void eval_runtime_data(Object &object_eval) const
void add_emitter(const Scene &scene, const Object &emitter)
void end_build(const Scene &scene)
bool can_skip_emitter(const Object &emitter) const
EmitterData * ensure_data_if_possible(const Scene &scene, const Object &emitter)
MapType::MutableValueIterator values()
const EmitterData * get_data(const Object &emitter) const
static constexpr int MAX_COLLECTION_ID
EmitterSetMembership light_membership
EmitterSetMembership shadow_membership
uint64_t get_mask() const
static constexpr uint64_t SET_MEMBERSHIP_ALL
uint64_t included_sets_mask
uint64_t excluded_sets_mask
uint64_t include_collection_mask
static constexpr int MAX_ID
bool operator==(const LightSet &other) const
uint64_t exclude_collection_mask
static constexpr int DEFAULT_ID
uint64_t get_light_set_for(const Object &object) const
void end_build(const Scene &scene, EmitterDataMap &emitter_data_map)
void link_object(const EmitterData &emitter_data, eCollectionLightLinkingState link_state, const Object &object)
internal::LightSet LightSet
internal::EmitterSetMembership EmitterSetMembership
void eval_runtime_data(const Depsgraph *depsgraph, Object &object_eval)
internal::EmitterData EmitterData
internal::LinkingData LinkingData
internal::EmitterDataMap EmitterDataMap
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
void BKE_light_linking_free_if_empty(struct Object *object)
bool DEG_is_original(const T *id)
eCollectionLightLinkingState
@ COLLECTION_LIGHT_LINKING_STATE_INCLUDE
@ COLLECTION_LIGHT_LINKING_STATE_EXCLUDE
void BKE_light_linking_ensure(struct Object *object)
T * DEG_get_original(T *id)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
struct Collection * collection
ListBaseT< CollectionChild > children
ListBaseT< CollectionObject > gobject
uint8_t blocker_shadow_set
uint8_t receiver_light_set
uint64_t light_set_membership
uint64_t shadow_set_membership
LightLinkingRuntime runtime
struct Collection * receiver_collection
LightLinking * light_linking
light_linking::Cache light_linking_cache