2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2012-06-08 16:17:57 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/particles.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/mesh.h"
|
|
|
|
|
#include "scene/object.h"
|
2012-08-31 17:27:08 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "blender/sync.h"
|
|
|
|
|
#include "blender/util.h"
|
2012-06-08 16:17:57 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Utilities */
|
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
bool BlenderSync::sync_dupli_particle(BL::Object &b_ob,
|
2018-05-30 15:21:21 +02:00
|
|
|
BL::DepsgraphObjectInstance &b_instance,
|
2016-01-30 14:18:29 +01:00
|
|
|
Object *object)
|
2012-08-31 17:27:08 +00:00
|
|
|
{
|
2021-02-05 16:23:34 +11:00
|
|
|
/* Test if this dupli was generated from a particle system. */
|
2018-05-30 15:21:21 +02:00
|
|
|
BL::ParticleSystem b_psys = b_instance.particle_system();
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!b_psys) {
|
2012-11-08 16:35:28 +00:00
|
|
|
return false;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_hide_on_missing_motion(true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* test if we need particle data */
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!object->get_geometry()->need_attribute(scene, ATTR_STD_PARTICLE)) {
|
2012-11-08 16:35:28 +00:00
|
|
|
return false;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* don't handle child particles yet */
|
2018-05-30 15:21:21 +02:00
|
|
|
BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id = b_instance.persistent_id();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (persistent_id[0] >= b_psys.particles.length()) {
|
2012-11-08 16:35:28 +00:00
|
|
|
return false;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* find particle system */
|
|
|
|
|
ParticleSystemKey key(b_ob, persistent_id);
|
|
|
|
|
ParticleSystem *psys;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
bool first_use = !particle_system_map.is_used(key);
|
2020-10-29 14:40:29 +01:00
|
|
|
bool need_update = particle_system_map.add_or_update(&psys, b_ob, b_instance.object(), key);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* no update needed? */
|
2020-11-04 11:17:38 +01:00
|
|
|
if (!need_update && !object->get_geometry()->is_modified() &&
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
!scene->object_manager->need_update())
|
2023-09-17 09:01:48 +10:00
|
|
|
{
|
2012-11-08 16:35:28 +00:00
|
|
|
return true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* first time used in this sync loop? clear and tag update */
|
|
|
|
|
if (first_use) {
|
2012-08-31 17:27:08 +00:00
|
|
|
psys->particles.clear();
|
2012-08-31 19:39:03 +00:00
|
|
|
psys->tag_update(scene);
|
2012-06-08 16:17:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* add particle */
|
|
|
|
|
BL::Particle b_pa = b_psys.particles[persistent_id[0]];
|
2024-07-22 09:52:19 +02:00
|
|
|
Particle pa;
|
2024-07-22 09:54:02 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
pa.index = persistent_id[0];
|
2021-08-13 13:31:21 +02:00
|
|
|
pa.age = b_scene.frame_current_final() - b_pa.birth_time();
|
2012-11-08 16:35:28 +00:00
|
|
|
pa.lifetime = b_pa.lifetime();
|
|
|
|
|
pa.location = get_float3(b_pa.location());
|
|
|
|
|
pa.rotation = get_float4(b_pa.rotation());
|
|
|
|
|
pa.size = b_pa.size();
|
|
|
|
|
pa.velocity = get_float3(b_pa.velocity());
|
|
|
|
|
pa.angular_velocity = get_float3(b_pa.angular_velocity());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
psys->particles.push_back_slow(pa);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_particle_system(psys);
|
|
|
|
|
object->set_particle_index(psys->particles.size() - 1);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (object->particle_index_is_modified()) {
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
scene->object_manager->tag_update(scene, ObjectManager::PARTICLE_MODIFIED);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* return that this object has particle data */
|
|
|
|
|
return true;
|
2012-06-08 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|