Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/geometry.cpp
| Show First 20 Lines • Show All 728 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < scene->geometry.size(); i++) { | ||||
| geom->index = i; | geom->index = i; | ||||
| scene->need_global_attributes(geom_attributes[i]); | scene->need_global_attributes(geom_attributes[i]); | ||||
| foreach (Node *node, geom->get_used_shaders()) { | foreach (Node *node, geom->get_used_shaders()) { | ||||
| Shader *shader = static_cast<Shader *>(node); | Shader *shader = static_cast<Shader *>(node); | ||||
| geom_attributes[i].add(shader->attributes); | geom_attributes[i].add(shader->attributes); | ||||
| } | } | ||||
| if (geom->is_hair() && static_cast<Hair *>(geom)->need_shadow_transparency()) { | |||||
| geom_attributes[i].add(ATTR_STD_SHADOW_TRANSPARENCY); | |||||
| } | |||||
| } | } | ||||
| /* convert object attributes to use the same data structures as geometry ones */ | /* convert object attributes to use the same data structures as geometry ones */ | ||||
| vector<AttributeRequestSet> object_attributes(scene->objects.size()); | vector<AttributeRequestSet> object_attributes(scene->objects.size()); | ||||
| vector<AttributeSet> object_attribute_values; | vector<AttributeSet> object_attribute_values; | ||||
| object_attribute_values.reserve(scene->objects.size()); | object_attribute_values.reserve(scene->objects.size()); | ||||
| ▲ Show 20 Lines • Show All 909 Lines • ▼ Show 20 Lines | void GeometryManager::device_update(Device *device, | ||||
| Progress &progress) | Progress &progress) | ||||
| { | { | ||||
| if (!need_update()) | if (!need_update()) | ||||
| return; | return; | ||||
| VLOG(1) << "Total " << scene->geometry.size() << " meshes."; | VLOG(1) << "Total " << scene->geometry.size() << " meshes."; | ||||
| bool true_displacement_used = false; | bool true_displacement_used = false; | ||||
| bool curve_shadow_transparency_used = false; | |||||
| size_t total_tess_needed = 0; | size_t total_tess_needed = 0; | ||||
| { | { | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry({"device_update (normals)", time}); | scene->update_stats->geometry.times.add_entry({"device_update (normals)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| foreach (Geometry *geom, scene->geometry) { | foreach (Geometry *geom, scene->geometry) { | ||||
| if (geom->is_modified() && | if (geom->is_modified()) { | ||||
| (geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME)) { | if ((geom->geometry_type == Geometry::MESH || geom->geometry_type == Geometry::VOLUME)) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| /* Update normals. */ | /* Update normals. */ | ||||
| mesh->add_face_normals(); | mesh->add_face_normals(); | ||||
| mesh->add_vertex_normals(); | mesh->add_vertex_normals(); | ||||
| if (mesh->need_attribute(scene, ATTR_STD_POSITION_UNDISPLACED)) { | if (mesh->need_attribute(scene, ATTR_STD_POSITION_UNDISPLACED)) { | ||||
| mesh->add_undisplaced(); | mesh->add_undisplaced(); | ||||
| } | } | ||||
| /* Test if we need tessellation. */ | /* Test if we need tessellation. */ | ||||
| if (mesh->need_tesselation()) { | if (mesh->need_tesselation()) { | ||||
| total_tess_needed++; | total_tess_needed++; | ||||
| } | } | ||||
| /* Test if we need displacement. */ | /* Test if we need displacement. */ | ||||
| if (mesh->has_true_displacement()) { | if (mesh->has_true_displacement()) { | ||||
| true_displacement_used = true; | true_displacement_used = true; | ||||
| } | } | ||||
| } | |||||
| else if (geom->geometry_type == Geometry::HAIR) { | |||||
| Hair *hair = static_cast<Hair *>(geom); | |||||
| if (hair->need_shadow_transparency()) { | |||||
| curve_shadow_transparency_used = true; | |||||
| } | |||||
| } | |||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (total_tess_needed) { | ||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| /* Update images needed for true displacement. */ | /* Update images needed for true displacement. */ | ||||
| bool old_need_object_flags_update = false; | bool old_need_object_flags_update = false; | ||||
| if (true_displacement_used) { | if (true_displacement_used || curve_shadow_transparency_used) { | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry( | scene->update_stats->geometry.times.add_entry( | ||||
| {"device_update (displacement: load images)", time}); | {"device_update (displacement: load images)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| device_update_displacement_images(device, scene, progress); | device_update_displacement_images(device, scene, progress); | ||||
| old_need_object_flags_update = scene->object_manager->need_flags_update; | old_need_object_flags_update = scene->object_manager->need_flags_update; | ||||
| scene->object_manager->device_update_flags(device, dscene, scene, progress, false); | scene->object_manager->device_update_flags(device, dscene, scene, progress, false); | ||||
| } | } | ||||
| /* Device update. */ | /* Device update. */ | ||||
| device_free(device, dscene, false); | device_free(device, dscene, false); | ||||
| const BVHLayout bvh_layout = BVHParams::best_bvh_layout(scene->params.bvh_layout, | const BVHLayout bvh_layout = BVHParams::best_bvh_layout(scene->params.bvh_layout, | ||||
| device->get_bvh_layout_mask()); | device->get_bvh_layout_mask()); | ||||
| mesh_calc_offset(scene, bvh_layout); | mesh_calc_offset(scene, bvh_layout); | ||||
| if (true_displacement_used) { | if (true_displacement_used || curve_shadow_transparency_used) { | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry( | scene->update_stats->geometry.times.add_entry( | ||||
| {"device_update (displacement: copy meshes to device)", time}); | {"device_update (displacement: copy meshes to device)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| device_update_mesh(device, dscene, scene, progress); | device_update_mesh(device, dscene, scene, progress); | ||||
| } | } | ||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| { | { | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry({"device_update (attributes)", time}); | scene->update_stats->geometry.times.add_entry({"device_update (attributes)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| device_update_attributes(device, dscene, scene, progress); | device_update_attributes(device, dscene, scene, progress); | ||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| /* Update displacement. */ | /* Update displacement and hair shadow transparency. */ | ||||
| bool displacement_done = false; | bool displacement_done = false; | ||||
| bool curve_shadow_transparency_done = false; | |||||
| size_t num_bvh = 0; | size_t num_bvh = 0; | ||||
| { | { | ||||
| /* Copy constant data needed by shader evaluation. */ | /* Copy constant data needed by shader evaluation. */ | ||||
| device->const_copy_to("__data", &dscene->data, sizeof(dscene->data)); | device->const_copy_to("__data", &dscene->data, sizeof(dscene->data)); | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry({"device_update (displacement)", time}); | scene->update_stats->geometry.times.add_entry({"device_update (displacement)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| foreach (Geometry *geom, scene->geometry) { | foreach (Geometry *geom, scene->geometry) { | ||||
| if (geom->is_modified()) { | if (geom->is_modified()) { | ||||
| if (geom->is_mesh()) { | if (geom->is_mesh()) { | ||||
| Mesh *mesh = static_cast<Mesh *>(geom); | Mesh *mesh = static_cast<Mesh *>(geom); | ||||
| if (displace(device, scene, mesh, progress)) { | if (displace(device, scene, mesh, progress)) { | ||||
| displacement_done = true; | displacement_done = true; | ||||
| } | } | ||||
| } | } | ||||
| else if (geom->geometry_type == Geometry::HAIR) { | |||||
| Hair *hair = static_cast<Hair *>(geom); | |||||
| if (hair->update_shadow_transparency(device, scene, progress)) { | |||||
| curve_shadow_transparency_done = true; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| if (geom->is_modified() || geom->need_update_bvh_for_offset) { | if (geom->is_modified() || geom->need_update_bvh_for_offset) { | ||||
| if (geom->need_build_bvh(bvh_layout)) { | if (geom->need_build_bvh(bvh_layout)) { | ||||
| num_bvh++; | num_bvh++; | ||||
| } | } | ||||
| } | } | ||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (progress.get_cancel()) { | if (progress.get_cancel()) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Device re-update after displacement. */ | /* Device re-update after displacement. */ | ||||
| if (displacement_done) { | if (displacement_done || curve_shadow_transparency_done) { | ||||
| scoped_callback_timer timer([scene](double time) { | scoped_callback_timer timer([scene](double time) { | ||||
| if (scene->update_stats) { | if (scene->update_stats) { | ||||
| scene->update_stats->geometry.times.add_entry( | scene->update_stats->geometry.times.add_entry( | ||||
| {"device_update (displacement: attributes)", time}); | {"device_update (displacement: attributes)", time}); | ||||
| } | } | ||||
| }); | }); | ||||
| device_free(device, dscene, false); | device_free(device, dscene, false); | ||||
| ▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines | |||||