840 bool true_displacement_used =
false;
841 bool curve_need_update_shadow_transparency =
false;
842 size_t num_tessellation = 0;
847 scene->
update_stats->geometry.times.add_entry({
"device_update (normals)", time});
854 Mesh *mesh =
static_cast<Mesh *
>(geom);
861#ifdef WITH_OPENSUBDIV
874 true_displacement_used =
true;
891 Hair *hair =
static_cast<Hair *
>(geom);
895 curve_need_update_shadow_transparency =
true;
914 {(num_tessellation) ?
"device_update (tessellation and tangents)" :
915 "device_update (tangents)",
921 if (num_tessellation) {
922 dicing_camera->set_screen_size(dicing_camera->get_full_width(),
923 dicing_camera->get_full_height());
924 dicing_camera->update(scene);
930 if (progress.get_cancel()) {
938 Mesh *mesh =
static_cast<Mesh *
>(geom);
942 if (num_tessellation && mesh->need_tessellation()) {
944 const thread_scoped_lock status_lock(status_mutex);
945 string msg =
"Tessellating ";
946 if (mesh->name.empty()) {
947 msg += string_printf(
"%u/%u", (uint)(i + 1), (uint)num_tessellation);
950 msg += string_printf(
951 "%s %u/%u", mesh->name.c_str(), (uint)(i + 1), (uint)num_tessellation);
954 progress.set_status(
"Updating Mesh", msg);
959 subd_params.
dicing_rate = mesh->get_subd_dicing_rate();
960 subd_params.max_level = mesh->get_subd_max_level();
962 subd_params.objecttoworld = mesh->get_subd_objecttoworld();
963 subd_params.camera = dicing_camera;
966 mesh->tessellate(subd_params);
970 mesh->update_tangents(scene,
true);
971 if (!mesh->has_true_displacement()) {
972 mesh->update_tangents(scene, false);
976 if (progress.get_cancel()) {
981 if (true_displacement_used || curve_need_update_shadow_transparency) {
983 if (scene->update_stats) {
984 scene->update_stats->geometry.times.add_entry(
985 {
"device_update (displacement: load images)",
time});
988 device_update_displacement_images(device, scene, progress);
989 scene->object_manager->device_update_flags(device, dscene, scene, progress,
false);
993 device_free(device, dscene,
false);
996 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->data.kernel_features));
997 geom_calc_offset(scene, bvh_layout);
998 if (true_displacement_used || curve_need_update_shadow_transparency) {
1000 if (scene->update_stats) {
1001 scene->update_stats->geometry.times.add_entry(
1002 {
"device_update (displacement: copy meshes to device)",
time});
1005 device_update_mesh(device, dscene, scene, progress);
1008 if (progress.get_cancel()) {
1015 if (scene->update_stats) {
1016 scene->update_stats->object.times.add_entry(
1017 {
"device_update (apply static transforms)",
time});
1021 progress.set_status(
"Updating Objects",
"Applying Static Transformations");
1022 scene->object_manager->apply_static_transforms(dscene, scene, progress);
1025 if (progress.get_cancel()) {
1032 const bool need_attributes_before_bvh = true_displacement_used ||
1033 curve_need_update_shadow_transparency;
1035 if (need_attributes_before_bvh) {
1037 if (scene->update_stats) {
1038 scene->update_stats->geometry.times.add_entry({
"device_update (attributes)",
time});
1041 device_update_attributes(device, dscene, scene, progress);
1042 if (progress.get_cancel()) {
1048 bool displacement_done =
false;
1051 device->const_copy_to(
"data", &dscene->data,
sizeof(dscene->data));
1054 if (scene->update_stats) {
1055 scene->update_stats->geometry.times.add_entry({
"device_update (displacement)",
time});
1059 for (
Geometry *geom : scene->geometry) {
1062 Mesh *mesh =
static_cast<Mesh *
>(geom);
1063 if (displace(device, scene, mesh, progress)) {
1064 displacement_done =
true;
1065 need_flags_update =
true;
1070 if (progress.get_cancel()) {
1076 if (progress.get_cancel()) {
1081 bool curve_shadow_transparency_done =
false;
1084 if (scene->update_stats) {
1085 scene->update_stats->geometry.times.add_entry(
1086 {
"device_update (curve shadow transparency)",
time});
1090 for (
Geometry *geom : scene->geometry) {
1092 Hair *hair =
static_cast<Hair *
>(geom);
1094 curve_shadow_transparency_done =
true;
1098 if (progress.get_cancel()) {
1104 if (progress.get_cancel()) {
1112 if (displacement_done || curve_shadow_transparency_done) {
1113 device_free(device, dscene,
false);
1121 bool need_update_scene_bvh = (scene->bvh ==
nullptr ||
1122 (update_flags & (TRANSFORM_MODIFIED | VISIBILITY_MODIFIED)) != 0);
1125 if (scene->update_stats) {
1126 scene->update_stats->geometry.times.add_entry({
"device_update (build object BVHs)",
time});
1132 for (
Geometry *geom : scene->geometry) {
1134 need_update_scene_bvh =
true;
1142 bvh_task_pool_.push([geom, device, dscene, scene, &progress, i, &num_bvh] {
1143 geom->
compute_bvh(device, dscene, &scene->params, &progress, i, num_bvh);
1149 bvh_task_pool_.wait_work(&summary);
1153 for (
Shader *shader : scene->shaders) {
1167 if (scene->update_stats) {
1168 scene->update_stats->geometry.times.add_entry({
"device_update (compute bounds)",
time});
1171 for (
Object *
object : scene->objects) {
1172 object->compute_bounds(motion_blur);
1176 if (progress.get_cancel()) {
1180 if (need_update_scene_bvh) {
1182 if (scene->update_stats) {
1183 scene->update_stats->geometry.times.add_entry({
"device_update (build scene BVH)",
time});
1186 device_update_bvh(device, dscene, scene, progress);
1187 if (progress.get_cancel()) {
1195 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->data.kernel_features));
1203 if (scene->update_stats) {
1204 scene->update_stats->geometry.times.add_entry({
"device_update (attributes)",
time});
1207 device_update_attributes(device, dscene, scene, progress);
1208 if (progress.get_cancel()) {
1215 if (scene->update_stats) {
1216 scene->update_stats->geometry.times.add_entry(
1217 {
"device_update (copy meshes to device)",
time});
1220 device_update_mesh(device, dscene, scene, progress);
1221 if (progress.get_cancel()) {
1228 for (
Geometry *geom : scene->geometry) {
1233 Mesh *mesh =
static_cast<Mesh *
>(geom);
1238 update_flags = UPDATE_NONE;
1240 dscene->bvh_nodes.clear_modified();
1241 dscene->bvh_leaf_nodes.clear_modified();
1242 dscene->object_node.clear_modified();
1243 dscene->prim_type.clear_modified();
1244 dscene->prim_visibility.clear_modified();
1245 dscene->prim_index.clear_modified();
1246 dscene->prim_object.clear_modified();
1247 dscene->prim_time.clear_modified();
1248 dscene->tri_shader.clear_modified();
1249 dscene->tri_vindex.clear_modified();
1250 dscene->tri_verts.clear_modified();
1251 dscene->curves.clear_modified();
1252 dscene->curve_keys.clear_modified();
1253 dscene->curve_segments.clear_modified();
1254 dscene->points.clear_modified();
1255 dscene->points_shader.clear_modified();
1256 dscene->attributes_map.clear_modified();
1257 dscene->attributes_float.clear_modified();
1258 dscene->attributes_float2.clear_modified();
1259 dscene->attributes_float3.clear_modified();
1260 dscene->attributes_float4.clear_modified();
1261 dscene->attributes_uchar4.clear_modified();
1262 dscene->attributes_normal.clear_modified();
1263 dscene->attributes_quaternion.clear_modified();
1264 dscene->attributes_spherical_harmonics_rest.clear_modified();