2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/camera.h"
|
|
|
|
#include "render/graph.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/integrator.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/light.h"
|
|
|
|
#include "render/mesh.h"
|
|
|
|
#include "render/nodes.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/object.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/particles.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/scene.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "blender/blender_object_cull.h"
|
|
|
|
#include "blender/blender_sync.h"
|
|
|
|
#include "blender/blender_util.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_hash.h"
|
|
|
|
#include "util/util_logging.h"
|
2020-10-21 16:38:36 +02:00
|
|
|
#include "util/util_task.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Utilities */
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
bool BlenderSync::BKE_object_is_modified(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* test if we can instance or if the object is modified */
|
2014-02-21 15:03:24 +01:00
|
|
|
if (b_ob.type() == BL::Object::type_META) {
|
|
|
|
/* multi-user and dupli metaballs are fused, can't instance */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ccl::BKE_object_is_modified(b_ob, b_scene, preview)) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* modifiers */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* object level material links */
|
2021-01-25 16:20:10 +01:00
|
|
|
for (BL::MaterialSlot &b_slot : b_ob.material_slots) {
|
|
|
|
if (b_slot.link() == BL::MaterialSlot::link_OBJECT) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2021-01-25 16:20:10 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-09 18:54:42 +02:00
|
|
|
bool BlenderSync::object_is_geometry(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
BL::ID b_ob_data = b_ob.data();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-29 03:56:14 +02:00
|
|
|
if (!b_ob_data) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-17 16:52:14 +01:00
|
|
|
BL::Object::type_enum type = b_ob.type();
|
|
|
|
|
2020-03-17 16:30:48 +01:00
|
|
|
if (type == BL::Object::type_VOLUME || type == BL::Object::type_HAIR) {
|
2020-03-17 16:52:14 +01:00
|
|
|
/* Will be exported attached to mesh. */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == BL::Object::type_CURVE) {
|
2017-09-29 03:56:14 +02:00
|
|
|
/* Skip exporting curves without faces, overhead can be
|
|
|
|
* significant if there are many for path animation. */
|
2020-03-17 16:52:14 +01:00
|
|
|
BL::Curve b_curve(b_ob_data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-29 03:56:14 +02:00
|
|
|
return (b_curve.bevel_object() || b_curve.extrude() != 0.0f || b_curve.bevel_depth() != 0.0f ||
|
2017-10-03 15:28:57 +05:00
|
|
|
b_curve.dimensions() == BL::Curve::dimensions_2D || b_ob.modifiers.length());
|
2017-09-29 03:56:14 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (b_ob_data.is_a(&RNA_Mesh) || b_ob_data.is_a(&RNA_Curve) ||
|
|
|
|
b_ob_data.is_a(&RNA_MetaBall));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
bool BlenderSync::object_is_light(BL::Object &b_ob)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
BL::ID b_ob_data = b_ob.data();
|
|
|
|
|
2018-06-27 14:41:53 +02:00
|
|
|
return (b_ob_data && b_ob_data.is_a(&RNA_Light));
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Object */
|
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph,
|
2018-07-25 12:26:09 +02:00
|
|
|
BL::ViewLayer &b_view_layer,
|
2018-05-30 15:21:21 +02:00
|
|
|
BL::DepsgraphObjectInstance &b_instance,
|
2015-04-10 18:09:58 +05:00
|
|
|
float motion_time,
|
2020-02-02 13:09:18 +01:00
|
|
|
bool use_particle_hair,
|
2019-08-27 15:47:30 +02:00
|
|
|
bool show_lights,
|
2016-11-13 00:45:16 +01:00
|
|
|
BlenderObjectCulling &culling,
|
2020-10-21 16:38:36 +02:00
|
|
|
bool *use_portal,
|
|
|
|
TaskPool *geom_task_pool)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-05-30 15:21:21 +02:00
|
|
|
const bool is_instance = b_instance.is_instance();
|
|
|
|
BL::Object b_ob = b_instance.object();
|
|
|
|
BL::Object b_parent = is_instance ? b_instance.parent() : b_instance.object();
|
|
|
|
BL::Object b_ob_instance = is_instance ? b_instance.instance_object() : b_ob;
|
2017-06-06 13:58:40 +02:00
|
|
|
const bool motion = motion_time != 0.0f;
|
|
|
|
/*const*/ Transform tfm = get_transform(b_ob.matrix_world());
|
|
|
|
int *persistent_id = NULL;
|
|
|
|
BL::Array<int, OBJECT_PERSISTENT_ID_SIZE> persistent_id_array;
|
2017-06-06 16:27:02 +02:00
|
|
|
if (is_instance) {
|
2018-05-30 15:21:21 +02:00
|
|
|
persistent_id_array = b_instance.persistent_id();
|
2017-06-06 13:58:40 +02:00
|
|
|
persistent_id = persistent_id_array.data;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* light is handled separately */
|
2018-07-25 12:35:27 +02:00
|
|
|
if (!motion && object_is_light(b_ob)) {
|
2019-08-27 15:47:30 +02:00
|
|
|
if (!show_lights) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-25 12:35:27 +02:00
|
|
|
/* TODO: don't use lights for excluded layers used as mask layer,
|
|
|
|
* when dynamic overrides are back. */
|
|
|
|
#if 0
|
2019-04-17 08:16:53 +02:00
|
|
|
if (!((layer_flag & view_layer.holdout_layer) && (layer_flag & view_layer.exclude_layer)))
|
2018-07-25 12:35:27 +02:00
|
|
|
#endif
|
2017-06-06 16:27:02 +02:00
|
|
|
{
|
|
|
|
sync_light(b_parent,
|
|
|
|
persistent_id,
|
|
|
|
b_ob,
|
|
|
|
b_ob_instance,
|
2018-05-30 15:21:21 +02:00
|
|
|
is_instance ? b_instance.random_id() : 0,
|
2017-06-06 16:27:02 +02:00
|
|
|
tfm,
|
|
|
|
use_portal);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
return NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* only interested in object that we can create meshes from */
|
2020-07-09 18:54:42 +02:00
|
|
|
if (!object_is_geometry(b_ob)) {
|
2012-11-08 16:35:28 +00:00
|
|
|
return NULL;
|
2016-11-13 00:45:16 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-11-13 00:16:50 +01:00
|
|
|
/* Perform object culling. */
|
2016-11-13 00:45:16 +01:00
|
|
|
if (culling.test(scene, b_ob, tfm)) {
|
2015-04-10 18:09:58 +05:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-29 03:56:14 +02:00
|
|
|
/* Visibility flags for both parent and child. */
|
2017-11-18 06:06:27 +01:00
|
|
|
PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles");
|
2018-07-25 12:26:09 +02:00
|
|
|
bool use_holdout = get_boolean(cobject, "is_holdout") ||
|
2019-03-12 18:44:56 +01:00
|
|
|
b_parent.holdout_get(PointerRNA_NULL, b_view_layer);
|
2017-09-29 03:56:14 +02:00
|
|
|
uint visibility = object_ray_visibility(b_ob) & PATH_RAY_ALL_VISIBILITY;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-29 03:56:14 +02:00
|
|
|
if (b_parent.ptr.data != b_ob.ptr.data) {
|
|
|
|
visibility &= object_ray_visibility(b_parent);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-25 12:35:27 +02:00
|
|
|
/* TODO: make holdout objects on excluded layer invisible for non-camera rays. */
|
|
|
|
#if 0
|
2019-04-17 08:16:53 +02:00
|
|
|
if (use_holdout && (layer_flag & view_layer.exclude_layer)) {
|
2017-09-29 03:56:14 +02:00
|
|
|
visibility &= ~(PATH_RAY_ALL_VISIBILITY - PATH_RAY_CAMERA);
|
|
|
|
}
|
2018-07-25 12:35:27 +02:00
|
|
|
#endif
|
2017-09-29 03:56:14 +02:00
|
|
|
|
2018-07-25 12:26:09 +02:00
|
|
|
/* Clear camera visibility for indirect only objects. */
|
2019-07-04 17:28:39 +02:00
|
|
|
bool use_indirect_only = !use_holdout &&
|
|
|
|
b_parent.indirect_only_get(PointerRNA_NULL, b_view_layer);
|
2018-07-25 12:26:09 +02:00
|
|
|
if (use_indirect_only) {
|
2017-09-29 03:56:14 +02:00
|
|
|
visibility &= ~PATH_RAY_CAMERA;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-09-29 03:56:14 +02:00
|
|
|
/* Don't export completely invisible objects. */
|
|
|
|
if (visibility == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-21 16:38:36 +02:00
|
|
|
/* Use task pool only for non-instances, since sync_dupli_particle accesses
|
|
|
|
* geometry. This restriction should be removed for better performance. */
|
|
|
|
TaskPool *object_geom_task_pool = (is_instance) ? NULL : geom_task_pool;
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
/* key to lookup object */
|
2020-02-02 13:09:18 +01:00
|
|
|
ObjectKey key(b_parent, persistent_id, b_ob_instance, use_particle_hair);
|
2011-04-27 11:58:34 +00:00
|
|
|
Object *object;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
/* motion vector case */
|
|
|
|
if (motion) {
|
|
|
|
object = object_map.find(key);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
if (object && object->use_motion()) {
|
|
|
|
/* Set transform at matching motion time step. */
|
|
|
|
int time_index = object->motion_step(motion_time);
|
|
|
|
if (time_index >= 0) {
|
2020-11-04 11:17:38 +01:00
|
|
|
array<Transform> motion = object->get_motion();
|
|
|
|
motion[time_index] = tfm;
|
|
|
|
object->set_motion(motion);
|
2016-08-07 22:41:35 +03:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* mesh deformation */
|
2020-11-04 11:17:38 +01:00
|
|
|
if (object->get_geometry())
|
2020-10-21 16:38:36 +02:00
|
|
|
sync_geometry_motion(b_depsgraph,
|
|
|
|
b_ob_instance,
|
|
|
|
object,
|
|
|
|
motion_time,
|
|
|
|
use_particle_hair,
|
|
|
|
object_geom_task_pool);
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
return object;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
/* test if we need to sync */
|
2011-04-27 11:58:34 +00:00
|
|
|
bool object_updated = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-29 14:40:29 +01:00
|
|
|
if (object_map.add_or_update(&object, b_ob, b_parent, key))
|
2011-11-12 14:29:52 +00:00
|
|
|
object_updated = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-12 14:29:52 +00:00
|
|
|
/* mesh sync */
|
2020-10-21 16:38:36 +02:00
|
|
|
/* b_ob is owned by the iterator and will go out of scope at the end of the block.
|
|
|
|
* b_ob_instance is the original object and will remain valid for deferred geometry
|
|
|
|
* sync. */
|
2020-11-04 11:17:38 +01:00
|
|
|
Geometry *geometry = sync_geometry(b_depsgraph,
|
|
|
|
b_ob_instance,
|
|
|
|
b_ob_instance,
|
|
|
|
object_updated,
|
|
|
|
use_particle_hair,
|
|
|
|
object_geom_task_pool);
|
|
|
|
object->set_geometry(geometry);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-26 20:34:29 +01:00
|
|
|
/* special case not tracked by object update flags */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
if (sync_object_attributes(b_instance, object)) {
|
|
|
|
object_updated = true;
|
|
|
|
}
|
|
|
|
|
2013-11-26 20:34:29 +01:00
|
|
|
/* holdout */
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_use_holdout(use_holdout);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_visibility(visibility);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-09 14:19:01 +01:00
|
|
|
bool is_shadow_catcher = get_boolean(cobject, "is_shadow_catcher");
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_is_shadow_catcher(is_shadow_catcher);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-05 13:55:24 +02:00
|
|
|
float shadow_terminator_offset = get_float(cobject, "shadow_terminator_offset");
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_shadow_terminator_offset(shadow_terminator_offset);
|
2020-05-05 13:55:24 +02:00
|
|
|
|
2018-10-28 05:37:41 -04:00
|
|
|
/* sync the asset name for Cryptomatte */
|
|
|
|
BL::Object parent = b_ob.parent();
|
|
|
|
ustring parent_name;
|
|
|
|
if (parent) {
|
|
|
|
while (parent.parent()) {
|
|
|
|
parent = parent.parent();
|
|
|
|
}
|
|
|
|
parent_name = parent.name();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parent_name = b_ob.name();
|
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_asset_name(parent_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
/* object sync
|
|
|
|
* transform comparison should not be needed, but duplis don't work perfect
|
2012-09-03 13:18:23 +00:00
|
|
|
* in the depsgraph and may not signal changes, so this is a workaround */
|
2020-11-04 11:17:38 +01:00
|
|
|
if (object->is_modified() || object_updated ||
|
|
|
|
(object->get_geometry() && object->get_geometry()->is_modified()) ||
|
|
|
|
tfm != object->get_tfm()) {
|
2011-10-03 17:42:24 +00:00
|
|
|
object->name = b_ob.name().c_str();
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_pass_id(b_ob.pass_index());
|
|
|
|
object->set_color(get_float3(b_ob.color()));
|
|
|
|
object->set_tfm(tfm);
|
|
|
|
array<Transform> motion;
|
|
|
|
object->set_motion(motion);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* motion blur */
|
2018-03-08 04:04:52 +01:00
|
|
|
Scene::MotionType need_motion = scene->need_motion();
|
2020-11-04 11:17:38 +01:00
|
|
|
if (need_motion != Scene::MOTION_NONE && object->get_geometry()) {
|
|
|
|
Geometry *geom = object->get_geometry();
|
|
|
|
geom->set_use_motion_blur(false);
|
|
|
|
geom->set_motion_steps(0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-08 04:04:52 +01:00
|
|
|
uint motion_steps;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-21 13:31:52 +01:00
|
|
|
if (need_motion == Scene::MOTION_BLUR) {
|
2020-02-18 14:02:40 +01:00
|
|
|
motion_steps = object_motion_steps(b_parent, b_ob, Object::MAX_MOTION_STEPS);
|
2020-11-04 11:17:38 +01:00
|
|
|
geom->set_motion_steps(motion_steps);
|
2018-03-12 17:33:46 +01:00
|
|
|
if (motion_steps && object_use_deform_motion(b_parent, b_ob)) {
|
2020-11-04 11:17:38 +01:00
|
|
|
geom->set_use_motion_blur(true);
|
2014-03-29 13:03:47 +01:00
|
|
|
}
|
2018-03-08 04:04:52 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
motion_steps = 3;
|
2020-11-04 11:17:38 +01:00
|
|
|
geom->set_motion_steps(motion_steps);
|
2018-03-08 04:04:52 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
motion.resize(motion_steps, transform_empty());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-12 17:33:46 +01:00
|
|
|
if (motion_steps) {
|
2020-11-04 11:17:38 +01:00
|
|
|
motion[motion_steps / 2] = tfm;
|
|
|
|
|
|
|
|
/* update motion socket before trying to access object->motion_time */
|
|
|
|
object->set_motion(motion);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-12 17:33:46 +01:00
|
|
|
for (size_t step = 0; step < motion_steps; step++) {
|
|
|
|
motion_times.insert(object->motion_time(step));
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-03-12 17:33:46 +01:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-14 18:13:44 +03:00
|
|
|
/* dupli texture coordinates and random_id */
|
2017-06-06 16:27:02 +02:00
|
|
|
if (is_instance) {
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_dupli_generated(0.5f * get_float3(b_instance.orco()) -
|
|
|
|
make_float3(0.5f, 0.5f, 0.5f));
|
|
|
|
object->set_dupli_uv(get_float2(b_instance.uv()));
|
|
|
|
object->set_random_id(b_instance.random_id());
|
2012-10-04 21:40:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-02-17 01:47:18 +01:00
|
|
|
object->set_dupli_generated(zero_float3());
|
|
|
|
object->set_dupli_uv(zero_float2());
|
2020-11-04 11:17:38 +01:00
|
|
|
object->set_random_id(hash_uint2(hash_string(object->name.c_str()), 0));
|
2012-10-04 21:40:39 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
object->tag_update(scene);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-02 16:32:32 +01:00
|
|
|
if (is_instance) {
|
|
|
|
/* Sync possible particle data. */
|
|
|
|
sync_dupli_particle(b_parent, b_instance, object);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-08 16:35:28 +00:00
|
|
|
return object;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
/* This function mirrors drw_uniform_property_lookup in draw_instance_data.cpp */
|
|
|
|
static bool lookup_property(BL::ID b_id, const string &name, float4 *r_value)
|
|
|
|
{
|
|
|
|
PointerRNA ptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
if (!RNA_path_resolve(&b_id.ptr, name.c_str(), &ptr, &prop)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-23 15:45:55 +01:00
|
|
|
if (prop == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
PropertyType type = RNA_property_type(prop);
|
|
|
|
int arraylen = RNA_property_array_length(&ptr, prop);
|
|
|
|
|
|
|
|
if (arraylen == 0) {
|
|
|
|
float value;
|
|
|
|
|
|
|
|
if (type == PROP_FLOAT)
|
|
|
|
value = RNA_property_float_get(&ptr, prop);
|
|
|
|
else if (type == PROP_INT)
|
|
|
|
value = RNA_property_int_get(&ptr, prop);
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*r_value = make_float4(value, value, value, 1.0f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (type == PROP_FLOAT && arraylen <= 4) {
|
|
|
|
*r_value = make_float4(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
RNA_property_float_get_array(&ptr, prop, &r_value->x);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function mirrors drw_uniform_attribute_lookup in draw_instance_data.cpp */
|
|
|
|
static float4 lookup_instance_property(BL::DepsgraphObjectInstance &b_instance,
|
|
|
|
const string &name,
|
|
|
|
bool use_instancer)
|
|
|
|
{
|
|
|
|
string idprop_name = string_printf("[\"%s\"]", name.c_str());
|
|
|
|
float4 value;
|
|
|
|
|
|
|
|
/* If requesting instance data, check the parent particle system and object. */
|
|
|
|
if (use_instancer && b_instance.is_instance()) {
|
|
|
|
BL::ParticleSystem b_psys = b_instance.particle_system();
|
|
|
|
|
|
|
|
if (b_psys) {
|
|
|
|
if (lookup_property(b_psys.settings(), idprop_name, &value) ||
|
|
|
|
lookup_property(b_psys.settings(), name, &value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lookup_property(b_instance.parent(), idprop_name, &value) ||
|
|
|
|
lookup_property(b_instance.parent(), name, &value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the object and mesh. */
|
|
|
|
BL::Object b_ob = b_instance.object();
|
|
|
|
BL::ID b_data = b_ob.data();
|
|
|
|
|
|
|
|
if (lookup_property(b_ob, idprop_name, &value) || lookup_property(b_ob, name, &value) ||
|
|
|
|
lookup_property(b_data, idprop_name, &value) || lookup_property(b_data, name, &value)) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return make_float4(0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BlenderSync::sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object)
|
|
|
|
{
|
|
|
|
/* Find which attributes are needed. */
|
2020-11-04 11:17:38 +01:00
|
|
|
AttributeRequestSet requests = object->get_geometry()->needed_attributes();
|
Materials: add custom object properties as uniform attributes.
This patch allows the user to type a property name into the
Attribute node, which will then output the value of the property
for each individual object, allowing to e.g. customize shaders
by object without duplicating the shader.
In order to make supporting this easier for Eevee, it is necessary
to explicitly choose whether the attribute is varying or uniform
via a dropdown option of the Attribute node. The dropdown also
allows choosing whether instancing should be taken into account.
The Cycles design treats all attributes as one common namespace,
so the Blender interface converts the enum to a name prefix that
can't be entered using keyboard.
In Eevee, the attributes are provided to the shader via a UBO indexed
with resource_id, similar to the existing Object Info data. Unlike it,
however, it is necessary to maintain a separate buffer for every
requested combination of attributes.
This is done using a hash table with the attribute set as the key,
as it is expected that technically different but similar materials
may use the same set of attributes. In addition, in order to minimize
wasted memory, a sparse UBO pool is implemented, so that chunks that
don't contain any data don't have to be allocated.
The back-end Cycles code is already refactored and committed by Brecht.
Differential Revision: https://developer.blender.org/D2057
2020-08-05 19:14:40 +03:00
|
|
|
|
|
|
|
/* Delete attributes that became unnecessary. */
|
|
|
|
vector<ParamValue> &attributes = object->attributes;
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
for (int i = attributes.size() - 1; i >= 0; i--) {
|
|
|
|
if (!requests.find(attributes[i].name())) {
|
|
|
|
attributes.erase(attributes.begin() + i);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update attribute values. */
|
|
|
|
foreach (AttributeRequest &req, requests.requests) {
|
|
|
|
ustring name = req.name;
|
|
|
|
|
|
|
|
std::string real_name;
|
|
|
|
BlenderAttributeType type = blender_attribute_name_split_type(name, &real_name);
|
|
|
|
|
|
|
|
if (type != BL::ShaderNodeAttribute::attribute_type_GEOMETRY) {
|
|
|
|
bool use_instancer = (type == BL::ShaderNodeAttribute::attribute_type_INSTANCER);
|
|
|
|
float4 value = lookup_instance_property(b_instance, real_name, use_instancer);
|
|
|
|
|
|
|
|
/* Try finding the existing attribute value. */
|
|
|
|
ParamValue *param = NULL;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < attributes.size(); i++) {
|
|
|
|
if (attributes[i].name() == name) {
|
|
|
|
param = &attributes[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replace or add the value. */
|
|
|
|
ParamValue new_param(name, TypeDesc::TypeFloat4, 1, &value);
|
|
|
|
assert(new_param.datasize() == sizeof(value));
|
|
|
|
|
|
|
|
if (!param) {
|
|
|
|
changed = true;
|
|
|
|
attributes.push_back(new_param);
|
|
|
|
}
|
|
|
|
else if (memcmp(param->data(), &value, sizeof(value)) != 0) {
|
|
|
|
changed = true;
|
|
|
|
*param = new_param;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Object Loop */
|
|
|
|
|
2019-08-27 15:47:30 +02:00
|
|
|
void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph,
|
|
|
|
BL::SpaceView3D &b_v3d,
|
|
|
|
float motion_time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-10-21 16:38:36 +02:00
|
|
|
/* Task pool for multithreaded geometry sync. */
|
|
|
|
TaskPool geom_task_pool;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* layer data */
|
2014-03-29 13:03:46 +01:00
|
|
|
bool motion = motion_time != 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
if (!motion) {
|
|
|
|
/* prepare for sync */
|
|
|
|
light_map.pre_sync();
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_map.pre_sync();
|
2012-04-30 12:49:26 +00:00
|
|
|
object_map.pre_sync();
|
2012-10-18 15:00:32 +00:00
|
|
|
particle_system_map.pre_sync();
|
2014-03-29 13:03:46 +01:00
|
|
|
motion_times.clear();
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2013-10-17 16:05:57 +00:00
|
|
|
else {
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_motion_synced.clear();
|
2013-10-17 16:05:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-11-13 00:45:16 +01:00
|
|
|
/* initialize culling */
|
|
|
|
BlenderObjectCulling culling(scene, b_scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* object loop */
|
2012-09-04 13:29:07 +00:00
|
|
|
bool cancel = false;
|
Cycles: Added support for light portals
This patch adds support for light portals: objects that help sampling the
environment light, therefore improving convergence. Using them tor other
lights in a unidirectional pathtracer is virtually useless.
The sampling is done with the area-preserving code already used for area lamps.
MIS is used both for combination of different portals and for combining portal-
and envmap-sampling.
The direction of portals is considered, they aren't used if the sampling point
is behind them.
Reviewers: sergey, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: Lapineige, nutel, jtheninja, dsisco11, januz, vitorbalbio, candreacchio, TARDISMaker, lichtwerk, ace_dragon, marcog, mib2berlin, Tunge, lopataasdf, lordodin, sergey, dingto
Differential Revision: https://developer.blender.org/D1133
2015-04-28 00:51:55 +05:00
|
|
|
bool use_portal = false;
|
2019-08-27 15:47:30 +02:00
|
|
|
const bool show_lights = BlenderViewportParameters(b_v3d).use_scene_lights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-25 12:26:09 +02:00
|
|
|
BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
|
2018-05-30 15:21:21 +02:00
|
|
|
BL::Depsgraph::object_instances_iterator b_instance_iter;
|
2020-10-21 16:38:36 +02:00
|
|
|
|
2018-05-30 15:21:21 +02:00
|
|
|
for (b_depsgraph.object_instances.begin(b_instance_iter);
|
|
|
|
b_instance_iter != b_depsgraph.object_instances.end() && !cancel;
|
|
|
|
++b_instance_iter) {
|
|
|
|
BL::DepsgraphObjectInstance b_instance = *b_instance_iter;
|
|
|
|
BL::Object b_ob = b_instance.object();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Viewport visibility. */
|
|
|
|
const bool show_in_viewport = !b_v3d || b_ob.visible_in_viewport_get(b_v3d);
|
|
|
|
if (show_in_viewport == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load per-object culling data. */
|
2017-04-25 16:18:24 +02:00
|
|
|
culling.init_object(scene, b_ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-23 17:13:21 +02:00
|
|
|
/* Ensure the object geom supporting the hair is processed before adding
|
|
|
|
* the hair processing task to the task pool, calling .to_mesh() on the
|
|
|
|
* same object in parallel does not work. */
|
|
|
|
const bool sync_hair = b_instance.show_particles() && object_has_particle_hair(b_ob);
|
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Object itself. */
|
|
|
|
if (b_instance.show_self()) {
|
|
|
|
sync_object(b_depsgraph,
|
|
|
|
b_view_layer,
|
|
|
|
b_instance,
|
|
|
|
motion_time,
|
|
|
|
false,
|
|
|
|
show_lights,
|
|
|
|
culling,
|
2020-10-21 16:38:36 +02:00
|
|
|
&use_portal,
|
2020-10-23 17:13:21 +02:00
|
|
|
sync_hair ? NULL : &geom_task_pool);
|
2020-02-02 13:09:18 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 13:09:18 +01:00
|
|
|
/* Particle hair as separate object. */
|
2020-10-23 17:13:21 +02:00
|
|
|
if (sync_hair) {
|
2018-02-26 16:46:48 +01:00
|
|
|
sync_object(b_depsgraph,
|
2018-07-25 12:26:09 +02:00
|
|
|
b_view_layer,
|
2018-05-30 15:21:21 +02:00
|
|
|
b_instance,
|
2017-04-25 16:18:24 +02:00
|
|
|
motion_time,
|
2020-02-02 13:09:18 +01:00
|
|
|
true,
|
2019-08-27 15:47:30 +02:00
|
|
|
show_lights,
|
2017-04-25 16:18:24 +02:00
|
|
|
culling,
|
2020-10-21 16:38:36 +02:00
|
|
|
&use_portal,
|
|
|
|
&geom_task_pool);
|
2017-04-25 16:18:24 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-04-25 16:18:24 +02:00
|
|
|
cancel = progress.get_cancel();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-21 16:38:36 +02:00
|
|
|
geom_task_pool.wait_work();
|
|
|
|
|
2012-09-28 12:37:20 +00:00
|
|
|
progress.set_sync_status("");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if (!cancel && !motion) {
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_background_light(b_v3d, use_portal);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-05-02 02:23:34 +02:00
|
|
|
/* Handle removed data and modified pointers, as this may free memory, delete Nodes in the
|
2021-05-04 00:42:34 +10:00
|
|
|
* right order to ensure that dependent data is freed after their users. Objects should be
|
2021-05-02 02:23:34 +02:00
|
|
|
* freed before particle systems and geometries. */
|
2020-10-29 14:40:29 +01:00
|
|
|
light_map.post_sync();
|
|
|
|
object_map.post_sync();
|
2021-05-02 02:23:34 +02:00
|
|
|
geometry_map.post_sync();
|
2020-10-29 14:40:29 +01:00
|
|
|
particle_system_map.post_sync();
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-10-17 16:05:57 +00:00
|
|
|
if (motion)
|
2020-02-02 12:04:19 +01:00
|
|
|
geometry_motion_synced.clear();
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
void BlenderSync::sync_motion(BL::RenderSettings &b_render,
|
2018-02-26 16:46:48 +01:00
|
|
|
BL::Depsgraph &b_depsgraph,
|
2019-08-27 15:47:30 +02:00
|
|
|
BL::SpaceView3D &b_v3d,
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object &b_override,
|
2015-07-21 15:36:35 +02:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
void **python_thread_state)
|
2012-04-30 12:49:26 +00:00
|
|
|
{
|
|
|
|
if (scene->need_motion() == Scene::MOTION_NONE)
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
/* get camera object here to deal with camera switch */
|
|
|
|
BL::Object b_cam = b_scene.camera();
|
|
|
|
if (b_override)
|
|
|
|
b_cam = b_override;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
int frame_center = b_scene.frame_current();
|
2016-09-14 14:58:55 +02:00
|
|
|
float subframe_center = b_scene.frame_subframe();
|
2015-06-29 17:40:13 +02:00
|
|
|
float frame_center_delta = 0.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-29 17:40:13 +02:00
|
|
|
if (scene->need_motion() != Scene::MOTION_PASS &&
|
2020-11-04 11:17:38 +01:00
|
|
|
scene->camera->get_motion_position() != Camera::MOTION_POSITION_CENTER) {
|
|
|
|
float shuttertime = scene->camera->get_shuttertime();
|
|
|
|
if (scene->camera->get_motion_position() == Camera::MOTION_POSITION_END) {
|
2015-06-29 17:40:13 +02:00
|
|
|
frame_center_delta = -shuttertime * 0.5f;
|
|
|
|
}
|
|
|
|
else {
|
2020-11-04 11:17:38 +01:00
|
|
|
assert(scene->camera->get_motion_position() == Camera::MOTION_POSITION_START);
|
2015-06-29 17:40:13 +02:00
|
|
|
frame_center_delta = shuttertime * 0.5f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-09-14 14:58:55 +02:00
|
|
|
float time = frame_center + subframe_center + frame_center_delta;
|
2015-06-29 17:40:13 +02:00
|
|
|
int frame = (int)floorf(time);
|
|
|
|
float subframe = time - frame;
|
|
|
|
python_thread_state_restore(python_thread_state);
|
|
|
|
b_engine.frame_set(frame, subframe);
|
|
|
|
python_thread_state_save(python_thread_state);
|
2020-08-17 14:20:37 +02:00
|
|
|
if (b_cam) {
|
|
|
|
sync_camera_motion(b_render, b_cam, width, height, 0.0f);
|
|
|
|
}
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_objects(b_depsgraph, b_v3d, 0.0f);
|
2015-06-29 17:40:13 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-19 02:51:27 +02:00
|
|
|
/* Insert motion times from camera. Motion times from other objects
|
|
|
|
* have already been added in a sync_objects call. */
|
2020-08-17 14:20:37 +02:00
|
|
|
if (b_cam) {
|
|
|
|
uint camera_motion_steps = object_motion_steps(b_cam, b_cam);
|
|
|
|
for (size_t step = 0; step < camera_motion_steps; step++) {
|
|
|
|
motion_times.insert(scene->camera->motion_time(step));
|
|
|
|
}
|
2020-05-19 02:51:27 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* note iteration over motion_times set happens in sorted order */
|
|
|
|
foreach (float relative_time, motion_times) {
|
2018-03-10 00:37:07 +01:00
|
|
|
/* center time is already handled. */
|
|
|
|
if (relative_time == 0.0f) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-07-21 15:36:35 +02:00
|
|
|
VLOG(1) << "Synchronizing motion for the relative time " << relative_time << ".";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* fixed shutter time to get previous and next frame for motion pass */
|
2016-07-16 18:56:59 +02:00
|
|
|
float shuttertime = scene->motion_shutter_time();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* compute frame and subframe time */
|
2016-09-14 14:58:55 +02:00
|
|
|
float time = frame_center + subframe_center + frame_center_delta +
|
|
|
|
relative_time * shuttertime * 0.5f;
|
2014-03-29 13:03:46 +01:00
|
|
|
int frame = (int)floorf(time);
|
|
|
|
float subframe = time - frame;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* change frame */
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_restore(python_thread_state);
|
2014-05-21 15:47:11 +02:00
|
|
|
b_engine.frame_set(frame, subframe);
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_save(python_thread_state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-19 02:51:27 +02:00
|
|
|
/* Syncs camera motion if relative_time is one of the camera's motion times. */
|
|
|
|
sync_camera_motion(b_render, b_cam, width, height, relative_time);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:46 +01:00
|
|
|
/* sync object */
|
2019-08-27 15:47:30 +02:00
|
|
|
sync_objects(b_depsgraph, b_v3d, relative_time);
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-12 21:49:34 +01:00
|
|
|
/* we need to set the python thread state again because this
|
|
|
|
* function assumes it is being executed from python and will
|
|
|
|
* try to save the thread state */
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_restore(python_thread_state);
|
2016-09-14 14:58:55 +02:00
|
|
|
b_engine.frame_set(frame_center, subframe_center);
|
2014-02-12 23:13:45 +01:00
|
|
|
python_thread_state_save(python_thread_state);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|