[Bf-blender-cvs] [b603792fec4] master: Code refactor: adjust camera update for easier code sharing with kernel.

Brecht Van Lommel noreply at git.blender.org
Sat Jan 13 00:01:07 CET 2018


Commit: b603792fec45b2f9563929c76e95ad3b7270797b
Author: Brecht Van Lommel
Date:   Fri Jan 12 20:22:55 2018 +0100
Branches: master
https://developer.blender.org/rBb603792fec45b2f9563929c76e95ad3b7270797b

Code refactor: adjust camera update for easier code sharing with kernel.

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_object_cull.cpp
M	intern/cycles/render/camera.cpp
M	intern/cycles/render/camera.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 6b003cfa539..d2757851877 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -920,7 +920,7 @@ static void create_subd_mesh(Scene *scene,
 	sdparams.dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
 	sdparams.max_level = max_subdivisions;
 
-	scene->dicing_camera->update();
+	scene->dicing_camera->update(scene);
 	sdparams.camera = scene->dicing_camera;
 	sdparams.objecttoworld = get_transform(b_ob.matrix_world());
 }
diff --git a/intern/cycles/blender/blender_object_cull.cpp b/intern/cycles/blender/blender_object_cull.cpp
index 0333c027f70..1d747de647a 100644
--- a/intern/cycles/blender/blender_object_cull.cpp
+++ b/intern/cycles/blender/blender_object_cull.cpp
@@ -62,7 +62,7 @@ void BlenderObjectCulling::init_object(Scene *scene, BL::Object& b_ob)
 
 	if(use_camera_cull_ || use_distance_cull_) {
 		/* Need to have proper projection matrix. */
-		scene->camera->update();
+		scene->camera->update(scene);
 	}
 }
 
diff --git a/intern/cycles/render/camera.cpp b/intern/cycles/render/camera.cpp
index 67c100564c2..8b975886081 100644
--- a/intern/cycles/render/camera.cpp
+++ b/intern/cycles/render/camera.cpp
@@ -168,6 +168,8 @@ Camera::Camera()
 	need_device_update = true;
 	need_flags_update = true;
 	previous_need_motion = -1;
+
+	memset(&kernel_camera, 0, sizeof(kernel_camera));
 }
 
 Camera::~Camera()
@@ -199,8 +201,17 @@ void Camera::compute_auto_viewplane()
 	}
 }
 
-void Camera::update()
+void Camera::update(Scene *scene)
 {
+	Scene::MotionType need_motion = scene->need_motion();
+
+	if(previous_need_motion != need_motion) {
+		/* scene's motion model could have been changed since previous device
+		 * camera update this could happen for example in case when one render
+		 * layer has got motion pass and another not */
+		need_device_update = true;
+	}
+
 	if(!need_update)
 		return;
 
@@ -299,28 +310,8 @@ void Camera::update()
 		perspective_motion.post = screentocamera_post * rastertoscreen;
 	}
 
-	need_update = false;
-	need_device_update = true;
-	need_flags_update = true;
-}
-
-void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
-{
-	Scene::MotionType need_motion = scene->need_motion();
-
-	update();
-
-	if(previous_need_motion != need_motion) {
-		/* scene's motion model could have been changed since previous device
-		 * camera update this could happen for example in case when one render
-		 * layer has got motion pass and another not */
-		need_device_update = true;
-	}
-
-	if(!need_device_update)
-		return;
-	
-	KernelCamera *kcam = &dscene->data.cam;
+	/* Compute kernel camera data. */
+	KernelCamera *kcam = &kernel_camera;
 
 	/* store matrices */
 	kcam->screentoworld = screentoworld;
@@ -379,20 +370,6 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
 	/* motion blur */
 	kcam->shuttertime = (need_motion == Scene::MOTION_BLUR) ? shuttertime: -1.0f;
 
-	scene->lookup_tables->remove_table(&shutter_table_offset);
-	if(need_motion == Scene::MOTION_BLUR) {
-		vector<float> shutter_table;
-		util_cdf_inverted(SHUTTER_TABLE_SIZE,
-		                  0.0f,
-		                  1.0f,
-		                  function_bind(shutter_curve_eval, _1, shutter_curve),
-		                  false,
-		                  shutter_table);
-		shutter_table_offset = scene->lookup_tables->add_table(dscene,
-		                                                       shutter_table);
-		kcam->shutter_table_offset = (int)shutter_table_offset;
-	}
-
 	/* type */
 	kcam->type = type;
 
@@ -453,9 +430,39 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
 	kcam->rolling_shutter_type = rolling_shutter_type;
 	kcam->rolling_shutter_duration = rolling_shutter_duration;
 
+	/* Set further update flags */
+	need_update = false;
+	need_device_update = true;
+	need_flags_update = true;
 	previous_need_motion = need_motion;
 }
 
+void Camera::device_update(Device * /* device */,
+                           DeviceScene *dscene,
+                           Scene *scene)
+{
+	update(scene);
+
+	if(!need_device_update)
+		return;
+
+	scene->lookup_tables->remove_table(&shutter_table_offset);
+	if(kernel_camera.shuttertime != -1.0f) {
+		vector<float> shutter_table;
+		util_cdf_inverted(SHUTTER_TABLE_SIZE,
+		                  0.0f,
+		                  1.0f,
+		                  function_bind(shutter_curve_eval, _1, shutter_curve),
+		                  false,
+		                  shutter_table);
+		shutter_table_offset = scene->lookup_tables->add_table(dscene,
+		                                                       shutter_table);
+		kernel_camera.shutter_table_offset = (int)shutter_table_offset;
+	}
+
+	dscene->data.cam = kernel_camera;
+}
+
 void Camera::device_update_volume(Device * /*device*/,
                                   DeviceScene *dscene,
                                   Scene *scene)
diff --git a/intern/cycles/render/camera.h b/intern/cycles/render/camera.h
index 12d67044d4f..4ec0fe3bc6e 100644
--- a/intern/cycles/render/camera.h
+++ b/intern/cycles/render/camera.h
@@ -174,13 +174,16 @@ public:
 	bool need_flags_update;
 	int previous_need_motion;
 
+	/* Kernel camera data, copied here for dicing. */
+	KernelCamera kernel_camera;
+
 	/* functions */
 	Camera();
 	~Camera();
 	
 	void compute_auto_viewplane();
 
-	void update();
+	void update(Scene *scene);
 
 	void device_update(Device *device, DeviceScene *dscene, Scene *scene);
 	void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene);



More information about the Bf-blender-cvs mailing list