diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-12 22:22:55 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-13 01:57:45 +0300 |
commit | b603792fec45b2f9563929c76e95ad3b7270797b (patch) | |
tree | 03daceb7479c413683b96c553c12eeb63ad228df | |
parent | 5cf032678ff969688b6eefb8db6b241ac8934860 (diff) |
Code refactor: adjust camera update for easier code sharing with kernel.
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/blender/blender_object_cull.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/render/camera.cpp | 81 | ||||
-rw-r--r-- | intern/cycles/render/camera.h | 5 |
4 files changed, 50 insertions, 40 deletions
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); |