[Bf-blender-cvs] [dc3563f] master: Cycles: Implement camera zoom motion blur

Sergey Sharybin noreply at git.blender.org
Tue Jul 21 18:08:15 CEST 2015


Commit: dc3563ff4801907ec8cd21a1589f0cb56d021a8f
Author: Sergey Sharybin
Date:   Tue Jul 21 15:36:35 2015 +0200
Branches: master
https://developer.blender.org/rBdc3563ff4801907ec8cd21a1589f0cb56d021a8f

Cycles: Implement camera zoom motion blur

Works totally similar to camera motion blur and majority of the changes are
related on just passing extra arguments to sync() functions.

Couple of things still to look into:

- Motion pass will not include motion caused by the zoom.
- Only perspective cameras are supported currently.
- Motion is being interpolated on projected coordinates, which might give
  different results from constructing projection matrix from interpolated
  field of view.

  This could be good enough for us, but we need to consider improving this
  at some point.

Reviewers: juicyfruit, dingto

Reviewed By: dingto

Differential Revision: https://developer.blender.org/D1383

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

M	intern/cycles/blender/blender_camera.cpp
M	intern/cycles/blender/blender_object.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/blender/blender_sync.h
M	intern/cycles/kernel/kernel_camera.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/camera.h
M	intern/cycles/util/util_transform.h

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

diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp
index 90b42ea..18e9aa8 100644
--- a/intern/cycles/blender/blender_camera.cpp
+++ b/intern/cycles/blender/blender_camera.cpp
@@ -244,8 +244,11 @@ static Transform blender_camera_matrix(const Transform& tfm,
 	return transform_clear_scale(result);
 }
 
-static void blender_camera_viewplane(BlenderCamera *bcam, int width, int height,
-	BoundBox2D *viewplane, float *aspectratio, float *sensor_size)
+static void blender_camera_viewplane(BlenderCamera *bcam,
+                                     int width, int height,
+                                     BoundBox2D *viewplane,
+                                     float *aspectratio,
+                                     float *sensor_size)
 {
 	/* dimensions */
 	float xratio = (float)width*bcam->pixelaspect.x;
@@ -258,24 +261,34 @@ static void blender_camera_viewplane(BlenderCamera *bcam, int width, int height,
 	/* sensor fitting */
 	if(bcam->sensor_fit == BlenderCamera::AUTO) {
 		horizontal_fit = (xratio > yratio);
-		*sensor_size = bcam->sensor_width;
+		if(sensor_size != NULL) {
+			*sensor_size = bcam->sensor_width;
+		}
 	}
 	else if(bcam->sensor_fit == BlenderCamera::HORIZONTAL) {
 		horizontal_fit = true;
-		*sensor_size = bcam->sensor_width;
+		if(sensor_size != NULL) {
+			*sensor_size = bcam->sensor_width;
+		}
 	}
 	else {
 		horizontal_fit = false;
-		*sensor_size = bcam->sensor_height;
+		if(sensor_size != NULL) {
+			*sensor_size = bcam->sensor_height;
+		}
 	}
 
 	if(horizontal_fit) {
-		*aspectratio = xratio/yratio;
+		if(aspectratio != NULL) {
+			*aspectratio = xratio/yratio;
+		}
 		xaspect = *aspectratio;
 		yaspect = 1.0f;
 	}
 	else {
-		*aspectratio = yratio/xratio;
+		if(aspectratio != NULL) {
+			*aspectratio = yratio/xratio;
+		}
 		xaspect = 1.0f;
 		yaspect = *aspectratio;
 	}
@@ -284,31 +297,37 @@ static void blender_camera_viewplane(BlenderCamera *bcam, int width, int height,
 	if(bcam->type == CAMERA_ORTHOGRAPHIC) {
 		xaspect = xaspect*bcam->ortho_scale/(*aspectratio*2.0f);
 		yaspect = yaspect*bcam->ortho_scale/(*aspectratio*2.0f);
-		*aspectratio = bcam->ortho_scale/2.0f;
+		if(aspectratio != NULL) {
+			*aspectratio = bcam->ortho_scale/2.0f;
+		}
 	}
 
 	if(bcam->type == CAMERA_PANORAMA) {
 		/* set viewplane */
-		*viewplane = bcam->pano_viewplane;
+		if(viewplane != NULL) {
+			*viewplane = bcam->pano_viewplane;
+		}
 	}
 	else {
 		/* set viewplane */
-		viewplane->left = -xaspect;
-		viewplane->right = xaspect;
-		viewplane->bottom = -yaspect;
-		viewplane->top = yaspect;
-
-		/* zoom for 3d camera view */
-		*viewplane = (*viewplane) * bcam->zoom;
-
-		/* modify viewplane with camera shift and 3d camera view offset */
-		float dx = 2.0f*(*aspectratio*bcam->shift.x + bcam->offset.x*xaspect*2.0f);
-		float dy = 2.0f*(*aspectratio*bcam->shift.y + bcam->offset.y*yaspect*2.0f);
-
-		viewplane->left += dx;
-		viewplane->right += dx;
-		viewplane->bottom += dy;
-		viewplane->top += dy;
+		if(viewplane != NULL) {
+			viewplane->left = -xaspect;
+			viewplane->right = xaspect;
+			viewplane->bottom = -yaspect;
+			viewplane->top = yaspect;
+
+			/* zoom for 3d camera view */
+			*viewplane = (*viewplane) * bcam->zoom;
+
+			/* modify viewplane with camera shift and 3d camera view offset */
+			float dx = 2.0f*(*aspectratio*bcam->shift.x + bcam->offset.x*xaspect*2.0f);
+			float dy = 2.0f*(*aspectratio*bcam->shift.y + bcam->offset.y*yaspect*2.0f);
+
+			viewplane->left += dx;
+			viewplane->right += dx;
+			viewplane->bottom += dy;
+			viewplane->top += dy;
+		}
 	}
 }
 
@@ -386,7 +405,10 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int
 	cam->motion.pre = cam->matrix;
 	cam->motion.post = cam->matrix;
 	cam->use_motion = false;
+	cam->use_perspective_motion = false;
 	cam->shuttertime = bcam->shuttertime;
+	cam->fov_pre = cam->fov;
+	cam->fov_post = cam->fov;
 
 	/* border */
 	cam->border = bcam->border;
@@ -435,7 +457,10 @@ void BlenderSync::sync_camera(BL::RenderSettings b_render, BL::Object b_override
 	blender_camera_sync(cam, &bcam, width, height);
 }
 
-void BlenderSync::sync_camera_motion(BL::Object b_ob, float motion_time)
+void BlenderSync::sync_camera_motion(BL::RenderSettings b_render,
+                                     BL::Object b_ob,
+                                     int width, int height,
+                                     float motion_time)
 {
 	Camera *cam = scene->camera;
 	BL::Array<float, 16> b_ob_matrix;
@@ -454,6 +479,31 @@ void BlenderSync::sync_camera_motion(BL::Object b_ob, float motion_time)
 			cam->use_motion = true;
 		}
 	}
+
+	if(cam->type == CAMERA_PERSPECTIVE) {
+		BlenderCamera bcam;
+		float aspectratio, sensor_size;
+		blender_camera_init(&bcam, b_render);
+		blender_camera_from_object(&bcam, b_engine, b_ob);
+		blender_camera_viewplane(&bcam,
+		                         width, height,
+		                         NULL,
+		                         &aspectratio,
+		                         &sensor_size);
+		/* TODO(sergey): De-duplicate calculation with camera sync. */
+		float fov = 2.0f * atanf((0.5f * sensor_size) / bcam.lens / aspectratio);
+		if(fov != cam->fov) {
+			VLOG(1) << "Camera " << b_ob.name() << " FOV change detected.";
+			if(motion_time == -1.0f) {
+				cam->fov_pre = fov;
+				cam->use_perspective_motion = true;
+			}
+			else if(motion_time == 1.0f) {
+				cam->fov_post = fov;
+				cam->use_perspective_motion = true;
+			}
+		}
+	}
 }
 
 /* Sync 3D View Camera */
diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp
index 35ba450..432c4aa 100644
--- a/intern/cycles/blender/blender_object.cpp
+++ b/intern/cycles/blender/blender_object.cpp
@@ -659,7 +659,11 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, float motion_time)
 		mesh_motion_synced.clear();
 }
 
-void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state)
+void BlenderSync::sync_motion(BL::RenderSettings b_render,
+                              BL::SpaceView3D b_v3d,
+                              BL::Object b_override,
+                              int width, int height,
+                              void **python_thread_state)
 {
 	if(scene->need_motion() == Scene::MOTION_NONE)
 		return;
@@ -679,6 +683,9 @@ void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void
 
 	/* note iteration over motion_times set happens in sorted order */
 	foreach(float relative_time, motion_times) {
+		VLOG(1) << "Synchronizing motion for the relative time "
+		        << relative_time << ".";
+
 		/* fixed shutter time to get previous and next frame for motion pass */
 		float shuttertime;
 
@@ -698,8 +705,12 @@ void BlenderSync::sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override, void
 		python_thread_state_save(python_thread_state);
 
 		/* sync camera, only supports two times at the moment */
-		if(relative_time == -1.0f || relative_time == 1.0f)
-			sync_camera_motion(b_cam, relative_time);
+		if(relative_time == -1.0f || relative_time == 1.0f) {
+			sync_camera_motion(b_render,
+			                   b_cam,
+			                   width, height,
+			                   relative_time);
+		}
 
 		/* sync object */
 		sync_objects(b_v3d, relative_time);
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index e1d5e13..8903801 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -122,7 +122,12 @@ void BlenderSession::create_session()
 		if(session_pause == false) {
 			/* full data sync */
 			sync->sync_view(b_v3d, b_rv3d, width, height);
-			sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state);
+			sync->sync_data(b_render,
+			                b_v3d,
+			                b_engine.camera_override(),
+			                width, height,
+			                &python_thread_state,
+			                b_rlay_name.c_str());
 		}
 	}
 	else {
@@ -477,7 +482,12 @@ void BlenderSession::render()
 
 			/* update scene */
 			sync->sync_camera(b_render, b_engine.camera_override(), width, height);
-			sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state, b_rlay_name.c_str());
+			sync->sync_data(b_render,
+			                b_v3d,
+			                b_engine.camera_override(),
+			                width, height,
+			                &python_thread_state,
+			                b_rlay_name.c_str());
 
 			/* update number of samples per layer */
 			int samples = sync->get_layer_samples();
@@ -570,7 +580,12 @@ void BlenderSession::bake(BL::Object b_object, const string& pass_type, const in
 
 	/* update scene */
 	sync->sync_camera(b_render, b_engine.camera_override(), width, height);
-	sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state);
+	sync->sync_data(b_render,
+	                b_v3d,
+	                b_engine.camera_override(),
+	                width, height,
+	                &python_thread_state,
+	                b_rlay_name.c_str());
 
 	/* get buffer parameters */
 	SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
@@ -712,7 +727,12 @@ void BlenderSession::synchronize()
 	}
 
 	/* data and camera synchronize */
-	sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state);
+	sync->sync_data(b_render,
+	                b_v3d,
+	                b_engine.camera_override(),
+	                width, height,
+	                &python_thread_state,
+	                b_rlay_name.c_str());
 
 	if(b_rv3d)
 		sync->sync_view(b_v3d, b_rv3d, width, height);
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index c5fb792..8888d21 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -145,7 +145,12 @@ bool BlenderSync::sync_recalc()
 	return recalc;
 }
 
-void BlenderSync::sync_data(BL::SpaceView3D b_v3d, BL::Object b_override, void **python_thread_state, const char *layer)
+void BlenderSync::sync_data(BL::RenderSettings b_render,
+                            BL::SpaceView3D b_v3d,
+                         

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list