2023-06-14 08:52:36 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2012-08-31 19:27:08 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/particles.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "device/device.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/scene.h"
|
|
|
|
#include "scene/stats.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/foreach.h"
|
|
|
|
#include "util/hash.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
#include "util/map.h"
|
|
|
|
#include "util/progress.h"
|
|
|
|
#include "util/vector.h"
|
2012-08-31 19:27:08 +02:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Particle System */
|
|
|
|
|
Cycles: introduce an ownership system to protect nodes from unwanted deletions.
Problem: the Blender synchronization process creates and tags nodes for usage. It does
this by directly adding and removing nodes from the scene data. If some node is not tagged
as used at the end of a synchronization, it then deletes the node from the scene. This poses
a problem when it comes to supporting procedural nodes who can create other nodes not known
by the Blender synchonization system, which will remove them.
Nodes now have a NodeOwner, which is set after creation. Those owners for now are the Scene
for scene level nodes and ShaderGraph for shader nodes. Instead of creating and deleting
nodes using `new` and `delete` explicitely, we now use `create_node` and `delete_node` methods
found on the owners. `delete_node` will assert that the owner is the right one.
Whenever a scene level node is created or deleted, the appropriate node manager is tagged for
an update, freeing this responsability from BlenderSync or other software exporters.
Concerning BlenderSync, the `id_maps` do not explicitely manipulate scene data anymore, they
only keep track of which nodes are used, employing the scene to create and delete them. To
achieve this, the ParticleSystem is now a Node, although it does not have any sockets.
This is part of T79131.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79131
Differential Revision: https://developer.blender.org/D8540
2020-08-30 23:20:51 +02:00
|
|
|
NODE_DEFINE(ParticleSystem)
|
|
|
|
{
|
|
|
|
NodeType *type = NodeType::add("particle_system", create);
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
ParticleSystem::ParticleSystem() : Node(get_node_type()) {}
|
2012-08-31 19:27:08 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
ParticleSystem::~ParticleSystem() {}
|
2012-08-31 19:27:08 +02:00
|
|
|
|
|
|
|
void ParticleSystem::tag_update(Scene *scene)
|
|
|
|
{
|
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->particle_system_manager->tag_update(scene);
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Particle System Manager */
|
|
|
|
|
|
|
|
ParticleSystemManager::ParticleSystemManager()
|
|
|
|
{
|
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
|
|
|
need_update_ = true;
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
ParticleSystemManager::~ParticleSystemManager() {}
|
2012-08-31 19:27:08 +02:00
|
|
|
|
2017-10-21 01:09:59 +02:00
|
|
|
void ParticleSystemManager::device_update_particles(Device *,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress)
|
2012-08-31 19:27:08 +02:00
|
|
|
{
|
|
|
|
/* count particles.
|
|
|
|
* adds one dummy particle at the beginning to avoid invalid lookups,
|
2012-11-08 17:35:28 +01:00
|
|
|
* in case a shader uses particle info without actual particle data. */
|
2012-08-31 19:27:08 +02:00
|
|
|
int num_particles = 1;
|
2023-09-17 01:01:48 +02:00
|
|
|
for (size_t j = 0; j < scene->particle_systems.size(); j++) {
|
2016-05-08 00:09:08 +02:00
|
|
|
num_particles += scene->particle_systems[j]->particles.size();
|
2023-09-17 01:01:48 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:35:24 +01:00
|
|
|
KernelParticle *kparticles = dscene->particles.alloc(num_particles);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-31 19:27:08 +02:00
|
|
|
/* dummy particle */
|
2018-03-08 00:35:24 +01:00
|
|
|
memset(kparticles, 0, sizeof(KernelParticle));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-31 19:27:08 +02:00
|
|
|
int i = 1;
|
2016-05-08 00:09:08 +02:00
|
|
|
for (size_t j = 0; j < scene->particle_systems.size(); j++) {
|
|
|
|
ParticleSystem *psys = scene->particle_systems[j];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
for (size_t k = 0; k < psys->particles.size(); k++) {
|
2012-08-31 19:27:08 +02:00
|
|
|
/* pack in texture */
|
2016-05-08 00:09:08 +02:00
|
|
|
Particle &pa = psys->particles[k];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 00:35:24 +01:00
|
|
|
kparticles[i].index = pa.index;
|
|
|
|
kparticles[i].age = pa.age;
|
|
|
|
kparticles[i].lifetime = pa.lifetime;
|
|
|
|
kparticles[i].size = pa.size;
|
|
|
|
kparticles[i].rotation = pa.rotation;
|
|
|
|
kparticles[i].location = float3_to_float4(pa.location);
|
|
|
|
kparticles[i].velocity = float3_to_float4(pa.velocity);
|
|
|
|
kparticles[i].angular_velocity = float3_to_float4(pa.angular_velocity);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-08-31 19:27:08 +02:00
|
|
|
i++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 01:01:48 +02:00
|
|
|
if (progress.get_cancel()) {
|
2012-08-31 19:27:08 +02:00
|
|
|
return;
|
2023-09-17 01:01:48 +02:00
|
|
|
}
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-21 01:09:59 +02:00
|
|
|
dscene->particles.copy_to_device();
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleSystemManager::device_update(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress)
|
|
|
|
{
|
2023-09-17 01:01:48 +02:00
|
|
|
if (!need_update()) {
|
2016-04-22 10:55:26 +02:00
|
|
|
return;
|
2023-09-17 01:01:48 +02:00
|
|
|
}
|
2016-04-22 10:55:26 +02:00
|
|
|
|
2020-10-01 23:16:01 +02:00
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->particles.times.add_entry({"device_update", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-06-16 19:39:13 +02:00
|
|
|
VLOG_INFO << "Total " << scene->particle_systems.size() << " particle systems.";
|
2015-04-10 12:36:56 +02:00
|
|
|
|
2012-08-31 19:27:08 +02:00
|
|
|
device_free(device, dscene);
|
|
|
|
|
|
|
|
progress.set_status("Updating Particle Systems", "Copying Particles to device");
|
|
|
|
device_update_particles(device, dscene, scene, progress);
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2023-09-17 01:01:48 +02:00
|
|
|
if (progress.get_cancel()) {
|
2012-08-31 19:27:08 +02:00
|
|
|
return;
|
2023-09-17 01:01:48 +02:00
|
|
|
}
|
2018-07-06 10:17:58 +02:00
|
|
|
|
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
|
|
|
need_update_ = false;
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:09:59 +02:00
|
|
|
void ParticleSystemManager::device_free(Device *, DeviceScene *dscene)
|
2012-08-31 19:27:08 +02:00
|
|
|
{
|
2017-10-21 01:09:59 +02:00
|
|
|
dscene->particles.free();
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
2015-03-27 11:47:55 +01:00
|
|
|
void ParticleSystemManager::tag_update(Scene * /*scene*/)
|
2012-08-31 19:27:08 +02:00
|
|
|
{
|
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
|
|
|
need_update_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParticleSystemManager::need_update() const
|
|
|
|
{
|
|
|
|
return need_update_;
|
2012-08-31 19:27:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|