2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/object.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 18:39:14 +00:00
|
|
|
#include "device/device.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/camera.h"
|
|
|
|
#include "render/curves.h"
|
2020-02-02 11:04:19 +00:00
|
|
|
#include "render/hair.h"
|
2020-03-07 13:38:52 +00:00
|
|
|
#include "render/integrator.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 18:39:14 +00:00
|
|
|
#include "render/light.h"
|
|
|
|
#include "render/mesh.h"
|
|
|
|
#include "render/particles.h"
|
|
|
|
#include "render/scene.h"
|
2020-10-01 21:16:01 +00:00
|
|
|
#include "render/stats.h"
|
2020-08-19 13:46:50 +00:00
|
|
|
#include "render/volume.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
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 18:39:14 +00:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_map.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "util/util_murmurhash.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 18:39:14 +00:00
|
|
|
#include "util/util_progress.h"
|
2018-11-07 03:05:47 +00:00
|
|
|
#include "util/util_set.h"
|
2020-06-05 09:39:11 +00:00
|
|
|
#include "util/util_task.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 18:39:14 +00:00
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
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 18:39:14 +00:00
|
|
|
#include "subd/subd_patch_table.h"
|
2016-07-17 02:57:06 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
/* Global state of object transform update. */
|
|
|
|
|
|
|
|
struct UpdateObjectTransformState {
|
|
|
|
/* Global state used by device_update_object_transform().
|
|
|
|
* Common for both threaded and non-threaded update.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Type of the motion required by the scene settings. */
|
|
|
|
Scene::MotionType need_motion;
|
|
|
|
|
|
|
|
/* Mapping from particle system to a index in packed particle array.
|
|
|
|
* Only used for read.
|
|
|
|
*/
|
|
|
|
map<ParticleSystem *, int> particle_offset;
|
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Motion offsets for each object. */
|
|
|
|
array<uint> motion_offset;
|
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
/* Packed object arrays. Those will be filled in. */
|
|
|
|
uint *object_flag;
|
|
|
|
KernelObject *objects;
|
2018-03-09 23:37:07 +00:00
|
|
|
Transform *object_motion_pass;
|
|
|
|
DecomposedTransform *object_motion;
|
2020-03-07 13:38:52 +00:00
|
|
|
float *object_volume_step;
|
2018-03-10 00:15:02 +00:00
|
|
|
|
|
|
|
/* Flags which will be synchronized to Integrator. */
|
|
|
|
bool have_motion;
|
|
|
|
bool have_curves;
|
|
|
|
|
|
|
|
/* ** Scheduling queue. ** */
|
|
|
|
Scene *scene;
|
|
|
|
|
|
|
|
/* First unused object index in the queue. */
|
|
|
|
int queue_start_object;
|
|
|
|
};
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Object */
|
|
|
|
|
2016-05-07 19:44:17 +00:00
|
|
|
NODE_DEFINE(Object)
|
|
|
|
{
|
|
|
|
NodeType *type = NodeType::add("object", create);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
SOCKET_NODE(geometry, "Geometry", &Geometry::node_base_type);
|
2016-05-07 19:44:17 +00:00
|
|
|
SOCKET_TRANSFORM(tfm, "Transform", transform_identity());
|
2016-06-12 15:12:25 +00:00
|
|
|
SOCKET_UINT(visibility, "Visibility", ~0);
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_COLOR(color, "Color", zero_float3());
|
2016-06-12 15:12:25 +00:00
|
|
|
SOCKET_UINT(random_id, "Random ID", 0);
|
2016-05-07 19:44:17 +00:00
|
|
|
SOCKET_INT(pass_id, "Pass ID", 0);
|
|
|
|
SOCKET_BOOLEAN(use_holdout, "Use Holdout", false);
|
2016-08-28 19:20:06 +00:00
|
|
|
SOCKET_BOOLEAN(hide_on_missing_motion, "Hide on Missing Motion", false);
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_POINT(dupli_generated, "Dupli Generated", zero_float3());
|
|
|
|
SOCKET_POINT2(dupli_uv, "Dupli UV", zero_float2());
|
2018-03-08 03:04:52 +00:00
|
|
|
SOCKET_TRANSFORM_ARRAY(motion, "Motion", array<Transform>());
|
2020-05-05 11:55:24 +00:00
|
|
|
SOCKET_FLOAT(shadow_terminator_offset, "Terminator Offset", 0.0f);
|
2020-11-04 10:17:38 +00:00
|
|
|
SOCKET_STRING(asset_name, "Asset Name", ustring());
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-02-09 13:19:01 +00:00
|
|
|
SOCKET_BOOLEAN(is_shadow_catcher, "Shadow Catcher", false);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
SOCKET_NODE(particle_system, "Particle System", &ParticleSystem::node_type);
|
|
|
|
SOCKET_INT(particle_index, "Particle Index", 0);
|
|
|
|
|
2016-05-07 19:44:17 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object::Object() : Node(node_type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-02-25 17:29:11 +00:00
|
|
|
particle_system = NULL;
|
|
|
|
particle_index = 0;
|
2020-10-26 14:37:07 +00:00
|
|
|
attr_map_offset = 0;
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
bounds = BoundBox::empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
void Object::update_motion()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-03-08 03:04:52 +00:00
|
|
|
if (!use_motion()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
bool have_motion = false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
for (size_t i = 0; i < motion.size(); i++) {
|
|
|
|
if (motion[i] == transform_empty()) {
|
|
|
|
if (hide_on_missing_motion) {
|
|
|
|
/* Hide objects that have no valid previous or next
|
|
|
|
* transform, for example particle that stop existing. It
|
|
|
|
* would be better to handle this in the kernel and make
|
|
|
|
* objects invisible outside certain motion steps. */
|
|
|
|
tfm = transform_empty();
|
|
|
|
motion.clear();
|
2016-08-28 19:20:06 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-08 03:04:52 +00:00
|
|
|
else {
|
|
|
|
/* Otherwise just copy center motion. */
|
|
|
|
motion[i] = tfm;
|
|
|
|
}
|
2016-08-28 19:20:06 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Test if any of the transforms are actually different. */
|
|
|
|
have_motion = have_motion || motion[i] != tfm;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
if (!have_motion) {
|
|
|
|
motion.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Object::compute_bounds(bool motion_blur)
|
|
|
|
{
|
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 14:01:26 +00:00
|
|
|
if (!is_modified() && !geometry->is_modified()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
BoundBox mbounds = geometry->bounds;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
if (motion_blur && use_motion()) {
|
|
|
|
array<DecomposedTransform> decomp(motion.size());
|
|
|
|
transform_motion_decompose(decomp.data(), motion.data(), motion.size());
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-08-28 19:20:06 +00:00
|
|
|
bounds = BoundBox::empty;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-20 00:39:03 +00:00
|
|
|
/* TODO: this is really terrible. according to PBRT there is a better
|
2016-08-28 19:20:06 +00:00
|
|
|
* way to find this iteratively, but did not find implementation yet
|
|
|
|
* or try to implement myself */
|
|
|
|
for (float t = 0.0f; t < 1.0f; t += (1.0f / 128.0f)) {
|
|
|
|
Transform ttfm;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
transform_motion_array_interpolate(&ttfm, decomp.data(), motion.size(), t);
|
2016-08-28 19:20:06 +00:00
|
|
|
bounds.grow(mbounds.transformed(&ttfm));
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-03 08:52:04 +00:00
|
|
|
else {
|
2018-03-08 03:04:52 +00:00
|
|
|
/* No motion blur case. */
|
2020-02-02 11:04:19 +00:00
|
|
|
if (geometry->transform_applied) {
|
2014-10-03 08:52:04 +00:00
|
|
|
bounds = mbounds;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bounds = mbounds.transformed(&tfm);
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
void Object::apply_transform(bool apply_to_motion)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-02 11:04:19 +00:00
|
|
|
if (!geometry || tfm == transform_identity())
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
geometry->apply_transform(tfm, apply_to_motion);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-11-12 14:29:52 +00:00
|
|
|
/* we keep normals pointing in same direction on negative scale, notify
|
2020-02-02 11:04:19 +00:00
|
|
|
* geometry about this in it (re)calculates normals */
|
2011-11-12 14:29:52 +00:00
|
|
|
if (transform_negative_scale(tfm))
|
2020-02-02 11:04:19 +00:00
|
|
|
geometry->transform_negative_scaled = true;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (bounds.valid()) {
|
2020-02-02 11:04:19 +00:00
|
|
|
geometry->compute_bounds();
|
2014-03-29 12:03:46 +00:00
|
|
|
compute_bounds(false);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-07-31 15:05:16 +00:00
|
|
|
/* tfm is not reset to identity, all code that uses it needs to check the
|
2016-07-14 16:36:21 +00:00
|
|
|
* transform_applied boolean */
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Object::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 14:01:26 +00:00
|
|
|
uint32_t flag = ObjectManager::UPDATE_NONE;
|
|
|
|
|
|
|
|
if (is_modified()) {
|
|
|
|
flag |= ObjectManager::OBJECT_MODIFIED;
|
|
|
|
|
|
|
|
if (use_holdout_is_modified()) {
|
|
|
|
flag |= ObjectManager::HOLDOUT_MODIFIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
if (geometry) {
|
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 14:01:26 +00:00
|
|
|
if (tfm_is_modified()) {
|
|
|
|
/* tag the geometry as modified so the BVH is updated, but do not tag everything as modified
|
|
|
|
*/
|
|
|
|
if (geometry->is_mesh() || geometry->is_volume()) {
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geometry);
|
|
|
|
mesh->tag_verts_modified();
|
|
|
|
}
|
|
|
|
else if (geometry->is_hair()) {
|
|
|
|
Hair *hair = static_cast<Hair *>(geometry);
|
|
|
|
hair->tag_curve_keys_modified();
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
foreach (Node *node, geometry->get_used_shaders()) {
|
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
|
|
|
if (shader->get_use_mis() && shader->has_surface_emission)
|
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 14:01:26 +00:00
|
|
|
scene->light_manager->tag_update(scene, LightManager::EMISSIVE_MESH_MODIFIED);
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-05-14 14:08:13 +00:00
|
|
|
scene->camera->need_flags_update = true;
|
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 14:01:26 +00:00
|
|
|
scene->object_manager->tag_update(scene, flag);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
bool Object::use_motion() const
|
|
|
|
{
|
|
|
|
return (motion.size() > 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
float Object::motion_time(int step) const
|
|
|
|
{
|
|
|
|
return (use_motion()) ? 2.0f * step / (motion.size() - 1) - 1.0f : 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Object::motion_step(float time) const
|
|
|
|
{
|
|
|
|
if (use_motion()) {
|
|
|
|
for (size_t step = 0; step < motion.size(); step++) {
|
|
|
|
if (time == motion_time(step)) {
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-09 23:37:07 +00:00
|
|
|
bool Object::is_traceable() const
|
2016-06-06 07:15:34 +00:00
|
|
|
{
|
|
|
|
/* Mesh itself can be empty,can skip all such objects. */
|
2021-02-17 00:47:18 +00:00
|
|
|
if (!bounds.valid() || bounds.size() == zero_float3()) {
|
2016-06-06 07:15:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* TODO(sergey): Check for mesh vertices/curves. visibility flags. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-10 07:19:40 +00:00
|
|
|
uint Object::visibility_for_tracing() const
|
|
|
|
{
|
|
|
|
uint trace_visibility = visibility;
|
2017-11-07 12:55:58 +00:00
|
|
|
if (is_shadow_catcher) {
|
2017-08-10 07:19:40 +00:00
|
|
|
trace_visibility &= ~PATH_RAY_SHADOW_NON_CATCHER;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
trace_visibility &= ~PATH_RAY_SHADOW_CATCHER;
|
|
|
|
}
|
|
|
|
return trace_visibility;
|
|
|
|
}
|
|
|
|
|
2020-03-07 13:38:52 +00:00
|
|
|
float Object::compute_volume_step_size() const
|
|
|
|
{
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geometry->geometry_type != Geometry::MESH && geometry->geometry_type != Geometry::VOLUME) {
|
2020-03-16 13:42:56 +00:00
|
|
|
return FLT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geometry);
|
|
|
|
|
|
|
|
if (!mesh->has_volume) {
|
2020-03-07 13:38:52 +00:00
|
|
|
return FLT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute step rate from shaders. */
|
|
|
|
float step_rate = FLT_MAX;
|
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
foreach (Node *node, mesh->get_used_shaders()) {
|
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
2020-03-07 13:38:52 +00:00
|
|
|
if (shader->has_volume) {
|
2020-11-04 10:17:38 +00:00
|
|
|
if ((shader->get_heterogeneous_volume() && shader->has_volume_spatial_varying) ||
|
2020-03-07 13:38:52 +00:00
|
|
|
(shader->has_volume_attribute_dependency)) {
|
2020-11-04 10:17:38 +00:00
|
|
|
step_rate = fminf(shader->get_volume_step_rate(), step_rate);
|
2020-03-07 13:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (step_rate == FLT_MAX) {
|
|
|
|
return FLT_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute step size from voxel grids. */
|
|
|
|
float step_size = FLT_MAX;
|
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geometry->geometry_type == Geometry::VOLUME) {
|
2020-08-19 13:46:50 +00:00
|
|
|
Volume *volume = static_cast<Volume *>(geometry);
|
2020-03-07 13:38:52 +00:00
|
|
|
|
2020-08-19 13:46:50 +00:00
|
|
|
foreach (Attribute &attr, volume->attributes.attributes) {
|
|
|
|
if (attr.element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
ImageHandle &handle = attr.data_voxel();
|
|
|
|
const ImageMetaData &metadata = handle.metadata();
|
|
|
|
if (metadata.width == 0 || metadata.height == 0 || metadata.depth == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-03-16 13:42:56 +00:00
|
|
|
|
2020-08-19 13:46:50 +00:00
|
|
|
/* User specified step size. */
|
2020-11-04 10:17:38 +00:00
|
|
|
float voxel_step_size = volume->get_step_size();
|
2020-03-07 13:38:52 +00:00
|
|
|
|
2020-08-19 13:46:50 +00:00
|
|
|
if (voxel_step_size == 0.0f) {
|
|
|
|
/* Auto detect step size. */
|
2021-02-17 00:47:18 +00:00
|
|
|
float3 size = one_float3();
|
2020-11-04 14:09:06 +00:00
|
|
|
#ifdef WITH_NANOVDB
|
|
|
|
/* Dimensions were not applied to image transform with NanOVDB (see image_vdb.cpp) */
|
|
|
|
if (metadata.type != IMAGE_DATA_TYPE_NANOVDB_FLOAT &&
|
|
|
|
metadata.type != IMAGE_DATA_TYPE_NANOVDB_FLOAT3)
|
|
|
|
#endif
|
|
|
|
size /= make_float3(metadata.width, metadata.height, metadata.depth);
|
2020-08-19 13:46:50 +00:00
|
|
|
|
|
|
|
/* Step size is transformed from voxel to world space. */
|
|
|
|
Transform voxel_tfm = tfm;
|
|
|
|
if (metadata.use_transform_3d) {
|
|
|
|
voxel_tfm = tfm * transform_inverse(metadata.transform_3d);
|
|
|
|
}
|
|
|
|
voxel_step_size = min3(fabs(transform_direction(&voxel_tfm, size)));
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (volume->get_object_space()) {
|
2020-08-19 13:46:50 +00:00
|
|
|
/* User specified step size in object space. */
|
|
|
|
float3 size = make_float3(voxel_step_size, voxel_step_size, voxel_step_size);
|
|
|
|
voxel_step_size = min3(fabs(transform_direction(&tfm, size)));
|
2020-03-16 13:42:56 +00:00
|
|
|
}
|
2020-03-07 13:38:52 +00:00
|
|
|
|
2020-08-19 13:46:50 +00:00
|
|
|
if (voxel_step_size > 0.0f) {
|
|
|
|
step_size = fminf(voxel_step_size, step_size);
|
|
|
|
}
|
2020-03-07 13:38:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (step_size == FLT_MAX) {
|
|
|
|
/* Fall back to 1/10th of bounds for procedural volumes. */
|
|
|
|
step_size = 0.1f * average(bounds.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
step_size *= step_rate;
|
|
|
|
|
|
|
|
return step_size;
|
|
|
|
}
|
|
|
|
|
2018-11-29 01:06:30 +00:00
|
|
|
int Object::get_device_index() const
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Object Manager */
|
|
|
|
|
|
|
|
ObjectManager::ObjectManager()
|
|
|
|
{
|
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 14:01:26 +00:00
|
|
|
update_flags = UPDATE_ALL;
|
2015-01-19 14:08:58 +00:00
|
|
|
need_flags_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectManager::~ObjectManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-12-24 13:19:21 +00:00
|
|
|
static float object_volume_density(const Transform &tfm, Geometry *geom)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-12-24 12:45:04 +00:00
|
|
|
if (geom->geometry_type == Geometry::VOLUME) {
|
2020-03-16 13:42:56 +00:00
|
|
|
/* Volume density automatically adjust to object scale. */
|
2020-12-24 12:45:04 +00:00
|
|
|
if (static_cast<Volume *>(geom)->get_object_space()) {
|
2021-02-17 00:47:18 +00:00
|
|
|
const float3 unit = normalize(one_float3());
|
2020-03-16 13:42:56 +00:00
|
|
|
return 1.0f / len(transform_direction(&tfm, unit));
|
|
|
|
}
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-12-24 12:45:04 +00:00
|
|
|
return 1.0f;
|
2020-02-02 11:04:19 +00: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 14:01:26 +00:00
|
|
|
void ObjectManager::device_update_object_transform(UpdateObjectTransformState *state,
|
|
|
|
Object *ob,
|
|
|
|
bool update_all)
|
2020-02-02 11:04:19 +00:00
|
|
|
{
|
|
|
|
KernelObject &kobject = state->objects[ob->index];
|
|
|
|
Transform *object_motion_pass = state->object_motion_pass;
|
|
|
|
|
|
|
|
Geometry *geom = ob->geometry;
|
|
|
|
uint flag = 0;
|
|
|
|
|
|
|
|
/* Compute transformations. */
|
|
|
|
Transform tfm = ob->tfm;
|
|
|
|
Transform itfm = transform_inverse(tfm);
|
|
|
|
|
|
|
|
float3 color = ob->color;
|
|
|
|
float pass_id = ob->pass_id;
|
|
|
|
float random_number = (float)ob->random_id * (1.0f / (float)0xFFFFFFFF);
|
|
|
|
int particle_index = (ob->particle_system) ?
|
|
|
|
ob->particle_index + state->particle_offset[ob->particle_system] :
|
|
|
|
0;
|
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
kobject.tfm = tfm;
|
|
|
|
kobject.itfm = itfm;
|
2020-12-24 13:19:21 +00:00
|
|
|
kobject.volume_density = object_volume_density(tfm, geom);
|
2019-08-22 12:26:09 +00:00
|
|
|
kobject.color[0] = color.x;
|
|
|
|
kobject.color[1] = color.y;
|
|
|
|
kobject.color[2] = color.z;
|
2018-03-07 21:19:56 +00:00
|
|
|
kobject.pass_id = pass_id;
|
|
|
|
kobject.random_number = random_number;
|
|
|
|
kobject.particle_index = particle_index;
|
2018-03-08 03:04:52 +00:00
|
|
|
kobject.motion_offset = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geom->get_use_motion_blur()) {
|
2017-08-17 10:44:09 +00:00
|
|
|
state->have_motion = true;
|
|
|
|
}
|
2020-02-02 11:04:19 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geom->geometry_type == Geometry::MESH) {
|
2020-02-02 11:04:19 +00:00
|
|
|
/* TODO: why only mesh? */
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
|
|
|
if (mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) {
|
|
|
|
flag |= SD_OBJECT_HAS_VERTEX_MOTION;
|
|
|
|
}
|
2017-08-17 10:44:09 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
if (state->need_motion == Scene::MOTION_PASS) {
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
ob->update_motion();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Compute motion transforms. */
|
|
|
|
Transform tfm_pre, tfm_post;
|
|
|
|
if (ob->use_motion()) {
|
|
|
|
tfm_pre = ob->motion[0];
|
|
|
|
tfm_post = ob->motion[ob->motion.size() - 1];
|
2016-08-05 22:38:23 +00:00
|
|
|
}
|
2018-03-08 03:04:52 +00:00
|
|
|
else {
|
|
|
|
tfm_pre = tfm;
|
|
|
|
tfm_post = tfm;
|
2016-08-05 22:38:23 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Motion transformations, is world/object space depending if mesh
|
|
|
|
* comes with deformed position in object space, or if we transform
|
|
|
|
* the shading point in world space. */
|
2020-02-02 11:04:19 +00:00
|
|
|
if (!(flag & SD_OBJECT_HAS_VERTEX_MOTION)) {
|
2018-03-08 03:04:52 +00:00
|
|
|
tfm_pre = tfm_pre * itfm;
|
|
|
|
tfm_post = tfm_post * itfm;
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-11-29 01:06:30 +00:00
|
|
|
int motion_pass_offset = ob->index * OBJECT_MOTION_PASS_SIZE;
|
2018-03-08 03:04:52 +00:00
|
|
|
object_motion_pass[motion_pass_offset + 0] = tfm_pre;
|
|
|
|
object_motion_pass[motion_pass_offset + 1] = tfm_post;
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
|
|
|
else if (state->need_motion == Scene::MOTION_BLUR) {
|
2018-03-08 03:04:52 +00:00
|
|
|
if (ob->use_motion()) {
|
2018-11-29 01:06:30 +00:00
|
|
|
kobject.motion_offset = state->motion_offset[ob->index];
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Decompose transforms for interpolation. */
|
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 14:01:26 +00:00
|
|
|
if (ob->tfm_is_modified() || update_all) {
|
|
|
|
DecomposedTransform *decomp = state->object_motion + kobject.motion_offset;
|
|
|
|
transform_motion_decompose(decomp, ob->motion.data(), ob->motion.size());
|
|
|
|
}
|
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
flag |= SD_OBJECT_MOTION;
|
|
|
|
state->have_motion = true;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
/* Dupli object coords and motion info. */
|
2018-03-07 21:19:56 +00:00
|
|
|
kobject.dupli_generated[0] = ob->dupli_generated[0];
|
|
|
|
kobject.dupli_generated[1] = ob->dupli_generated[1];
|
|
|
|
kobject.dupli_generated[2] = ob->dupli_generated[2];
|
2020-11-04 10:17:38 +00:00
|
|
|
kobject.numkeys = (geom->geometry_type == Geometry::HAIR) ?
|
|
|
|
static_cast<Hair *>(geom)->get_curve_keys().size() :
|
|
|
|
0;
|
2018-03-07 21:19:56 +00:00
|
|
|
kobject.dupli_uv[0] = ob->dupli_uv[0];
|
|
|
|
kobject.dupli_uv[1] = ob->dupli_uv[1];
|
2020-11-04 10:17:38 +00:00
|
|
|
int totalsteps = geom->get_motion_steps();
|
2018-03-07 21:19:56 +00:00
|
|
|
kobject.numsteps = (totalsteps - 1) / 2;
|
2020-11-04 10:17:38 +00:00
|
|
|
kobject.numverts = (geom->geometry_type == Geometry::MESH ||
|
|
|
|
geom->geometry_type == Geometry::VOLUME) ?
|
|
|
|
static_cast<Mesh *>(geom)->get_verts().size() :
|
2020-08-19 13:46:50 +00:00
|
|
|
0;
|
2018-03-07 21:19:56 +00:00
|
|
|
kobject.patch_map_offset = 0;
|
|
|
|
kobject.attribute_map_offset = 0;
|
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 14:01:26 +00:00
|
|
|
|
|
|
|
if (ob->asset_name_is_modified() || update_all) {
|
|
|
|
uint32_t hash_name = util_murmur_hash3(ob->name.c_str(), ob->name.length(), 0);
|
|
|
|
uint32_t hash_asset = util_murmur_hash3(ob->asset_name.c_str(), ob->asset_name.length(), 0);
|
|
|
|
kobject.cryptomatte_object = util_hash_to_float(hash_name);
|
|
|
|
kobject.cryptomatte_asset = util_hash_to_float(hash_asset);
|
|
|
|
}
|
|
|
|
|
2020-05-05 11:55:24 +00:00
|
|
|
kobject.shadow_terminator_offset = 1.0f / (1.0f - 0.5f * ob->shadow_terminator_offset);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
/* Object flag. */
|
|
|
|
if (ob->use_holdout) {
|
2016-12-23 09:49:59 +00:00
|
|
|
flag |= SD_OBJECT_HOLDOUT_MASK;
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2018-11-29 01:06:30 +00:00
|
|
|
state->object_flag[ob->index] = flag;
|
2020-03-07 13:38:52 +00:00
|
|
|
state->object_volume_step[ob->index] = FLT_MAX;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
/* Have curves. */
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geom->geometry_type == Geometry::HAIR) {
|
2016-04-20 16:12:26 +00:00
|
|
|
state->have_curves = true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-04 21:40:39 +00:00
|
|
|
|
2018-01-15 10:45:16 +00:00
|
|
|
void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress)
|
2016-04-20 16:12:26 +00:00
|
|
|
{
|
2018-02-05 09:01:00 +00:00
|
|
|
UpdateObjectTransformState state;
|
2018-01-12 18:56:52 +00:00
|
|
|
state.need_motion = scene->need_motion();
|
2016-04-20 16:12:26 +00:00
|
|
|
state.have_motion = false;
|
|
|
|
state.have_curves = false;
|
|
|
|
state.scene = scene;
|
|
|
|
state.queue_start_object = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 21:19:56 +00:00
|
|
|
state.objects = dscene->objects.alloc(scene->objects.size());
|
2018-03-10 00:15:02 +00:00
|
|
|
state.object_flag = dscene->object_flag.alloc(scene->objects.size());
|
2020-03-07 13:38:52 +00:00
|
|
|
state.object_volume_step = dscene->object_volume_step.alloc(scene->objects.size());
|
2018-03-08 03:04:52 +00:00
|
|
|
state.object_motion = NULL;
|
2018-03-09 23:37:07 +00:00
|
|
|
state.object_motion_pass = NULL;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
if (state.need_motion == Scene::MOTION_PASS) {
|
2018-03-09 23:37:07 +00:00
|
|
|
state.object_motion_pass = dscene->object_motion_pass.alloc(OBJECT_MOTION_PASS_SIZE *
|
|
|
|
scene->objects.size());
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2018-03-08 03:04:52 +00:00
|
|
|
else if (state.need_motion == Scene::MOTION_BLUR) {
|
|
|
|
/* Set object offsets into global object motion array. */
|
|
|
|
uint *motion_offsets = state.motion_offset.resize(scene->objects.size());
|
|
|
|
uint motion_offset = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
foreach (Object *ob, scene->objects) {
|
|
|
|
*motion_offsets = motion_offset;
|
|
|
|
motion_offsets++;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
ob->update_motion();
|
|
|
|
motion_offset += ob->motion.size();
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 03:04:52 +00:00
|
|
|
state.object_motion = dscene->object_motion.alloc(motion_offset);
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
/* Particle system device offsets
|
|
|
|
* 0 is dummy particle, index starts at 1.
|
|
|
|
*/
|
|
|
|
int numparticles = 1;
|
|
|
|
foreach (ParticleSystem *psys, scene->particle_systems) {
|
|
|
|
state.particle_offset[psys] = numparticles;
|
|
|
|
numparticles += psys->particles.size();
|
|
|
|
}
|
2019-04-17 04:17:24 +00: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 14:01:26 +00:00
|
|
|
/* as all the arrays are the same size, checking only dscene.objects is sufficient */
|
|
|
|
const bool update_all = dscene->objects.need_realloc();
|
|
|
|
|
2020-06-25 13:13:02 +00:00
|
|
|
/* Parallel object update, with grain size to avoid too much threading overhead
|
2020-06-05 10:53:38 +00:00
|
|
|
* for individual objects. */
|
|
|
|
static const int OBJECTS_PER_TASK = 32;
|
|
|
|
parallel_for(blocked_range<size_t>(0, scene->objects.size(), OBJECTS_PER_TASK),
|
|
|
|
[&](const blocked_range<size_t> &r) {
|
|
|
|
for (size_t i = r.begin(); i != r.end(); i++) {
|
|
|
|
Object *ob = state.scene->objects[i];
|
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 14:01:26 +00:00
|
|
|
device_update_object_transform(&state, ob, update_all);
|
2020-06-05 10:53:38 +00:00
|
|
|
}
|
|
|
|
});
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-06-24 15:08:01 +00:00
|
|
|
if (progress.get_cancel()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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 14:01:26 +00:00
|
|
|
dscene->objects.copy_to_device_if_modified();
|
2016-04-20 16:12:26 +00:00
|
|
|
if (state.need_motion == Scene::MOTION_PASS) {
|
2018-03-09 23:37:07 +00:00
|
|
|
dscene->object_motion_pass.copy_to_device();
|
2016-04-20 16:12:26 +00:00
|
|
|
}
|
2018-03-08 03:04:52 +00:00
|
|
|
else if (state.need_motion == Scene::MOTION_BLUR) {
|
|
|
|
dscene->object_motion.copy_to_device();
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-04-20 16:12:26 +00:00
|
|
|
dscene->data.bvh.have_motion = state.have_motion;
|
|
|
|
dscene->data.bvh.have_curves = state.have_curves;
|
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 14:01:26 +00:00
|
|
|
|
|
|
|
dscene->objects.clear_modified();
|
|
|
|
dscene->object_motion_pass.clear_modified();
|
|
|
|
dscene->object_motion.clear_modified();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManager::device_update(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress)
|
|
|
|
{
|
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 14:01:26 +00:00
|
|
|
if (!need_update())
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2016-04-22 08:55:26 +00: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 14:01:26 +00:00
|
|
|
if (update_flags & (OBJECT_ADDED | OBJECT_REMOVED)) {
|
|
|
|
dscene->objects.tag_realloc();
|
|
|
|
dscene->object_motion_pass.tag_realloc();
|
|
|
|
dscene->object_motion.tag_realloc();
|
|
|
|
dscene->object_flag.tag_realloc();
|
|
|
|
dscene->object_volume_step.tag_realloc();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_flags & HOLDOUT_MODIFIED) {
|
|
|
|
dscene->object_flag.tag_modified();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_flags & PARTICLE_MODIFIED) {
|
|
|
|
dscene->objects.tag_modified();
|
|
|
|
}
|
|
|
|
|
2016-04-22 08:55:26 +00:00
|
|
|
VLOG(1) << "Total " << scene->objects.size() << " objects.";
|
|
|
|
|
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 14:01:26 +00:00
|
|
|
device_free(device, dscene, false);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if (scene->objects.size() == 0)
|
|
|
|
return;
|
|
|
|
|
2020-10-01 21:16:01 +00:00
|
|
|
{
|
|
|
|
/* Assign object IDs. */
|
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->object.times.add_entry({"device_update (assign index)", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
|
foreach (Object *object, scene->objects) {
|
|
|
|
object->index = index++;
|
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 14:01:26 +00:00
|
|
|
|
|
|
|
/* this is a bit too broad, however a bigger refactor might be needed to properly separate
|
|
|
|
* update each type of data (transform, flags, etc.) */
|
|
|
|
if (object->is_modified()) {
|
|
|
|
dscene->objects.tag_modified();
|
|
|
|
dscene->object_motion_pass.tag_modified();
|
|
|
|
dscene->object_motion.tag_modified();
|
|
|
|
dscene->object_flag.tag_modified();
|
|
|
|
dscene->object_volume_step.tag_modified();
|
|
|
|
}
|
2020-10-01 21:16:01 +00:00
|
|
|
}
|
2018-11-29 01:06:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-01 21:16:01 +00:00
|
|
|
{
|
|
|
|
/* set object transform matrices, before applying static transforms */
|
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->object.times.add_entry(
|
|
|
|
{"device_update (copy objects to device)", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
progress.set_status("Updating Objects", "Copying Transformations to device");
|
|
|
|
device_update_transforms(dscene, scene, progress);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* prepare for static BVH building */
|
|
|
|
/* todo: do before to support getting object level coords? */
|
2014-05-19 10:49:36 +00:00
|
|
|
if (scene->params.bvh_type == SceneParams::BVH_STATIC) {
|
2020-10-01 21:16:01 +00:00
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->object.times.add_entry(
|
|
|
|
{"device_update (apply static transforms)", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Updating Objects", "Applying Static Transformations");
|
2018-03-10 00:15:02 +00:00
|
|
|
apply_static_transforms(dscene, scene, progress);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
|
|
|
|
foreach (Object *object, scene->objects) {
|
|
|
|
object->clear_modified();
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
void ObjectManager::device_update_flags(
|
2015-06-01 18:59:23 +00:00
|
|
|
Device *, DeviceScene *dscene, Scene *scene, Progress & /*progress*/, bool bounds_valid)
|
2014-10-03 10:11:19 +00: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 14:01:26 +00:00
|
|
|
if (!need_update() && !need_flags_update)
|
2014-10-03 10:11:19 +00:00
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-10-01 21:16:01 +00:00
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->object.times.add_entry({"device_update_flags", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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 14:01:26 +00:00
|
|
|
update_flags = UPDATE_NONE;
|
2015-01-19 14:08:58 +00:00
|
|
|
need_flags_update = false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-10-03 10:11:19 +00:00
|
|
|
if (scene->objects.size() == 0)
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
/* Object info flag. */
|
2017-11-04 23:34:30 +00:00
|
|
|
uint *object_flag = dscene->object_flag.data();
|
2020-03-07 13:38:52 +00:00
|
|
|
float *object_volume_step = dscene->object_volume_step.data();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
/* Object volume intersection. */
|
2014-10-03 10:11:19 +00:00
|
|
|
vector<Object *> volume_objects;
|
2015-06-01 18:59:23 +00:00
|
|
|
bool has_volume_objects = false;
|
2014-10-03 10:11:19 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2020-02-02 11:04:19 +00:00
|
|
|
if (object->geometry->has_volume) {
|
2015-06-01 18:59:23 +00:00
|
|
|
if (bounds_valid) {
|
|
|
|
volume_objects.push_back(object);
|
|
|
|
}
|
|
|
|
has_volume_objects = true;
|
2020-03-07 13:38:52 +00:00
|
|
|
object_volume_step[object->index] = object->compute_volume_step_size();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
object_volume_step[object->index] = FLT_MAX;
|
2014-10-03 10:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-10-03 10:11:19 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2020-02-02 11:04:19 +00:00
|
|
|
if (object->geometry->has_volume) {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME;
|
|
|
|
object_flag[object->index] &= ~SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
foreach (Attribute &attr, object->geometry->attributes.attributes) {
|
2018-02-18 02:20:39 +00:00
|
|
|
if (attr.element == ATTR_ELEMENT_VOXEL) {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
|
2018-02-18 02:20:39 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-03 10:11:19 +00:00
|
|
|
}
|
2015-01-19 14:08:58 +00:00
|
|
|
else {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] &= ~(SD_OBJECT_HAS_VOLUME | SD_OBJECT_HAS_VOLUME_ATTRIBUTES);
|
2015-01-19 14:08:58 +00:00
|
|
|
}
|
2020-03-07 13:38:52 +00:00
|
|
|
|
2017-02-09 13:19:01 +00:00
|
|
|
if (object->is_shadow_catcher) {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] |= SD_OBJECT_SHADOW_CATCHER;
|
2017-02-09 13:19:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] &= ~SD_OBJECT_SHADOW_CATCHER;
|
2017-02-09 13:19:01 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-06-01 18:59:23 +00:00
|
|
|
if (bounds_valid) {
|
|
|
|
foreach (Object *volume_object, volume_objects) {
|
|
|
|
if (object == volume_object) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (object->bounds.intersects(volume_object->bounds)) {
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] |= SD_OBJECT_INTERSECTS_VOLUME;
|
2015-06-01 18:59:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-10-03 10:11:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-01 18:59:23 +00:00
|
|
|
else if (has_volume_objects) {
|
|
|
|
/* Not really valid, but can't make more reliable in the case
|
|
|
|
* of bounds not being up to date.
|
|
|
|
*/
|
2018-11-29 01:06:30 +00:00
|
|
|
object_flag[object->index] |= SD_OBJECT_INTERSECTS_VOLUME;
|
2015-06-01 18:59:23 +00:00
|
|
|
}
|
2014-10-03 10:11:19 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
/* Copy object flag. */
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->object_flag.copy_to_device();
|
2020-03-07 13:38:52 +00:00
|
|
|
dscene->object_volume_step.copy_to_device();
|
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 14:01:26 +00:00
|
|
|
|
|
|
|
dscene->object_flag.clear_modified();
|
|
|
|
dscene->object_volume_step.clear_modified();
|
2014-10-03 10:11:19 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 16:40:36 +00:00
|
|
|
void ObjectManager::device_update_mesh_offsets(Device *, DeviceScene *dscene, Scene *scene)
|
2016-07-17 02:57:06 +00:00
|
|
|
{
|
2018-01-02 21:56:07 +00:00
|
|
|
if (dscene->objects.size() == 0) {
|
2016-08-09 02:32:38 +00:00
|
|
|
return;
|
2016-10-24 10:26:12 +00:00
|
|
|
}
|
2016-08-09 02:32:38 +00:00
|
|
|
|
2018-03-07 21:19:56 +00:00
|
|
|
KernelObject *kobjects = dscene->objects.data();
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
bool update = false;
|
|
|
|
|
2017-11-05 16:40:36 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2020-02-02 11:04:19 +00:00
|
|
|
Geometry *geom = object->geometry;
|
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geom->geometry_type == Geometry::MESH) {
|
2020-02-02 11:04:19 +00:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
|
|
|
if (mesh->patch_table) {
|
|
|
|
uint patch_map_offset = 2 * (mesh->patch_table_offset + mesh->patch_table->total_size() -
|
|
|
|
mesh->patch_table->num_nodes * PATCH_NODE_SIZE) -
|
|
|
|
mesh->patch_offset;
|
|
|
|
|
|
|
|
if (kobjects[object->index].patch_map_offset != patch_map_offset) {
|
|
|
|
kobjects[object->index].patch_map_offset = patch_map_offset;
|
|
|
|
update = true;
|
|
|
|
}
|
2016-07-17 02:57:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:37:07 +00:00
|
|
|
size_t attr_map_offset = object->attr_map_offset;
|
|
|
|
|
|
|
|
/* An object attribute map cannot have a zero offset because mesh maps come first. */
|
|
|
|
if (attr_map_offset == 0) {
|
|
|
|
attr_map_offset = geom->attr_map_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kobjects[object->index].attribute_map_offset != attr_map_offset) {
|
|
|
|
kobjects[object->index].attribute_map_offset = attr_map_offset;
|
2017-11-05 16:40:36 +00:00
|
|
|
update = true;
|
|
|
|
}
|
2016-07-17 02:57:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update) {
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->objects.copy_to_device();
|
2016-07-17 02:57:06 +00: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 14:01:26 +00:00
|
|
|
void ObjectManager::device_free(Device *, DeviceScene *dscene, bool force_free)
|
2011-04-27 11:58:34 +00: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 14:01:26 +00:00
|
|
|
dscene->objects.free_if_need_realloc(force_free);
|
|
|
|
dscene->object_motion_pass.free_if_need_realloc(force_free);
|
|
|
|
dscene->object_motion.free_if_need_realloc(force_free);
|
|
|
|
dscene->object_flag.free_if_need_realloc(force_free);
|
|
|
|
dscene->object_volume_step.free_if_need_realloc(force_free);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, Progress &progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* todo: normals and displacement should be done before applying transform! */
|
2020-02-02 11:04:19 +00:00
|
|
|
/* todo: create objects/geometry in right order! */
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
/* counter geometry users */
|
|
|
|
map<Geometry *, int> geometry_users;
|
2012-10-15 21:12:58 +00:00
|
|
|
Scene::MotionType need_motion = scene->need_motion();
|
|
|
|
bool motion_blur = need_motion == Scene::MOTION_BLUR;
|
2014-05-09 15:02:08 +00:00
|
|
|
bool apply_to_motion = need_motion != Scene::MOTION_PASS;
|
2012-12-01 19:15:05 +00:00
|
|
|
int i = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2020-02-02 11:04:19 +00:00
|
|
|
map<Geometry *, int>::iterator it = geometry_users.find(object->geometry);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
if (it == geometry_users.end())
|
|
|
|
geometry_users[object->geometry] = 1;
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
|
|
|
it->second++;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-10 00:15:02 +00:00
|
|
|
uint *object_flag = dscene->object_flag.data();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
/* apply transforms for objects with single user geometry */
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2016-03-31 15:46:22 +00:00
|
|
|
/* Annoying feedback loop here: we can't use is_instanced() because
|
|
|
|
* it'll use uninitialized transform_applied flag.
|
|
|
|
*
|
2020-02-02 11:04:19 +00:00
|
|
|
* Could be solved by moving reference counter to Geometry.
|
2016-03-31 15:46:22 +00:00
|
|
|
*/
|
2020-02-02 11:04:19 +00:00
|
|
|
Geometry *geom = object->geometry;
|
|
|
|
bool apply = (geometry_users[geom] == 1) && !geom->has_surface_bssrdf &&
|
|
|
|
!geom->has_true_displacement();
|
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (geom->geometry_type == Geometry::MESH) {
|
2020-02-02 11:04:19 +00:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-11-04 10:17:38 +00:00
|
|
|
apply = apply && mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE;
|
2020-02-02 11:04:19 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (geom->geometry_type == Geometry::HAIR) {
|
2020-07-07 12:47:59 +00:00
|
|
|
/* Can't apply non-uniform scale to curves, this can't be represented by
|
|
|
|
* control points and radius alone. */
|
|
|
|
float scale;
|
|
|
|
apply = apply && transform_uniform_scale(object->tfm, scale);
|
|
|
|
}
|
2020-02-02 11:04:19 +00:00
|
|
|
|
|
|
|
if (apply) {
|
2018-03-08 03:04:52 +00:00
|
|
|
if (!(motion_blur && object->use_motion())) {
|
2020-02-02 11:04:19 +00:00
|
|
|
if (!geom->transform_applied) {
|
2014-05-09 15:02:08 +00:00
|
|
|
object->apply_transform(apply_to_motion);
|
2020-02-02 11:04:19 +00:00
|
|
|
geom->transform_applied = true;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-12-23 09:49:59 +00:00
|
|
|
object_flag[i] |= SD_OBJECT_TRANSFORM_APPLIED;
|
2020-02-02 11:04:19 +00:00
|
|
|
if (geom->transform_negative_scaled)
|
2016-12-23 09:49:59 +00:00
|
|
|
object_flag[i] |= SD_OBJECT_NEGATIVE_SCALE_APPLIED;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
i++;
|
2011-04-27 11:58:34 +00: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 14:01:26 +00:00
|
|
|
void ObjectManager::tag_update(Scene *scene, uint32_t flag)
|
|
|
|
{
|
|
|
|
update_flags |= flag;
|
|
|
|
|
|
|
|
/* avoid infinite loops if the geometry manager tagged us for an update */
|
|
|
|
if ((flag & GEOMETRY_MANAGER) == 0) {
|
2021-02-11 10:54:29 +00:00
|
|
|
uint32_t geometry_flag = GeometryManager::OBJECT_MANAGER;
|
|
|
|
|
|
|
|
/* Also notify in case added or removed objects were instances, as no Geometry might have been
|
|
|
|
* added or removed, but the BVH still needs to updated. */
|
|
|
|
if ((flag & (OBJECT_ADDED | OBJECT_REMOVED)) != 0) {
|
|
|
|
geometry_flag |= (GeometryManager::GEOMETRY_ADDED | GeometryManager::GEOMETRY_REMOVED);
|
|
|
|
}
|
|
|
|
|
|
|
|
scene->geometry_manager->tag_update(scene, geometry_flag);
|
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 14:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
scene->light_manager->tag_update(scene, LightManager::OBJECT_MANAGER);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectManager::need_update() const
|
2011-04-27 11:58:34 +00: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 14:01:26 +00:00
|
|
|
return update_flags != UPDATE_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2018-11-07 03:05:47 +00:00
|
|
|
string ObjectManager::get_cryptomatte_objects(Scene *scene)
|
|
|
|
{
|
|
|
|
string manifest = "{";
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-11-07 03:05:47 +00:00
|
|
|
unordered_set<ustring, ustringHash> objects;
|
|
|
|
foreach (Object *object, scene->objects) {
|
|
|
|
if (objects.count(object->name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
objects.insert(object->name);
|
|
|
|
uint32_t hash_name = util_murmur_hash3(object->name.c_str(), object->name.length(), 0);
|
|
|
|
manifest += string_printf("\"%s\":\"%08x\",", object->name.c_str(), hash_name);
|
|
|
|
}
|
|
|
|
manifest[manifest.size() - 1] = '}';
|
|
|
|
return manifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
string ObjectManager::get_cryptomatte_assets(Scene *scene)
|
|
|
|
{
|
|
|
|
string manifest = "{";
|
|
|
|
unordered_set<ustring, ustringHash> assets;
|
|
|
|
foreach (Object *ob, scene->objects) {
|
|
|
|
if (assets.count(ob->asset_name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assets.insert(ob->asset_name);
|
|
|
|
uint32_t hash_asset = util_murmur_hash3(ob->asset_name.c_str(), ob->asset_name.length(), 0);
|
|
|
|
manifest += string_printf("\"%s\":\"%08x\",", ob->asset_name.c_str(), hash_asset);
|
|
|
|
}
|
|
|
|
manifest[manifest.size() - 1] = '}';
|
|
|
|
return manifest;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|