diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:47 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2014-03-29 16:03:47 +0400 |
commit | 6020d0099039ed18c6a6cd330b68361123c85c1a (patch) | |
tree | 511c682800b981019f2eb5dfaf341238ea4882f8 /intern/cycles/render/object.cpp | |
parent | 8f33538fabe9b2485478b7ce0167c15396bdb355 (diff) |
Cycles: add support for mesh deformation motion blur.
Diffstat (limited to 'intern/cycles/render/object.cpp')
-rw-r--r-- | intern/cycles/render/object.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index e99ca323929..df03fa4a04c 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -89,17 +89,36 @@ void Object::apply_transform() float3 c2 = transform_get_column(&tfm, 2); float scalar = pow(fabsf(dot(cross(c0, c1), c2)), 1.0f/3.0f); - /* apply to mesh vertices */ - for(size_t i = 0; i < mesh->verts.size(); i++) - mesh->verts[i] = transform_point(&tfm, mesh->verts[i]); + /* triangles */ + if(mesh->verts.size()) { + /* store matrix to transform later. when accessing these as attributes we + * do not want the transform to be applied for consistency between static + * and dynamic BVH, so we do it on packing. */ + mesh->transform_normal = transform_transpose(transform_inverse(tfm)); + + /* apply to mesh vertices */ + for(size_t i = 0; i < mesh->verts.size(); i++) + mesh->verts[i] = transform_point(&tfm, mesh->verts[i]); + + Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); + if (attr) { + size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1); + float3 *vert_steps = attr->data_float3(); + + for (size_t i = 0; i < steps_size; i++) + vert_steps[i] = transform_point(&tfm, vert_steps[i]); + } - Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - if (attr) { - size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1); - float3 *vert_steps = attr->data_float3(); + Attribute *attr_N = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL); - for (size_t i = 0; i < steps_size; i++) - vert_steps[i] = transform_point(&tfm, vert_steps[i]); + if(attr_N) { + Transform ntfm = mesh->transform_normal; + size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1); + float3 *normal_steps = attr_N->data_float3(); + + for (size_t i = 0; i < steps_size; i++) + normal_steps[i] = normalize(transform_direction(&ntfm, normal_steps[i])); + } } /* apply to curve keys */ @@ -121,11 +140,6 @@ void Object::apply_transform() vert_steps[i] = transform_point(&tfm, vert_steps[i]); } - /* store matrix to transform later. when accessing these as attributes we - * do not want the transform to be applied for consistency between static - * and dynamic BVH, so we do it on packing. */ - mesh->transform_normal = transform_transpose(transform_inverse(tfm)); - /* we keep normals pointing in same direction on negative scale, notify * mesh about this in it (re)calculates normals */ if(transform_negative_scale(tfm)) |