Code refactor: adjust camera update for easier code sharing with kernel.
This commit is contained in:
@@ -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.dicing_rate = max(0.1f, RNA_float_get(&cobj, "dicing_rate") * dicing_rate);
|
||||||
sdparams.max_level = max_subdivisions;
|
sdparams.max_level = max_subdivisions;
|
||||||
|
|
||||||
scene->dicing_camera->update();
|
scene->dicing_camera->update(scene);
|
||||||
sdparams.camera = scene->dicing_camera;
|
sdparams.camera = scene->dicing_camera;
|
||||||
sdparams.objecttoworld = get_transform(b_ob.matrix_world());
|
sdparams.objecttoworld = get_transform(b_ob.matrix_world());
|
||||||
}
|
}
|
||||||
|
@@ -62,7 +62,7 @@ void BlenderObjectCulling::init_object(Scene *scene, BL::Object& b_ob)
|
|||||||
|
|
||||||
if(use_camera_cull_ || use_distance_cull_) {
|
if(use_camera_cull_ || use_distance_cull_) {
|
||||||
/* Need to have proper projection matrix. */
|
/* Need to have proper projection matrix. */
|
||||||
scene->camera->update();
|
scene->camera->update(scene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -168,6 +168,8 @@ Camera::Camera()
|
|||||||
need_device_update = true;
|
need_device_update = true;
|
||||||
need_flags_update = true;
|
need_flags_update = true;
|
||||||
previous_need_motion = -1;
|
previous_need_motion = -1;
|
||||||
|
|
||||||
|
memset(&kernel_camera, 0, sizeof(kernel_camera));
|
||||||
}
|
}
|
||||||
|
|
||||||
Camera::~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)
|
if(!need_update)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -299,28 +310,8 @@ void Camera::update()
|
|||||||
perspective_motion.post = screentocamera_post * rastertoscreen;
|
perspective_motion.post = screentocamera_post * rastertoscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_update = false;
|
/* Compute kernel camera data. */
|
||||||
need_device_update = true;
|
KernelCamera *kcam = &kernel_camera;
|
||||||
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;
|
|
||||||
|
|
||||||
/* store matrices */
|
/* store matrices */
|
||||||
kcam->screentoworld = screentoworld;
|
kcam->screentoworld = screentoworld;
|
||||||
@@ -379,20 +370,6 @@ void Camera::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|||||||
/* motion blur */
|
/* motion blur */
|
||||||
kcam->shuttertime = (need_motion == Scene::MOTION_BLUR) ? shuttertime: -1.0f;
|
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 */
|
/* type */
|
||||||
kcam->type = 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_type = rolling_shutter_type;
|
||||||
kcam->rolling_shutter_duration = rolling_shutter_duration;
|
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;
|
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*/,
|
void Camera::device_update_volume(Device * /*device*/,
|
||||||
DeviceScene *dscene,
|
DeviceScene *dscene,
|
||||||
Scene *scene)
|
Scene *scene)
|
||||||
|
@@ -174,13 +174,16 @@ public:
|
|||||||
bool need_flags_update;
|
bool need_flags_update;
|
||||||
int previous_need_motion;
|
int previous_need_motion;
|
||||||
|
|
||||||
|
/* Kernel camera data, copied here for dicing. */
|
||||||
|
KernelCamera kernel_camera;
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
Camera();
|
Camera();
|
||||||
~Camera();
|
~Camera();
|
||||||
|
|
||||||
void compute_auto_viewplane();
|
void compute_auto_viewplane();
|
||||||
|
|
||||||
void update();
|
void update(Scene *scene);
|
||||||
|
|
||||||
void device_update(Device *device, DeviceScene *dscene, Scene *scene);
|
void device_update(Device *device, DeviceScene *dscene, Scene *scene);
|
||||||
void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene);
|
void device_update_volume(Device *device, DeviceScene *dscene, Scene *scene);
|
||||||
|
Reference in New Issue
Block a user