Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKévin Dietrich <kevin.dietrich@mailoo.org>2020-08-03 04:28:04 +0300
committerKévin Dietrich <kevin.dietrich@mailoo.org>2020-08-03 04:44:40 +0300
commitb5dcf746369e51c08285292cd78f621999dd09e9 (patch)
tree1eec4e7e262b40711002002a13df94ed91015a92 /intern/cycles/blender/blender_mesh.cpp
parent396d0b5cd0bcd9dd3dfa8d9006ee9f6f91c7196d (diff)
Cycles: add support for rendering deformation motion blur from Alembic caches.
This patch adds the ability to render motion blur from Alembic caches. The motion blur data is derived from a velocity attribute whose name has to be defined by the user through the MeshSequenceCache modifier, with a default value of ".velocities", which is the standard name in Alembic for the velocity property, although other software may ignore it and write velocity with their own naming convention (e.g. "v" in Houdini). Furthermore, a property was added to define how the velocity vectors are interpreted with regard to time : frame or second. "Frame" means that the velocity is already scaled by the time step and we do not need to modify it for it to look proper. "Second" means that the unit the velocity was measured in is in seconds and so has to be scaled by some time step computed here as being the time between two frames (1 / FPS, which would be typical for a simulation). This appears to be common, and is the default behavior. Another property was added to control the scale of the velocity to further modify the look of the motion blur. Reviewed By: brecht, sybren Differential Revision: https://developer.blender.org/D2388
Diffstat (limited to 'intern/cycles/blender/blender_mesh.cpp')
-rw-r--r--intern/cycles/blender/blender_mesh.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 49407799fcd..9043cd81293 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -923,6 +923,73 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
+static BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob, BL::Scene b_scene)
+{
+ BL::Object::modifiers_iterator b_mod;
+
+ for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
+ if (!b_mod->is_a(&RNA_MeshSequenceCacheModifier)) {
+ continue;
+ }
+
+ BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(*b_mod);
+
+ if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
+ return mesh_cache;
+ }
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
+static void sync_mesh_cached_velocities(BL::Object &b_ob,
+ BL::Scene b_scene,
+ Scene *scene,
+ Mesh *mesh)
+{
+ if (scene->need_motion() == Scene::MOTION_NONE)
+ return;
+
+ BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob, b_scene);
+
+ if (!b_mesh_cache) {
+ return;
+ }
+
+ /* Find or add attribute */
+ float3 *P = &mesh->verts[0];
+ Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+
+ if (!attr_mP) {
+ attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+ }
+
+ if (!MeshSequenceCacheModifier_read_velocity_get(&b_mesh_cache.ptr)) {
+ return;
+ }
+
+ const size_t numverts = mesh->verts.size();
+
+ if (b_mesh_cache.vertex_velocities.length() != numverts) {
+ return;
+ }
+
+ /* Only export previous and next frame, we don't have any in between data. */
+ float motion_times[2] = {-1.0f, 1.0f};
+ for (int step = 0; step < 2; step++) {
+ const float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f;
+ float3 *mP = attr_mP->data_float3() + step * numverts;
+
+ BL::MeshSequenceCacheModifier::vertex_velocities_iterator vvi;
+ int i = 0;
+
+ for (b_mesh_cache.vertex_velocities.begin(vvi); vvi != b_mesh_cache.vertex_velocities.end();
+ ++vvi, ++i) {
+ mP[i] = P[i] + get_float3(vvi->velocity()) * relative_time;
+ }
+ }
+}
+
static void sync_mesh_fluid_motion(BL::Object &b_ob, Scene *scene, Mesh *mesh)
{
if (scene->need_motion() == Scene::MOTION_NONE)
@@ -1002,6 +1069,9 @@ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph,
}
}
+ /* cached velocities (e.g. from alembic archive) */
+ sync_mesh_cached_velocities(b_ob, b_depsgraph.scene(), scene, mesh);
+
/* mesh fluid motion mantaflow */
sync_mesh_fluid_motion(b_ob, scene, mesh);
@@ -1023,6 +1093,12 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph,
return;
}
+ /* Cached motion blur already exported. */
+ BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob, b_scene);
+ if (mesh_cache) {
+ return;
+ }
+
/* Skip if no vertices were exported. */
size_t numverts = mesh->verts.size();
if (numverts == 0) {