[Bf-blender-cvs] [d4c60d6] alembic_basic_io: Cycles: initial support for motion bluring of dynamic meshes.

Kévin Dietrich noreply at git.blender.org
Thu Jul 7 13:10:33 CEST 2016


Commit: d4c60d60880b46a71294401f9e5799b163e6474f
Author: Kévin Dietrich
Date:   Thu Jul 7 13:03:08 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rBd4c60d60880b46a71294401f9e5799b163e6474f

Cycles: initial support for motion bluring of dynamic meshes.

This adds support for motion bluring of dynamic meshes (such as meshes
from liquid simulation).

For now, this is a little buggy since it appears that half of the motion
blur data is missing, also motion vectors seems to need to be scaled,
but I'm not sure just yet how to do so, and with which metric.

===================================================================

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/blender/blender_util.h
M	source/blender/alembic/ABC_alembic.h
M	source/blender/alembic/intern/alembic_capi.cc
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/rna_modifier.c

===================================================================

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 4bd385c..1db6e91 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -850,9 +850,29 @@ Mesh *BlenderSync::sync_mesh(BL::Object& b_ob,
 	return mesh;
 }
 
+static inline BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob)
+{
+	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);
+}
+
 void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
                                    Object *object,
-                                   float motion_time)
+                                   float motion_time,
+                                   float shuttertime)
 {
 	/* ensure we only sync instanced meshes once */
 	Mesh *mesh = object->mesh;
@@ -910,7 +930,10 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
 	 * would need a more extensive check to see which objects are animated */
 	BL::Mesh b_mesh(PointerRNA_NULL);
 
-	if(ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
+	/* First try to determine if this is a fluid domain. */
+	BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob);
+
+	if(mesh_cache || ccl::BKE_object_is_deform_modified(b_ob, b_scene, preview)) {
 		/* get derived mesh */
 		b_mesh = object_to_mesh(b_data, b_ob, b_scene, true, !preview, false);
 	}
@@ -948,6 +971,13 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
 
 	/* TODO(sergey): Perform preliminary check for number of verticies. */
 	if(numverts) {
+		/* For fluid meshes since we have change in geometry, we use velocities,
+		 * not delta-positions, and all the work is done on the first frame when
+		 * time_index is == 0, so the work is done. */
+		if(mesh_cache && time_index != 0) {
+			return;
+		}
+
 		/* find attributes */
 		Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
 		Attribute *attr_mN = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
@@ -963,46 +993,77 @@ void BlenderSync::sync_mesh_motion(BL::Object& b_ob,
 			new_attribute = true;
 		}
 
-		/* load vertex data from mesh */
-		float3 *mP = attr_mP->data_float3() + time_index*numverts;
-		float3 *mN = (attr_mN)? attr_mN->data_float3() + time_index*numverts: NULL;
+		if (mesh_cache) {
+			/* load vertex data from mesh */
+			float3 *P = &mesh->verts[0];
+			float3 *N = (attr_mN) ? attr_N->data_float3() : NULL;
 
-		BL::Mesh::vertices_iterator v;
-		int i = 0;
+			int step = 0;
 
-		for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end() && i < numverts; ++v, ++i) {
-			mP[i] = get_float3(v->co());
-			if(mN)
-				mN[i] = get_float3(v->normal());
-		}
+			/* Generate motion data for all motion times in one go, so that
+			 * vertices and velocities coincide. */
+			foreach(float relative_time, this->motion_times) {
+				float3 *mP = attr_mP->data_float3() + step*numverts;
+				float3 *mN = (attr_mN) ? attr_mN->data_float3() + step*numverts : NULL;
 
-		/* in case of new attribute, we verify if there really was any motion */
-		if(new_attribute) {
-			if(b_mesh.vertices.length() != numverts ||
-			   memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0)
-			{
-				/* no motion, remove attributes again */
-				if(b_mesh.vertices.length() != numverts) {
-					VLOG(1) << "Topology differs, disabling motion blur.";
-				}
-				else {
-					VLOG(1) << "No actual deformation motion for object " << b_ob.name();
+//				printf("Setting velocity for relative time: %f\n", (double)relative_time);
+
+				MeshSequenceCacheModifier_velocity_cache_get(&mesh_cache.ptr, &mP[0].x);
+
+				for (int i = 0; i < numverts; ++i) {
+					float3 nPos = P[i] + mP[i]*relative_time*shuttertime*0.5f;
+					mP[i] = nPos;
+
+					if(mN) {
+						mN[i] = N[i];
+					}
 				}
-				mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
-				if(attr_mN)
-					mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL);
+
+				++step;
+			}
+		}
+		else {
+			/* load vertex data from mesh */
+			float3 *mP = attr_mP->data_float3() + time_index*numverts;
+			float3 *mN = (attr_mN)? attr_mN->data_float3() + time_index*numverts: NULL;
+
+			BL::Mesh::vertices_iterator v;
+			int i = 0;
+
+			for(b_mesh.vertices.begin(v); v != b_mesh.vertices.end() && i < numverts; ++v, ++i) {
+				mP[i] = get_float3(v->co());
+				if(mN)
+					mN[i] = get_float3(v->normal());
 			}
-			else if(time_index > 0) {
-				VLOG(1) << "Filling deformation motion for object " << b_ob.name();
-				/* motion, fill up previous steps that we might have skipped because
-				 * they had no motion, but we need them anyway now */
-				float3 *P = &mesh->verts[0];
-				float3 *N = (attr_N)? attr_N->data_float3(): NULL;
 
-				for(int step = 0; step < time_index; step++) {
-					memcpy(attr_mP->data_float3() + step*numverts, P, sizeof(float3)*numverts);
+			/* in case of new attribute, we verify if there really was any motion */
+			if(new_attribute) {
+				if(b_mesh.vertices.length() != numverts ||
+				   memcmp(mP, &mesh->verts[0], sizeof(float3)*numverts) == 0)
+				{
+					/* no motion, remove attributes again */
+					if(b_mesh.vertices.length() != numverts) {
+						VLOG(1) << "Topology differs, disabling motion blur.";
+					}
+					else {
+						VLOG(1) << "No actual deformation motion for object " << b_ob.name();
+					}
+					mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_POSITION);
 					if(attr_mN)
-						memcpy(attr_mN->data_float3() + step*numverts, N, sizeof(float3)*numverts);
+						mesh->attributes.remove(ATTR_STD_MOTION_VERTEX_NORMAL);
+				}
+				else if(time_index > 0) {
+					VLOG(1) << "Filling deformation motion for object " << b_ob.name();
+					/* motion, fill up previous steps that we might have skipped because
+					 * they had no motion, but we need them anyway now */
+					float3 *P = &mesh->verts[0];
+					float3 *N = (attr_N)? attr_N->data_float3(): NULL;
+
+					for(int step = 0; step < time_index; step++) {
+						memcpy(attr_mP->data_float3() + step*numverts, P, sizeof(float3)*numverts);
+						if(attr_mN)
+							memcpy(attr_mN->data_float3() + step*numverts, N, sizeof(float3)*numverts);
+					}
 				}
 			}
 		}
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 80768c0..7782620e 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -280,6 +280,7 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
                                  Transform& tfm,
                                  uint layer_flag,
                                  float motion_time,
+                                 float shutter_time,
                                  bool hide_tris,
                                  bool use_camera_cull,
                                  float camera_cull_margin,
@@ -332,7 +333,7 @@ Object *BlenderSync::sync_object(BL::Object& b_parent,
 
 			/* mesh deformation */
 			if(object->mesh)
-				sync_mesh_motion(b_ob, object, motion_time);
+				sync_mesh_motion(b_ob, object, motion_time, shutter_time);
 		}
 
 		return object;
@@ -518,7 +519,7 @@ static bool object_render_hide_duplis(BL::Object& b_ob)
 
 /* Object Loop */
 
-void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
+void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time, float shutter_time)
 {
 	/* layer data */
 	uint scene_layer = render_layer.scene_layer;
@@ -609,6 +610,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
 							                             tfm,
 							                             ob_layer,
 							                             motion_time,
+							                             shutter_time,
 							                             hide_tris,
 							                             use_camera_cull,
 							                             camera_cull_margin,
@@ -639,6 +641,7 @@ void BlenderSync::sync_objects(BL::SpaceView3D& b_v3d, float motion_time)
 					            tfm,
 					            ob_layer,
 					            motion_time,
+					            shutter_time,
 					            hide_tris,
 					            use_camera_cull,
 					            camera_cull_margin,
@@ -707,7 +710,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
 		b_engine.frame_set(frame, subframe);
 		python_thread_state_save(python_thread_state);
 		sync_camera_motion(b_render, b_cam, width, height, 0.0f);
-		sync_objects(b_v3d, 0.0f);
+		sync_objects(b_v3d, 0.0f, 0.0f);
 	}
 
 	/* always sample these times for camera motion */
@@ -746,7 +749,7 @@ void BlenderSync::sync_motion(BL::RenderSettings& b_render,
 		}
 
 		/* sync object */
-		sync_objects(b_v3d, relative_time);
+		sync_objects(b_v3d, relative_time, shuttertime);
 	}
 
 	/* we need to set the python thread state again because this
diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h
index d690adb..b6a3e2a 100644
--- a/intern/cycles/blender/blender_sync.h
+++ b/intern/cycles/blender/blender_sync.h
@@ -96,7 +96,7 @@ private:
 	/* sync */
 	void sync_lamps(bool update_all);
 	void sync_materials(bool update_all);
-	void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f);
+	void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f, float shutter_time = 0.0f);
 	void sync_motion(BL::RenderSettings& b_render,
 	                 BL::SpaceView3D& b_v3d,
 	                 BL::Object& b_override,
@@ -121,6 +121,7 @@ private:
 	                    Transform& tfm,
 	                    uint layer_flag,
 	                    float motion_time,
+	                    float shutter_time,
 	                    bool hide_tris,
 	                    bool use_camera_cull,
 	                    float camera_cull_margin,
@@ -131,7 +132,10 @@ private:
 	                Transform& tfm,
 	                bool *use_portal);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list