2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/object.h"
|
2024-12-26 17:53:59 +01: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 20:39:14 +02:00
|
|
|
#include "device/device.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/camera.h"
|
|
|
|
|
#include "scene/curves.h"
|
|
|
|
|
#include "scene/hair.h"
|
|
|
|
|
#include "scene/integrator.h"
|
|
|
|
|
#include "scene/light.h"
|
|
|
|
|
#include "scene/mesh.h"
|
|
|
|
|
#include "scene/particles.h"
|
2021-12-01 17:30:46 +01:00
|
|
|
#include "scene/pointcloud.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/scene.h"
|
|
|
|
|
#include "scene/stats.h"
|
|
|
|
|
#include "scene/volume.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/map.h"
|
|
|
|
|
#include "util/murmurhash.h"
|
|
|
|
|
#include "util/progress.h"
|
|
|
|
|
#include "util/set.h"
|
2024-12-26 17:53:59 +01:00
|
|
|
#include "util/tbb.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "subd/patch_table.h"
|
2016-07-16 22:57:06 -04:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2018-03-10 01:15:02 +01: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 04:04:52 +01:00
|
|
|
/* Motion offsets for each object. */
|
|
|
|
|
array<uint> motion_offset;
|
|
|
|
|
|
2018-03-10 01:15:02 +01:00
|
|
|
/* Packed object arrays. Those will be filled in. */
|
|
|
|
|
uint *object_flag;
|
2021-02-28 23:23:24 +01:00
|
|
|
uint *object_visibility;
|
2018-03-10 01:15:02 +01:00
|
|
|
KernelObject *objects;
|
2018-03-10 00:37:07 +01:00
|
|
|
Transform *object_motion_pass;
|
|
|
|
|
DecomposedTransform *object_motion;
|
2020-03-07 14:38:52 +01:00
|
|
|
float *object_volume_step;
|
2018-03-10 01:15:02 +01:00
|
|
|
|
|
|
|
|
/* Flags which will be synchronized to Integrator. */
|
|
|
|
|
bool have_motion;
|
|
|
|
|
bool have_curves;
|
2022-11-14 15:35:47 +00:00
|
|
|
bool have_points;
|
|
|
|
|
bool have_volumes;
|
2018-03-10 01:15:02 +01:00
|
|
|
|
|
|
|
|
/* ** 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 21:44:17 +02:00
|
|
|
NODE_DEFINE(Object)
|
|
|
|
|
{
|
|
|
|
|
NodeType *type = NodeType::add("object", create);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-03-15 16:11:12 +01:00
|
|
|
SOCKET_NODE(geometry, "Geometry", Geometry::get_node_base_type());
|
2016-05-07 21:44:17 +02:00
|
|
|
SOCKET_TRANSFORM(tfm, "Transform", transform_identity());
|
2016-06-12 17:12:25 +02:00
|
|
|
SOCKET_UINT(visibility, "Visibility", ~0);
|
2021-02-17 01:47:18 +01:00
|
|
|
SOCKET_COLOR(color, "Color", zero_float3());
|
2022-03-07 17:34:52 +01:00
|
|
|
SOCKET_FLOAT(alpha, "Alpha", 0.0f);
|
2016-06-12 17:12:25 +02:00
|
|
|
SOCKET_UINT(random_id, "Random ID", 0);
|
2016-05-07 21:44:17 +02:00
|
|
|
SOCKET_INT(pass_id, "Pass ID", 0);
|
|
|
|
|
SOCKET_BOOLEAN(use_holdout, "Use Holdout", false);
|
2016-08-28 21:20:06 +02:00
|
|
|
SOCKET_BOOLEAN(hide_on_missing_motion, "Hide on Missing Motion", false);
|
2021-02-17 01:47:18 +01:00
|
|
|
SOCKET_POINT(dupli_generated, "Dupli Generated", zero_float3());
|
|
|
|
|
SOCKET_POINT2(dupli_uv, "Dupli UV", zero_float2());
|
2018-03-08 04:04:52 +01:00
|
|
|
SOCKET_TRANSFORM_ARRAY(motion, "Motion", array<Transform>());
|
2021-06-28 13:54:18 +02:00
|
|
|
SOCKET_FLOAT(shadow_terminator_shading_offset, "Shadow Terminator Shading Offset", 0.0f);
|
|
|
|
|
SOCKET_FLOAT(shadow_terminator_geometry_offset, "Shadow Terminator Geometry Offset", 0.1f);
|
2020-11-04 11:17:38 +01:00
|
|
|
SOCKET_STRING(asset_name, "Asset Name", ustring());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-09 14:19:01 +01:00
|
|
|
SOCKET_BOOLEAN(is_shadow_catcher, "Shadow Catcher", false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
SOCKET_BOOLEAN(is_caustics_caster, "Cast Shadow Caustics", false);
|
|
|
|
|
SOCKET_BOOLEAN(is_caustics_receiver, "Receive Shadow Caustics", false);
|
|
|
|
|
|
2025-01-02 12:48:21 +01:00
|
|
|
SOCKET_BOOLEAN(is_bake_target, "Bake Target", false);
|
|
|
|
|
|
2021-03-15 16:11:12 +01:00
|
|
|
SOCKET_NODE(particle_system, "Particle System", ParticleSystem::get_node_type());
|
2020-11-04 11:17:38 +01:00
|
|
|
SOCKET_INT(particle_index, "Particle Index", 0);
|
|
|
|
|
|
2021-08-03 12:20:28 +02:00
|
|
|
SOCKET_FLOAT(ao_distance, "AO Distance", 0.0f);
|
|
|
|
|
|
2022-04-02 00:11:11 +02:00
|
|
|
SOCKET_STRING(lightgroup, "Light Group", ustring());
|
2023-05-24 13:36:13 +02:00
|
|
|
SOCKET_UINT(receiver_light_set, "Light Set Index", 0);
|
|
|
|
|
SOCKET_UINT64(light_set_membership, "Light Set Membership", LIGHT_LINK_MASK_ALL);
|
|
|
|
|
SOCKET_UINT(blocker_shadow_set, "Shadow Set Index", 0);
|
|
|
|
|
SOCKET_UINT64(shadow_set_membership, "Shadow Set Membership", LIGHT_LINK_MASK_ALL);
|
2022-04-02 00:11:11 +02:00
|
|
|
|
2016-05-07 21:44:17 +02:00
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 16:11:12 +01:00
|
|
|
Object::Object() : Node(get_node_type())
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
particle_system = nullptr;
|
2014-02-25 18:29:11 +01:00
|
|
|
particle_index = 0;
|
2020-10-26 15:37:07 +01: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;
|
2021-10-22 14:20:22 +02:00
|
|
|
intersects_volume = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
Object::~Object() = default;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
void Object::update_motion()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-03-08 04:04:52 +01:00
|
|
|
if (!use_motion()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
bool have_motion = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01: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 21:20:06 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
/* Otherwise just copy center motion. */
|
|
|
|
|
motion[i] = tfm;
|
2016-08-28 21:20:06 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
/* Test if any of the transforms are actually different. */
|
|
|
|
|
have_motion = have_motion || motion[i] != tfm;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
|
if (!have_motion) {
|
|
|
|
|
motion.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::compute_bounds(bool motion_blur)
|
|
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
BoundBox mbounds = geometry->bounds;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
if (motion_blur && use_motion()) {
|
|
|
|
|
array<DecomposedTransform> decomp(motion.size());
|
|
|
|
|
transform_motion_decompose(decomp.data(), motion.data(), motion.size());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-28 21:20:06 +02:00
|
|
|
bounds = BoundBox::empty;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-20 11:39:03 +11:00
|
|
|
/* TODO: this is really terrible. according to PBRT there is a better
|
2016-08-28 21:20:06 +02: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 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
transform_motion_array_interpolate(&ttfm, decomp.data(), motion.size(), t);
|
2016-08-28 21:20:06 +02:00
|
|
|
bounds.grow(mbounds.transformed(&ttfm));
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-03 10:52:04 +02:00
|
|
|
else {
|
2018-03-08 04:04:52 +01:00
|
|
|
/* No motion blur case. */
|
2020-02-02 12:04:19 +01:00
|
|
|
if (geometry->transform_applied) {
|
2014-10-03 10:52:04 +02:00
|
|
|
bounds = mbounds;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
bounds = mbounds.transformed(&tfm);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2014-05-09 17:02:08 +02:00
|
|
|
void Object::apply_transform(bool apply_to_motion)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!geometry || tfm == transform_identity()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry->apply_transform(tfm, apply_to_motion);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-12 14:29:52 +00:00
|
|
|
/* we keep normals pointing in same direction on negative scale, notify
|
2020-02-02 12:04:19 +01:00
|
|
|
* geometry about this in it (re)calculates normals */
|
2023-09-17 09:01:48 +10:00
|
|
|
if (transform_negative_scale(tfm)) {
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry->transform_negative_scaled = true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (bounds.valid()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry->compute_bounds();
|
2014-03-29 13:03:46 +01:00
|
|
|
compute_bounds(false);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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-15 02:36:21 +10: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 15:01:26 +01:00
|
|
|
uint32_t flag = ObjectManager::UPDATE_NONE;
|
|
|
|
|
|
|
|
|
|
if (is_modified()) {
|
|
|
|
|
flag |= ObjectManager::OBJECT_MODIFIED;
|
|
|
|
|
|
|
|
|
|
if (use_holdout_is_modified()) {
|
|
|
|
|
flag |= ObjectManager::HOLDOUT_MODIFIED;
|
|
|
|
|
}
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
|
|
|
|
if (is_shadow_catcher_is_modified()) {
|
|
|
|
|
scene->tag_shadow_catcher_modified();
|
2023-01-11 21:35:09 +01:00
|
|
|
flag |= ObjectManager::VISIBILITY_MODIFIED;
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +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
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
if (geometry) {
|
2022-05-03 21:54:18 +02:00
|
|
|
if (tfm_is_modified() || motion_is_modified()) {
|
2021-03-24 10:36:31 +01:00
|
|
|
flag |= ObjectManager::TRANSFORM_MODIFIED;
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 15:01:26 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-05-10 18:23:32 +02:00
|
|
|
if (visibility_is_modified()) {
|
|
|
|
|
flag |= ObjectManager::VISIBILITY_MODIFIED;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Node *node : geometry->get_used_shaders()) {
|
2020-11-04 11:17:38 +01:00
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
2023-09-17 09:01:48 +10:00
|
|
|
if (shader->emission_sampling != EMISSION_SAMPLING_NONE) {
|
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->light_manager->tag_update(scene, LightManager::EMISSIVE_MESH_MODIFIED);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-05-14 19:08:13 +05: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 15:01:26 +01:00
|
|
|
scene->object_manager->tag_update(scene, flag);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-08 04:04:52 +01: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 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-10 00:37:07 +01:00
|
|
|
bool Object::is_traceable() const
|
2016-06-06 09:15:34 +02:00
|
|
|
{
|
|
|
|
|
/* Mesh itself can be empty,can skip all such objects. */
|
2021-02-17 01:47:18 +01:00
|
|
|
if (!bounds.valid() || bounds.size() == zero_float3()) {
|
2016-06-06 09:15:34 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* TODO(sergey): Check for mesh vertices/curves. visibility flags. */
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 09:19:40 +02:00
|
|
|
uint Object::visibility_for_tracing() const
|
|
|
|
|
{
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
return SHADOW_CATCHER_OBJECT_VISIBILITY(is_shadow_catcher, visibility & PATH_RAY_ALL_VISIBILITY);
|
2017-08-10 09:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-07 14:38:52 +01:00
|
|
|
float Object::compute_volume_step_size() const
|
|
|
|
|
{
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geometry->geometry_type != Geometry::MESH && geometry->geometry_type != Geometry::VOLUME) {
|
2020-03-16 14:42:56 +01:00
|
|
|
return FLT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Mesh *mesh = static_cast<Mesh *>(geometry);
|
|
|
|
|
|
|
|
|
|
if (!mesh->has_volume) {
|
2020-03-07 14:38:52 +01:00
|
|
|
return FLT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compute step rate from shaders. */
|
|
|
|
|
float step_rate = FLT_MAX;
|
|
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Node *node : mesh->get_used_shaders()) {
|
2020-11-04 11:17:38 +01:00
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
2020-03-07 14:38:52 +01:00
|
|
|
if (shader->has_volume) {
|
2020-11-04 11:17:38 +01:00
|
|
|
if ((shader->get_heterogeneous_volume() && shader->has_volume_spatial_varying) ||
|
2020-03-07 14:38:52 +01:00
|
|
|
(shader->has_volume_attribute_dependency))
|
|
|
|
|
{
|
2020-11-04 11:17:38 +01:00
|
|
|
step_rate = fminf(shader->get_volume_step_rate(), step_rate);
|
2020-03-07 14:38:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (step_rate == FLT_MAX) {
|
|
|
|
|
return FLT_MAX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compute step size from voxel grids. */
|
|
|
|
|
float step_size = FLT_MAX;
|
|
|
|
|
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geometry->is_volume()) {
|
2020-08-19 15:46:50 +02:00
|
|
|
Volume *volume = static_cast<Volume *>(geometry);
|
2020-03-07 14:38:52 +01:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Attribute &attr : volume->attributes.attributes) {
|
2020-08-19 15:46:50 +02:00
|
|
|
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 14:42:56 +01:00
|
|
|
|
2020-08-19 15:46:50 +02:00
|
|
|
/* User specified step size. */
|
2020-11-04 11:17:38 +01:00
|
|
|
float voxel_step_size = volume->get_step_size();
|
2020-03-07 14:38:52 +01:00
|
|
|
|
2020-08-19 15:46:50 +02:00
|
|
|
if (voxel_step_size == 0.0f) {
|
|
|
|
|
/* Auto detect step size. */
|
2021-02-17 01:47:18 +01:00
|
|
|
float3 size = one_float3();
|
2020-11-04 15:09:06 +01:00
|
|
|
#ifdef WITH_NANOVDB
|
2022-05-20 18:01:26 +02:00
|
|
|
/* Dimensions were not applied to image transform with NanoVDB (see image_vdb.cpp) */
|
2020-11-04 15:09:06 +01:00
|
|
|
if (metadata.type != IMAGE_DATA_TYPE_NANOVDB_FLOAT &&
|
2022-05-20 18:01:26 +02:00
|
|
|
metadata.type != IMAGE_DATA_TYPE_NANOVDB_FLOAT3 &&
|
|
|
|
|
metadata.type != IMAGE_DATA_TYPE_NANOVDB_FPN &&
|
|
|
|
|
metadata.type != IMAGE_DATA_TYPE_NANOVDB_FP16)
|
2020-11-04 15:09:06 +01:00
|
|
|
#endif
|
2024-12-26 17:53:59 +01:00
|
|
|
{
|
2020-11-04 15:09:06 +01:00
|
|
|
size /= make_float3(metadata.width, metadata.height, metadata.depth);
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
2020-08-19 15:46:50 +02: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);
|
|
|
|
|
}
|
2022-06-23 14:29:17 +02:00
|
|
|
voxel_step_size = reduce_min(fabs(transform_direction(&voxel_tfm, size)));
|
2020-08-19 15:46:50 +02:00
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
else if (volume->get_object_space()) {
|
2020-08-19 15:46:50 +02:00
|
|
|
/* User specified step size in object space. */
|
|
|
|
|
float3 size = make_float3(voxel_step_size, voxel_step_size, voxel_step_size);
|
2022-06-23 14:29:17 +02:00
|
|
|
voxel_step_size = reduce_min(fabs(transform_direction(&tfm, size)));
|
2020-03-16 14:42:56 +01:00
|
|
|
}
|
2020-03-07 14:38:52 +01:00
|
|
|
|
2020-08-19 15:46:50 +02:00
|
|
|
if (voxel_step_size > 0.0f) {
|
|
|
|
|
step_size = fminf(voxel_step_size, step_size);
|
|
|
|
|
}
|
2020-03-07 14:38:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (step_size == FLT_MAX) {
|
|
|
|
|
/* Fall back to 1/10th of bounds for procedural volumes. */
|
2024-04-24 20:15:58 +02:00
|
|
|
assert(bounds.valid());
|
2020-03-07 14:38:52 +01:00
|
|
|
step_size = 0.1f * average(bounds.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
step_size *= step_rate;
|
|
|
|
|
|
|
|
|
|
return step_size;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
int Object::get_device_index() const
|
|
|
|
|
{
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 10:54:17 +02:00
|
|
|
bool Object::usable_as_light() const
|
|
|
|
|
{
|
|
|
|
|
Geometry *geom = get_geometry();
|
|
|
|
|
if (!geom->is_mesh() && !geom->is_volume()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* Skip non-traceable objects. */
|
|
|
|
|
if (!is_traceable()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* Skip if we are not visible for BSDFs. */
|
2024-01-02 13:53:56 +01:00
|
|
|
if (!(get_visibility() &
|
|
|
|
|
(PATH_RAY_DIFFUSE | PATH_RAY_GLOSSY | PATH_RAY_TRANSMIT | PATH_RAY_VOLUME_SCATTER)))
|
|
|
|
|
{
|
2023-04-03 10:54:17 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/* Skip if we have no emission shaders. */
|
|
|
|
|
/* TODO(sergey): Ideally we want to avoid such duplicated loop, since it'll
|
|
|
|
|
* iterate all geometry shaders twice (when counting and when calculating
|
|
|
|
|
* triangle area.
|
|
|
|
|
*/
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Node *node : geom->get_used_shaders()) {
|
2023-04-03 10:54:17 +02:00
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
|
|
|
|
if (shader->emission_sampling != EMISSION_SAMPLING_NONE) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-26 12:21:44 +02:00
|
|
|
bool Object::has_light_linking() const
|
|
|
|
|
{
|
|
|
|
|
if (get_receiver_light_set()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_light_set_membership() != LIGHT_LINK_MASK_ALL) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Object::has_shadow_linking() const
|
|
|
|
|
{
|
|
|
|
|
if (get_blocker_shadow_set()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_shadow_set_membership() != LIGHT_LINK_MASK_ALL) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
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 15:01:26 +01:00
|
|
|
update_flags = UPDATE_ALL;
|
2015-01-19 19:08:58 +05:00
|
|
|
need_flags_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
ObjectManager::~ObjectManager() = default;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-12-24 14:19:21 +01:00
|
|
|
static float object_volume_density(const Transform &tfm, Geometry *geom)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_volume()) {
|
2020-03-16 14:42:56 +01:00
|
|
|
/* Volume density automatically adjust to object scale. */
|
2020-12-24 13:45:04 +01:00
|
|
|
if (static_cast<Volume *>(geom)->get_object_space()) {
|
2021-02-17 01:47:18 +01:00
|
|
|
const float3 unit = normalize(one_float3());
|
2020-03-16 14:42:56 +01:00
|
|
|
return 1.0f / len(transform_direction(&tfm, unit));
|
|
|
|
|
}
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-12-24 13:45:04 +01:00
|
|
|
return 1.0f;
|
2020-02-02 12:04:19 +01: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
|
|
|
void ObjectManager::device_update_object_transform(UpdateObjectTransformState *state,
|
|
|
|
|
Object *ob,
|
2022-04-02 00:11:11 +02:00
|
|
|
bool update_all,
|
|
|
|
|
const Scene *scene)
|
2020-02-02 12:04:19 +01: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 04:04:52 +01:00
|
|
|
kobject.tfm = tfm;
|
|
|
|
|
kobject.itfm = itfm;
|
2020-12-24 14:19:21 +01:00
|
|
|
kobject.volume_density = object_volume_density(tfm, geom);
|
2019-08-22 14:26:09 +02:00
|
|
|
kobject.color[0] = color.x;
|
|
|
|
|
kobject.color[1] = color.y;
|
|
|
|
|
kobject.color[2] = color.z;
|
2022-03-07 17:34:52 +01:00
|
|
|
kobject.alpha = ob->alpha;
|
2018-03-07 22:19:56 +01:00
|
|
|
kobject.pass_id = pass_id;
|
|
|
|
|
kobject.random_number = random_number;
|
|
|
|
|
kobject.particle_index = particle_index;
|
2018-03-08 04:04:52 +01:00
|
|
|
kobject.motion_offset = 0;
|
2021-08-03 12:20:28 +02:00
|
|
|
kobject.ao_distance = ob->ao_distance;
|
2023-05-24 13:36:13 +02:00
|
|
|
kobject.receiver_light_set = ob->receiver_light_set >= LIGHT_LINK_SET_MAX ?
|
|
|
|
|
0 :
|
|
|
|
|
ob->receiver_light_set;
|
|
|
|
|
kobject.light_set_membership = ob->light_set_membership;
|
|
|
|
|
kobject.blocker_shadow_set = ob->blocker_shadow_set >= LIGHT_LINK_SET_MAX ?
|
|
|
|
|
0 :
|
|
|
|
|
ob->blocker_shadow_set;
|
|
|
|
|
kobject.shadow_set_membership = ob->shadow_set_membership;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
if (geom->get_use_motion_blur()) {
|
2017-08-17 12:44:09 +02:00
|
|
|
state->have_motion = true;
|
|
|
|
|
}
|
2020-02-02 12:04:19 +01:00
|
|
|
|
Fix T89037: Cycles: Backfacing node can be wrong for lights with negative scale
When rendering in the viewport (or probably on instanced objects, but I didn't
test that), emissive objects whose scale is negative give the wrong value on the
"backfacing" input when multiple sampling is enabled.
The underlying problem was a corner case in how normal transformation is handled,
which is generally a bit messy.
From what I can tell, the pattern appears to be:
- If you first transform vertices to world space and then compute the normal from
them (as triangle light samping, MNEE and light tree do), you need to flip
whenever the transform has negative scale regardless of whether the transform
has been applied
- If you compute the normal in object space and then transform it to world space
(as the regular shader_setup_from_ray path does), you only need to flip if the
transform was already applied and was negative
- If you get the normal from a local intersection result (as bevel and SSS do),
you only need to flip if the transform was already applied and was negative
- If you get the normal from vertex normals, you don't need to do anything since
the host-side code does the flip for you (arguably it'd be more consistent to
do this in the kernel as well, but meh, not worth the potential slowdown)
So, this patch fixes the logic in the triangle emission code.
Also, turns out that the MNEE code had the same problem and was also having
problems in the viewport on negative-scale objects, this is also fixed now.
Differential Revision: https://developer.blender.org/D16952
2023-01-10 02:32:16 +01:00
|
|
|
if (transform_negative_scale(tfm)) {
|
|
|
|
|
flag |= SD_OBJECT_NEGATIVE_SCALE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh() || geom->is_pointcloud()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
/* TODO: why only mesh? */
|
2024-12-26 17:53:54 +01:00
|
|
|
if (geom->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) {
|
2020-02-02 12:04:19 +01:00
|
|
|
flag |= SD_OBJECT_HAS_VERTEX_MOTION;
|
|
|
|
|
}
|
2017-08-17 12:44:09 +02:00
|
|
|
}
|
2022-04-19 16:28:14 +02:00
|
|
|
else if (geom->is_volume()) {
|
|
|
|
|
Volume *volume = static_cast<Volume *>(geom);
|
|
|
|
|
if (volume->attributes.find(ATTR_STD_VOLUME_VELOCITY) && volume->get_velocity_scale() != 0.0f)
|
|
|
|
|
{
|
|
|
|
|
flag |= SD_OBJECT_HAS_VOLUME_MOTION;
|
|
|
|
|
kobject.velocity_scale = volume->get_velocity_scale();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
if (state->need_motion == Scene::MOTION_PASS) {
|
2018-03-08 04:04:52 +01:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
|
ob->update_motion();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01: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-06 00:38:23 +02:00
|
|
|
}
|
2018-03-08 04:04:52 +01:00
|
|
|
else {
|
|
|
|
|
tfm_pre = tfm;
|
|
|
|
|
tfm_post = tfm;
|
2016-08-06 00:38:23 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01: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 12:04:19 +01:00
|
|
|
if (!(flag & SD_OBJECT_HAS_VERTEX_MOTION)) {
|
2018-03-08 04:04:52 +01:00
|
|
|
tfm_pre = tfm_pre * itfm;
|
|
|
|
|
tfm_post = tfm_post * itfm;
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
int motion_pass_offset = ob->index * OBJECT_MOTION_PASS_SIZE;
|
2018-03-08 04:04:52 +01:00
|
|
|
object_motion_pass[motion_pass_offset + 0] = tfm_pre;
|
|
|
|
|
object_motion_pass[motion_pass_offset + 1] = tfm_post;
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
|
|
|
|
else if (state->need_motion == Scene::MOTION_BLUR) {
|
2018-03-08 04:04:52 +01:00
|
|
|
if (ob->use_motion()) {
|
2018-11-29 02:06:30 +01:00
|
|
|
kobject.motion_offset = state->motion_offset[ob->index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
/* Decompose transforms for interpolation. */
|
2022-05-03 21:54:18 +02:00
|
|
|
if (ob->tfm_is_modified() || ob->motion_is_modified() || update_all) {
|
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
|
|
|
DecomposedTransform *decomp = state->object_motion + kobject.motion_offset;
|
|
|
|
|
transform_motion_decompose(decomp, ob->motion.data(), ob->motion.size());
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
flag |= SD_OBJECT_MOTION;
|
|
|
|
|
state->have_motion = true;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
/* Dupli object coords and motion info. */
|
2018-03-07 22:19:56 +01: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];
|
|
|
|
|
kobject.dupli_uv[0] = ob->dupli_uv[0];
|
|
|
|
|
kobject.dupli_uv[1] = ob->dupli_uv[1];
|
2020-11-04 11:17:38 +01:00
|
|
|
int totalsteps = geom->get_motion_steps();
|
2018-03-07 22:19:56 +01:00
|
|
|
kobject.numsteps = (totalsteps - 1) / 2;
|
2024-10-30 16:45:56 +01:00
|
|
|
kobject.numverts = (geom->is_mesh() || geom->is_volume()) ?
|
2020-11-04 11:17:38 +01:00
|
|
|
static_cast<Mesh *>(geom)->get_verts().size() :
|
2024-10-30 16:45:56 +01:00
|
|
|
geom->is_hair() ? static_cast<Hair *>(geom)->get_curve_keys().size() :
|
|
|
|
|
geom->is_pointcloud() ? static_cast<PointCloud *>(geom)->num_points() :
|
|
|
|
|
0;
|
2018-03-07 22:19:56 +01: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 15:01:26 +01: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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 13:54:18 +02:00
|
|
|
kobject.shadow_terminator_shading_offset = 1.0f /
|
|
|
|
|
(1.0f - 0.5f * ob->shadow_terminator_shading_offset);
|
|
|
|
|
kobject.shadow_terminator_geometry_offset = ob->shadow_terminator_geometry_offset;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
kobject.visibility = ob->visibility_for_tracing();
|
|
|
|
|
kobject.primitive_type = geom->primitive_type();
|
|
|
|
|
|
Cycles: approximate shadow caustics using manifold next event estimation
This adds support for selective rendering of caustics in shadows of refractive
objects. Example uses are rendering of underwater caustics and eye caustics.
This is based on "Manifold Next Event Estimation", a method developed for
production rendering. The idea is to selectively enable shadow caustics on a
few objects in the scene where they have a big visual impact, without impacting
render performance for the rest of the scene.
The Shadow Caustic option must be manually enabled on light, caustic receiver
and caster objects. For such light paths, the Filter Glossy option will be
ignored and replaced by sharp caustics.
Currently this method has a various limitations:
* Only caustics in shadows of refractive objects work, which means no caustics
from reflection or caustics that outside shadows. Only up to 4 refractive
caustic bounces are supported.
* Caustic caster objects should have smooth normals.
* Not currently support for Metal GPU rendering.
In the future this method may be extended for more general caustics.
TECHNICAL DETAILS
This code adds manifold next event estimation through refractive surface(s) as a
new sampling technique for direct lighting, i.e. finding the point on the
refractive surface(s) along the path to a light sample, which satisfies Fermat's
principle for a given microfacet normal and the path's end points. This
technique involves walking on the "specular manifold" using a pseudo newton
solver. Such a manifold is defined by the specular constraint matrix from the
manifold exploration framework [2]. For each refractive interface, this
constraint is defined by enforcing that the generalized half-vector projection
onto the interface local tangent plane is null. The newton solver guides the
walk by linearizing the manifold locally before reprojecting the linear solution
onto the refractive surface. See paper [1] for more details about the technique
itself and [3] for the half-vector light transport formulation, from which it is
derived.
[1] Manifold Next Event Estimation
Johannes Hanika, Marc Droske, and Luca Fascione. 2015.
Comput. Graph. Forum 34, 4 (July 2015), 87–97.
https://jo.dreggn.org/home/2015_mnee.pdf
[2] Manifold exploration: a Markov Chain Monte Carlo technique for rendering
scenes with difficult specular transport Wenzel Jakob and Steve Marschner.
2012. ACM Trans. Graph. 31, 4, Article 58 (July 2012), 13 pages.
https://www.cs.cornell.edu/projects/manifolds-sg12/
[3] The Natural-Constraint Representation of the Path Space for Efficient
Light Transport Simulation. Anton S. Kaplanyan, Johannes Hanika, and Carsten
Dachsbacher. 2014. ACM Trans. Graph. 33, 4, Article 102 (July 2014), 13 pages.
https://cg.ivd.kit.edu/english/HSLT.php
The code for this samping technique was inserted at the light sampling stage
(direct lighting). If the walk is successful, it turns off path regularization
using a specialized flag in the path state (PATH_MNEE_SUCCESS). This flag tells
the integrator not to blur the brdf roughness further down the path (in a child
ray created from BSDF sampling). In addition, using a cascading mechanism of
flag values, we cull connections to caustic lights for this and children rays,
which should be resolved through MNEE.
This mechanism also cancels the MIS bsdf counter part at the casutic receiver
depth, in essence leaving MNEE as the only sampling technique from receivers
through refractive casters to caustic lights. This choice might not be optimal
when the light gets large wrt to the receiver, though this is usually not when
you want to use MNEE.
This connection culling strategy removes a fair amount of fireflies, at the cost
of introducing a slight bias. Because of the selective nature of the culling
mechanism, reflective caustics still benefit from the native path
regularization, which further removes fireflies on other surfaces (bouncing
light off casters).
Differential Revision: https://developer.blender.org/D13533
2022-04-01 15:44:24 +02:00
|
|
|
/* Object shadow caustics flag */
|
|
|
|
|
if (ob->is_caustics_caster) {
|
|
|
|
|
flag |= SD_OBJECT_CAUSTICS_CASTER;
|
|
|
|
|
}
|
|
|
|
|
if (ob->is_caustics_receiver) {
|
|
|
|
|
flag |= SD_OBJECT_CAUSTICS_RECEIVER;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
/* Object flag. */
|
|
|
|
|
if (ob->use_holdout) {
|
2016-12-23 10:49:59 +01:00
|
|
|
flag |= SD_OBJECT_HOLDOUT_MASK;
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2018-11-29 02:06:30 +01:00
|
|
|
state->object_flag[ob->index] = flag;
|
2020-03-07 14:38:52 +01:00
|
|
|
state->object_volume_step[ob->index] = FLT_MAX;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
/* Have curves. */
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_hair()) {
|
2016-04-20 18:12:26 +02:00
|
|
|
state->have_curves = true;
|
|
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_pointcloud()) {
|
2022-11-14 15:35:47 +00:00
|
|
|
state->have_points = true;
|
|
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_volume()) {
|
2022-11-14 15:35:47 +00:00
|
|
|
state->have_volumes = true;
|
|
|
|
|
}
|
2022-04-02 00:11:11 +02:00
|
|
|
|
|
|
|
|
/* Light group. */
|
|
|
|
|
auto it = scene->lightgroups.find(ob->lightgroup);
|
|
|
|
|
if (it != scene->lightgroups.end()) {
|
|
|
|
|
kobject.lightgroup = it->second;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kobject.lightgroup = LIGHTGROUP_NONE;
|
|
|
|
|
}
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2012-10-04 21:40:39 +00:00
|
|
|
|
2021-11-29 15:06:22 +00:00
|
|
|
void ObjectManager::device_update_prim_offsets(Device *device, DeviceScene *dscene, Scene *scene)
|
|
|
|
|
{
|
2022-12-02 19:04:00 +01:00
|
|
|
if (!scene->integrator->get_use_light_tree()) {
|
2023-04-06 12:16:13 +02:00
|
|
|
BVHLayoutMask layout_mask = device->get_bvh_layout_mask(dscene->data.kernel_features);
|
2022-12-02 19:04:00 +01:00
|
|
|
if (layout_mask != BVH_LAYOUT_METAL && layout_mask != BVH_LAYOUT_MULTI_METAL &&
|
2023-04-24 19:05:30 +02:00
|
|
|
layout_mask != BVH_LAYOUT_MULTI_METAL_EMBREE && layout_mask != BVH_LAYOUT_HIPRT &&
|
|
|
|
|
layout_mask != BVH_LAYOUT_MULTI_HIPRT && layout_mask != BVH_LAYOUT_MULTI_HIPRT_EMBREE)
|
|
|
|
|
{
|
2022-12-02 19:04:00 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-11-29 15:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* On MetalRT, primitive / curve segment offsets can't be baked at BVH build time. Intersection
|
|
|
|
|
* handlers need to apply the offset manually. */
|
|
|
|
|
uint *object_prim_offset = dscene->object_prim_offset.alloc(scene->objects.size());
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *ob : scene->objects) {
|
2021-11-29 15:06:22 +00:00
|
|
|
uint32_t prim_offset = 0;
|
|
|
|
|
if (Geometry *const geom = ob->geometry) {
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_hair()) {
|
2021-11-29 15:06:22 +00:00
|
|
|
prim_offset = ((Hair *const)geom)->curve_segment_offset;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
prim_offset = geom->prim_offset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uint obj_index = ob->get_device_index();
|
|
|
|
|
object_prim_offset[obj_index] = prim_offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dscene->object_prim_offset.copy_to_device();
|
|
|
|
|
dscene->object_prim_offset.clear_modified();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 11:45:16 +01:00
|
|
|
void ObjectManager::device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress)
|
2016-04-20 18:12:26 +02:00
|
|
|
{
|
2018-02-05 11:01:00 +02:00
|
|
|
UpdateObjectTransformState state;
|
2018-01-12 19:56:52 +01:00
|
|
|
state.need_motion = scene->need_motion();
|
2016-04-20 18:12:26 +02:00
|
|
|
state.have_motion = false;
|
|
|
|
|
state.have_curves = false;
|
2022-11-14 15:35:47 +00:00
|
|
|
state.have_points = false;
|
|
|
|
|
state.have_volumes = false;
|
2016-04-20 18:12:26 +02:00
|
|
|
state.scene = scene;
|
|
|
|
|
state.queue_start_object = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-07 22:19:56 +01:00
|
|
|
state.objects = dscene->objects.alloc(scene->objects.size());
|
2018-03-10 01:15:02 +01:00
|
|
|
state.object_flag = dscene->object_flag.alloc(scene->objects.size());
|
2020-03-07 14:38:52 +01:00
|
|
|
state.object_volume_step = dscene->object_volume_step.alloc(scene->objects.size());
|
2024-12-26 17:53:55 +01:00
|
|
|
state.object_motion = nullptr;
|
|
|
|
|
state.object_motion_pass = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
if (state.need_motion == Scene::MOTION_PASS) {
|
2018-03-10 00:37:07 +01:00
|
|
|
state.object_motion_pass = dscene->object_motion_pass.alloc(OBJECT_MOTION_PASS_SIZE *
|
|
|
|
|
scene->objects.size());
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2018-03-08 04:04:52 +01: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 06:17:24 +02:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *ob : scene->objects) {
|
2018-03-08 04:04:52 +01:00
|
|
|
*motion_offsets = motion_offset;
|
|
|
|
|
motion_offsets++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
/* Clear motion array if there is no actual motion. */
|
|
|
|
|
ob->update_motion();
|
|
|
|
|
motion_offset += ob->motion.size();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
state.object_motion = dscene->object_motion.alloc(motion_offset);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
/* Particle system device offsets
|
|
|
|
|
* 0 is dummy particle, index starts at 1.
|
|
|
|
|
*/
|
|
|
|
|
int numparticles = 1;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (ParticleSystem *psys : scene->particle_systems) {
|
2016-04-20 18:12:26 +02:00
|
|
|
state.particle_offset[psys] = numparticles;
|
|
|
|
|
numparticles += psys->particles.size();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +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
|
|
|
/* 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 23:13:02 +10:00
|
|
|
/* Parallel object update, with grain size to avoid too much threading overhead
|
2020-06-05 12:53:38 +02: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];
|
2022-04-02 00:11:11 +02:00
|
|
|
device_update_object_transform(&state, ob, update_all, scene);
|
2020-06-05 12:53:38 +02:00
|
|
|
}
|
|
|
|
|
});
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-24 17:08:01 +02: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 15:01:26 +01:00
|
|
|
dscene->objects.copy_to_device_if_modified();
|
2016-04-20 18:12:26 +02:00
|
|
|
if (state.need_motion == Scene::MOTION_PASS) {
|
2018-03-10 00:37:07 +01:00
|
|
|
dscene->object_motion_pass.copy_to_device();
|
2016-04-20 18:12:26 +02:00
|
|
|
}
|
2018-03-08 04:04:52 +01:00
|
|
|
else if (state.need_motion == Scene::MOTION_BLUR) {
|
|
|
|
|
dscene->object_motion.copy_to_device();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-20 18:12:26 +02:00
|
|
|
dscene->data.bvh.have_motion = state.have_motion;
|
|
|
|
|
dscene->data.bvh.have_curves = state.have_curves;
|
2022-11-14 15:35:47 +00:00
|
|
|
dscene->data.bvh.have_points = state.have_points;
|
|
|
|
|
dscene->data.bvh.have_volumes = state.have_volumes;
|
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
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!need_update()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2016-04-22 10:55:26 +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
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 19:39:13 +02:00
|
|
|
VLOG_INFO << "Total " << scene->objects.size() << " objects.";
|
2016-04-22 10:55:26 +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
|
|
|
device_free(device, dscene, false);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (scene->objects.empty()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-10-01 23:16:01 +02: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;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-10-01 23:16:01 +02:00
|
|
|
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 15:01:26 +01: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 23:16:01 +02:00
|
|
|
}
|
2018-11-29 02:06:30 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-01 23:16:01 +02: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
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (progress.get_cancel()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
/* prepare for static BVH building */
|
|
|
|
|
/* todo: do before to support getting object level coords? */
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
if (scene->params.bvh_type == BVH_TYPE_STATIC) {
|
2020-10-01 23:16:01 +02: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 01:15:02 +01:00
|
|
|
apply_static_transforms(dscene, scene, progress);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-11-04 11:17:38 +01:00
|
|
|
object->clear_modified();
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
void ObjectManager::device_update_flags(Device * /*unused*/,
|
|
|
|
|
DeviceScene *dscene,
|
|
|
|
|
Scene *scene,
|
|
|
|
|
Progress & /*progress*/,
|
|
|
|
|
bool bounds_valid)
|
2014-10-03 12:11:19 +02:00
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!need_update() && !need_flags_update) {
|
2014-10-03 12:11:19 +02:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-01 23:16:01 +02:00
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
|
if (scene->update_stats) {
|
|
|
|
|
scene->update_stats->object.times.add_entry({"device_update_flags", time});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-04-24 20:15:58 +02:00
|
|
|
if (bounds_valid) {
|
|
|
|
|
/* Object flags and calculations related to volume depend on proper bounds calculated, which
|
|
|
|
|
* might not be available yet when object flags are updated for displacement or hair
|
|
|
|
|
* transparency calculation. In this case do not clear the need_flags_update, so that these
|
|
|
|
|
* values which depend on bounds are re-calculated when the device_update process comes back
|
|
|
|
|
* here from the "Updating Objects Flags" stage. */
|
|
|
|
|
update_flags = UPDATE_NONE;
|
|
|
|
|
need_flags_update = false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (scene->objects.empty()) {
|
2014-10-03 12:11:19 +02:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-10 01:15:02 +01:00
|
|
|
/* Object info flag. */
|
2017-11-05 00:34:30 +01:00
|
|
|
uint *object_flag = dscene->object_flag.data();
|
2020-03-07 14:38:52 +01:00
|
|
|
float *object_volume_step = dscene->object_volume_step.data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-10 01:15:02 +01:00
|
|
|
/* Object volume intersection. */
|
2014-10-03 12:11:19 +02:00
|
|
|
vector<Object *> volume_objects;
|
2015-06-01 23:59:23 +05:00
|
|
|
bool has_volume_objects = false;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-02-02 12:04:19 +01:00
|
|
|
if (object->geometry->has_volume) {
|
2024-05-31 15:53:12 +02:00
|
|
|
/* If the bounds are not valid it is not always possible to calculate the volume step, and
|
|
|
|
|
* the step size is not needed for the displacement. So, delay calculation of the volume
|
|
|
|
|
* step size until the final bounds are known. */
|
2015-06-01 23:59:23 +05:00
|
|
|
if (bounds_valid) {
|
|
|
|
|
volume_objects.push_back(object);
|
2024-05-31 15:53:12 +02:00
|
|
|
object_volume_step[object->index] = object->compute_volume_step_size();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
object_volume_step[object->index] = FLT_MAX;
|
2015-06-01 23:59:23 +05:00
|
|
|
}
|
|
|
|
|
has_volume_objects = true;
|
2020-03-07 14:38:52 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
object_volume_step[object->index] = FLT_MAX;
|
2014-10-03 12:11:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-02-02 12:04:19 +01:00
|
|
|
if (object->geometry->has_volume) {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME;
|
|
|
|
|
object_flag[object->index] &= ~SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Attribute &attr : object->geometry->attributes.attributes) {
|
2018-02-18 03:20:39 +01:00
|
|
|
if (attr.element == ATTR_ELEMENT_VOXEL) {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] |= SD_OBJECT_HAS_VOLUME_ATTRIBUTES;
|
2018-02-18 03:20:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
2014-10-03 12:11:19 +02:00
|
|
|
}
|
2015-01-19 19:08:58 +05:00
|
|
|
else {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] &= ~(SD_OBJECT_HAS_VOLUME | SD_OBJECT_HAS_VOLUME_ATTRIBUTES);
|
2015-01-19 19:08:58 +05:00
|
|
|
}
|
2020-03-07 14:38:52 +01:00
|
|
|
|
2017-02-09 14:19:01 +01:00
|
|
|
if (object->is_shadow_catcher) {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] |= SD_OBJECT_SHADOW_CATCHER;
|
2017-02-09 14:19:01 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] &= ~SD_OBJECT_SHADOW_CATCHER;
|
2017-02-09 14:19:01 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-01 23:59:23 +05:00
|
|
|
if (bounds_valid) {
|
2021-10-22 14:20:22 +02:00
|
|
|
object->intersects_volume = false;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *volume_object : volume_objects) {
|
2015-06-01 23:59:23 +05:00
|
|
|
if (object == volume_object) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (object->bounds.intersects(volume_object->bounds)) {
|
2018-11-29 02:06:30 +01:00
|
|
|
object_flag[object->index] |= SD_OBJECT_INTERSECTS_VOLUME;
|
2021-10-22 14:20:22 +02:00
|
|
|
object->intersects_volume = true;
|
2015-06-01 23:59:23 +05:00
|
|
|
break;
|
|
|
|
|
}
|
2014-10-03 12:11:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-01 23:59:23 +05: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 02:06:30 +01:00
|
|
|
object_flag[object->index] |= SD_OBJECT_INTERSECTS_VOLUME;
|
2015-06-01 23:59:23 +05:00
|
|
|
}
|
2014-10-03 12:11:19 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-10 01:15:02 +01:00
|
|
|
/* Copy object flag. */
|
2017-10-21 01:09:59 +02:00
|
|
|
dscene->object_flag.copy_to_device();
|
2020-03-07 14:38:52 +01: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 15:01:26 +01:00
|
|
|
|
|
|
|
|
dscene->object_flag.clear_modified();
|
|
|
|
|
dscene->object_volume_step.clear_modified();
|
2014-10-03 12:11:19 +02:00
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
void ObjectManager::device_update_geom_offsets(Device * /*unused*/,
|
|
|
|
|
DeviceScene *dscene,
|
|
|
|
|
Scene *scene)
|
2016-07-16 22:57:06 -04:00
|
|
|
{
|
2018-01-02 22:56:07 +01:00
|
|
|
if (dscene->objects.size() == 0) {
|
2016-08-09 04:32:38 +02:00
|
|
|
return;
|
2016-10-24 12:26:12 +02:00
|
|
|
}
|
2016-08-09 04:32:38 +02:00
|
|
|
|
2018-03-07 22:19:56 +01:00
|
|
|
KernelObject *kobjects = dscene->objects.data();
|
2016-07-16 22:57:06 -04:00
|
|
|
|
|
|
|
|
bool update = false;
|
|
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Geometry *geom = object->geometry;
|
|
|
|
|
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh()) {
|
2020-02-02 12:04:19 +01: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-16 22:57:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-26 15:37:07 +01: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 17:40:36 +01:00
|
|
|
update = true;
|
|
|
|
|
}
|
2016-07-16 22:57:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (update) {
|
2017-10-21 01:09:59 +02:00
|
|
|
dscene->objects.copy_to_device();
|
2016-07-16 22:57:06 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
void ObjectManager::device_free(Device * /*unused*/, 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 15:01:26 +01: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);
|
2021-11-29 15:06:22 +00:00
|
|
|
dscene->object_prim_offset.free_if_need_realloc(force_free);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-10 01:15:02 +01: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 12:04:19 +01:00
|
|
|
/* todo: create objects/geometry in right order! */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 12:04:19 +01: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 17:02:08 +02:00
|
|
|
bool apply_to_motion = need_motion != Scene::MOTION_PASS;
|
2012-12-01 19:15:05 +00:00
|
|
|
int i = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2020-02-02 12:04:19 +01:00
|
|
|
map<Geometry *, int>::iterator it = geometry_users.find(object->geometry);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (it == geometry_users.end()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_users[object->geometry] = 1;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-04-27 11:58:34 +00:00
|
|
|
it->second++;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (progress.get_cancel()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-10 01:15:02 +01:00
|
|
|
uint *object_flag = dscene->object_flag.data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
/* apply transforms for objects with single user geometry */
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2016-03-31 17:46:22 +02:00
|
|
|
/* Annoying feedback loop here: we can't use is_instanced() because
|
|
|
|
|
* it'll use uninitialized transform_applied flag.
|
|
|
|
|
*
|
2020-02-02 12:04:19 +01:00
|
|
|
* Could be solved by moving reference counter to Geometry.
|
2016-03-31 17:46:22 +02:00
|
|
|
*/
|
2020-02-02 12:04:19 +01:00
|
|
|
Geometry *geom = object->geometry;
|
|
|
|
|
bool apply = (geometry_users[geom] == 1) && !geom->has_surface_bssrdf &&
|
|
|
|
|
!geom->has_true_displacement();
|
|
|
|
|
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
apply = apply && mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE;
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geom->is_hair()) {
|
2020-07-07 14:47:59 +02: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 12:04:19 +01:00
|
|
|
|
|
|
|
|
if (apply) {
|
2018-03-08 04:04:52 +01:00
|
|
|
if (!(motion_blur && object->use_motion())) {
|
2020-02-02 12:04:19 +01:00
|
|
|
if (!geom->transform_applied) {
|
2014-05-09 17:02:08 +02:00
|
|
|
object->apply_transform(apply_to_motion);
|
2020-02-02 12:04:19 +01:00
|
|
|
geom->transform_applied = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (progress.get_cancel()) {
|
2012-04-30 12:49:26 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-12-23 10:49:59 +01:00
|
|
|
object_flag[i] |= SD_OBJECT_TRANSFORM_APPLIED;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02: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 15:01:26 +01: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 11:54:29 +01: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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 10:36:31 +01:00
|
|
|
if ((flag & TRANSFORM_MODIFIED) != 0) {
|
|
|
|
|
geometry_flag |= GeometryManager::TRANSFORM_MODIFIED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-10 18:23:32 +02:00
|
|
|
if ((flag & VISIBILITY_MODIFIED) != 0) {
|
|
|
|
|
geometry_flag |= GeometryManager::VISIBILITY_MODIFIED;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-11 11:54:29 +01:00
|
|
|
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 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scene->light_manager->tag_update(scene, LightManager::OBJECT_MANAGER);
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
|
|
|
|
|
/* Integrator's shadow catcher settings depends on object visibility settings. */
|
|
|
|
|
if (flag & (OBJECT_ADDED | OBJECT_REMOVED | OBJECT_MODIFIED)) {
|
|
|
|
|
scene->integrator->tag_update(scene, Integrator::OBJECT_MANAGER);
|
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 15:01:26 +01:00
|
|
|
return update_flags != UPDATE_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-07 04:05:47 +01:00
|
|
|
string ObjectManager::get_cryptomatte_objects(Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
string manifest = "{";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
unordered_set<ustring> objects;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *object : scene->objects) {
|
2018-11-07 04:05:47 +01:00
|
|
|
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 = "{";
|
2024-10-17 19:48:38 +02:00
|
|
|
unordered_set<ustring> assets;
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Object *ob : scene->objects) {
|
2018-11-07 04:05:47 +01:00
|
|
|
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
|