79 if (!preserve_shaders) {
91 return (motion_steps > 1) ? 2.0f * step / (motion_steps - 1) - 1.0f : 0.0f;
96 if (motion_steps > 1) {
99 for (
int step = 0; step < motion_steps; step++) {
101 if (step_time == time) {
106 if (step != motion_steps / 2) {
137 foreach (
Node *node, used_shaders) {
139 if (shader->has_displacement && shader->get_displacement_method() !=
DISPLACE_BUMP) {
159 foreach (
Node *node, used_shaders) {
200 og->object_name_map.clear();
201 og->object_names.clear();
203 for (
size_t i = 0; i < scene->objects.size(); i++) {
205 Object *
object = scene->objects[i];
206 og->object_name_map[
object->name] = i;
207 og->object_names.push_back(object->name);
218 foreach (
const Attribute &attr, attributes.attributes) {
225 switch (kernel_type) {
275 size_t vert_size = 0;
278 size_t curve_size = 0;
279 size_t curve_key_size = 0;
280 size_t curve_segment_size = 0;
282 size_t point_size = 0;
284 size_t patch_size = 0;
285 size_t face_size = 0;
286 size_t corner_size = 0;
288 foreach (
Geometry *geom, scene->geometry) {
289 bool prim_offset_changed =
false;
292 Mesh *mesh =
static_cast<Mesh *
>(geom);
294 prim_offset_changed = (mesh->prim_offset != tri_size);
296 mesh->vert_offset = vert_size;
297 mesh->prim_offset = tri_size;
299 mesh->patch_offset = patch_size;
300 mesh->face_offset = face_size;
301 mesh->corner_offset = corner_size;
303 vert_size += mesh->verts.size();
304 tri_size += mesh->num_triangles();
306 if (mesh->get_num_subd_faces()) {
307 Mesh::SubdFace last = mesh->get_subd_face(mesh->get_num_subd_faces() - 1);
311 if (mesh->patch_table) {
312 mesh->patch_table_offset = patch_size;
313 patch_size += mesh->patch_table->total_size();
317 face_size += mesh->get_num_subd_faces();
318 corner_size += mesh->subd_face_corners.size();
321 Hair *hair =
static_cast<Hair *
>(geom);
323 prim_offset_changed = (hair->curve_segment_offset != curve_segment_size);
325 hair->curve_segment_offset = curve_segment_size;
326 hair->prim_offset = curve_size;
328 curve_size += hair->num_curves();
329 curve_key_size += hair->get_curve_keys().size();
330 curve_segment_size += hair->num_segments();
335 prim_offset_changed = (pointcloud->
prim_offset != point_size);
341 if (prim_offset_changed) {
361 if (scene->update_stats) {
362 scene->update_stats->geometry.times.add_entry({
"device_update_preprocess", time});
366 progress.set_status(
"Updating Meshes Flags");
369 bool volume_images_updated =
false;
371 foreach (
Geometry *geom, scene->geometry) {
377 Mesh *mesh =
static_cast<Mesh *
>(geom);
381 foreach (
Node *node, geom->get_used_shaders()) {
383 if (shader->has_volume) {
387 if (shader->has_surface_bssrdf) {
391 if (shader->need_update_uvs) {
396 Mesh *mesh =
static_cast<Mesh *
>(geom);
397 if (mesh->need_tesselation()) {
403 if (shader->need_update_attribute) {
408 Mesh *mesh =
static_cast<Mesh *
>(geom);
409 if (mesh->need_tesselation()) {
415 if (shader->need_update_displacement) {
418 Mesh *mesh =
static_cast<Mesh *
>(geom);
419 mesh->tag_verts_modified();
420 mesh->tag_subd_dicing_rate_modified();
421 mesh->tag_subd_max_level_modified();
422 mesh->tag_subd_objecttoworld_modified();
441 if (!volume_images_updated) {
442 progress.set_status(
"Updating Meshes Volume Bounds");
443 device_update_volume_images(device, scene, progress);
444 volume_images_updated =
true;
448 create_volume_mesh(scene, volume, progress);
456 Hair *hair =
static_cast<Hair *
>(geom);
459 if (hair->need_update_rebuild) {
462 else if (hair->is_modified()) {
468 Mesh *mesh =
static_cast<Mesh *
>(geom);
470 if (mesh->need_update_rebuild) {
473 else if (mesh->is_modified()) {
490 if (update_flags & (MESH_ADDED | MESH_REMOVED)) {
494 if (update_flags & (HAIR_ADDED | HAIR_REMOVED)) {
498 if (update_flags & (POINT_ADDED | POINT_REMOVED)) {
509 scene->bvh =
nullptr;
542 if ((update_flags & VISIBILITY_MODIFIED) != 0) {
605 need_flags_update =
false;
612 progress.
set_status(
"Updating Displacement Images");
615 set<int> bump_images;
617 bool has_osl_node =
false;
619 foreach (
Geometry *geom, scene->geometry) {
624 bool need_shadow_transparency =
false;
626 Hair *hair =
static_cast<Hair *
>(geom);
630 foreach (
Node *node, geom->get_used_shaders()) {
632 const bool is_true_displacement = (shader->has_displacement &&
634 if (!is_true_displacement && !need_shadow_transparency) {
637 foreach (
ShaderNode *node, shader->graph->nodes) {
651 bump_images.insert(slot);
663 OSLShaderManager::osl_image_slots(device, image_manager, bump_images);
667 foreach (
int slot, bump_images) {
676 progress.
set_status(
"Updating Volume Images");
679 set<int> volume_images;
681 foreach (
Geometry *geom, scene->geometry) {
694 if (!handle.vdb_loader()) {
697 volume_images.insert(slot);
703 foreach (
int slot, volume_images) {
719 VLOG_INFO <<
"Total " << scene->geometry.size() <<
" meshes.";
721 bool true_displacement_used =
false;
722 bool curve_shadow_transparency_used =
false;
723 size_t total_tess_needed = 0;
727 if (scene->update_stats) {
728 scene->update_stats->geometry.times.add_entry({
"device_update (normals)", time});
732 foreach (
Geometry *geom, scene->geometry) {
735 Mesh *mesh =
static_cast<Mesh *
>(geom);
739 mesh->add_vertex_normals();
742 mesh->add_undisplaced();
746 if (mesh->need_tesselation()) {
751 if (mesh->has_true_displacement()) {
752 true_displacement_used =
true;
756 Hair *hair =
static_cast<Hair *
>(geom);
757 if (hair->need_shadow_transparency()) {
758 curve_shadow_transparency_used =
true;
769 if (progress.get_cancel()) {
774 if (total_tess_needed) {
776 if (scene->update_stats) {
777 scene->update_stats->geometry.times.add_entry(
778 {
"device_update (adaptive subdivision)", time});
782 Camera *dicing_camera = scene->dicing_camera;
784 dicing_camera->get_full_height());
785 dicing_camera->
update(scene);
788 foreach (
Geometry *geom, scene->geometry) {
793 Mesh *mesh =
static_cast<Mesh *
>(geom);
794 if (mesh->need_tesselation()) {
795 string msg =
"Tessellating ";
796 if (mesh->name ==
"") {
801 "%s %u/%u", mesh->name.c_str(), (
uint)(i + 1), (
uint)total_tess_needed);
804 progress.set_status(
"Updating Mesh", msg);
806 mesh->subd_params->camera = dicing_camera;
808 mesh->tessellate(&dsplit);
812 if (progress.get_cancel()) {
818 if (progress.get_cancel()) {
824 if (true_displacement_used || curve_shadow_transparency_used) {
826 if (scene->update_stats) {
827 scene->update_stats->geometry.times.add_entry(
828 {
"device_update (displacement: load images)", time});
831 device_update_displacement_images(device, scene, progress);
832 scene->object_manager->device_update_flags(device, dscene, scene, progress,
false);
836 device_free(device, dscene,
false);
839 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->
data.kernel_features));
840 geom_calc_offset(scene, bvh_layout);
841 if (true_displacement_used || curve_shadow_transparency_used) {
843 if (scene->update_stats) {
844 scene->update_stats->geometry.times.add_entry(
845 {
"device_update (displacement: copy meshes to device)", time});
848 device_update_mesh(device, dscene, scene, progress);
850 if (progress.get_cancel()) {
856 if (scene->update_stats) {
857 scene->update_stats->geometry.times.add_entry({
"device_update (attributes)", time});
860 device_update_attributes(device, dscene, scene, progress);
861 if (progress.get_cancel()) {
867 bool displacement_done =
false;
868 bool curve_shadow_transparency_done =
false;
873 device->const_copy_to(
"data", &dscene->
data,
sizeof(dscene->
data));
876 if (scene->update_stats) {
877 scene->update_stats->geometry.times.add_entry({
"device_update (displacement)", time});
881 foreach (
Geometry *geom, scene->geometry) {
884 Mesh *mesh =
static_cast<Mesh *
>(geom);
885 if (displace(device, scene, mesh, progress)) {
886 displacement_done =
true;
890 Hair *hair =
static_cast<Hair *
>(geom);
891 if (hair->update_shadow_transparency(device, scene, progress)) {
892 curve_shadow_transparency_done =
true;
903 if (progress.get_cancel()) {
909 if (progress.get_cancel()) {
914 if (displacement_done || curve_shadow_transparency_done) {
916 if (scene->update_stats) {
917 scene->update_stats->geometry.times.add_entry(
918 {
"device_update (displacement: attributes)", time});
921 device_free(device, dscene,
false);
923 device_update_attributes(device, dscene, scene, progress);
924 if (progress.get_cancel()) {
934 bool need_update_scene_bvh = (scene->bvh ==
nullptr ||
935 (update_flags & (TRANSFORM_MODIFIED | VISIBILITY_MODIFIED)) != 0);
938 if (scene->update_stats) {
939 scene->update_stats->geometry.times.add_entry({
"device_update (build object BVHs)", time});
945 foreach (
Geometry *geom, scene->geometry) {
947 need_update_scene_bvh =
true;
961 foreach (
Shader *shader, scene->shaders) {
962 shader->need_update_uvs =
false;
963 shader->need_update_attribute =
false;
964 shader->need_update_displacement =
false;
973 if (scene->update_stats) {
974 scene->update_stats->geometry.times.add_entry({
"device_update (compute bounds)", time});
977 foreach (
Object *
object, scene->objects) {
978 object->compute_bounds(motion_blur);
982 if (progress.get_cancel()) {
986 if (need_update_scene_bvh) {
988 if (scene->update_stats) {
989 scene->update_stats->geometry.times.add_entry({
"device_update (build scene BVH)", time});
992 device_update_bvh(device, dscene, scene, progress);
993 if (progress.get_cancel()) {
1001 scene->params.bvh_layout, device->get_bvh_layout_mask(dscene->
data.kernel_features));
1005 if (scene->update_stats) {
1006 scene->update_stats->geometry.times.add_entry(
1007 {
"device_update (copy meshes to device)", time});
1010 device_update_mesh(device, dscene, scene, progress);
1011 if (progress.get_cancel()) {
1018 foreach (
Geometry *geom, scene->geometry) {
1023 Mesh *mesh =
static_cast<Mesh *
>(geom);
1028 update_flags = UPDATE_NONE;
1094 og->object_name_map.clear();
1095 og->object_names.clear();
1104 update_flags |=
flag;
1119 foreach (
Geometry *geometry, scene->geometry) {
1121 NamedSizeEntry(
string(geometry->name.c_str()), geometry->get_total_size_in_bytes()));
list< Attribute > attributes
static AttrKernelDataType kernel_type(const Attribute &attr)
ImageHandle & data_voxel()
static BVHLayout best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
device_vector< uint > points_shader
device_vector< float2 > prim_time
device_vector< uint > patches
device_vector< float4 > points
device_vector< uint > prim_visibility
device_vector< float4 > attributes_float4
device_vector< KernelCurveSegment > curve_segments
device_vector< float2 > attributes_float2
device_vector< AttributeMap > attributes_map
device_vector< KernelCurve > curves
device_vector< packed_uint3 > tri_vindex
device_vector< int > object_node
device_vector< packed_float3 > attributes_float3
device_vector< int > prim_object
device_vector< float4 > curve_keys
device_vector< packed_float3 > tri_vnormal
device_vector< int4 > bvh_leaf_nodes
device_vector< uint > tri_shader
device_vector< packed_float3 > tri_verts
device_vector< float > attributes_float
device_vector< float2 > tri_patch_uv
device_vector< uint > tri_patch
device_vector< int > prim_type
device_vector< int4 > bvh_nodes
device_vector< int > prim_index
device_vector< uchar4 > attributes_uchar4
virtual void * get_cpu_osl_memory()
void device_update_displacement_images(Device *device, Scene *scene, Progress &progress)
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress)
void geom_calc_offset(Scene *scene, BVHLayout bvh_layout)
void update_osl_globals(Device *device, Scene *scene)
void device_free(Device *device, DeviceScene *dscene, bool force_free)
void tag_update(Scene *scene, uint32_t flag)
void collect_statistics(const Scene *scene, RenderStats *stats)
void device_update_preprocess(Device *device, Scene *scene, Progress &progress)
void device_update_volume_images(Device *device, Scene *scene, Progress &progress)
Transform transform_normal
void compute_bvh(Device *device, DeviceScene *dscene, SceneParams *params, Progress *progress, size_t n, size_t total)
float motion_time(int step) const
bool need_update_bvh_for_offset
bool has_true_displacement() const
bool need_build_bvh(BVHLayout layout) const
bool is_pointcloud() const
int motion_step(float time) const
bool is_instanced() const
bool has_motion_blur() const
void tag_update(Scene *scene, bool rebuild)
Geometry(const NodeType *node_type, const Type type)
bool transform_negative_scaled
void tag_bvh_update(bool rebuild)
virtual void clear(bool preserve_shaders=false)
bool need_shadow_transparency()
CurveShapeType curve_shape
int svm_slot(const int tile_index=0) const
void device_update_slot(Device *device, Scene *scene, size_t slot, Progress *progress)
void add_entry(const NamedSizeEntry &entry)
void set_status(const string &status_, const string &substatus_="")
void tag_update(Scene *scene)
void free_if_need_realloc(bool force_free)
#define CCL_NAMESPACE_END
@ ATTR_STD_POSITION_UNDISPLACED
@ ATTR_STD_MOTION_VERTEX_POSITION
@ BVH_LAYOUT_MULTI_HIPRT_EMBREE
@ BVH_LAYOUT_MULTI_EMBREEGPU
@ BVH_LAYOUT_MULTI_METAL_EMBREE
@ BVH_LAYOUT_MULTI_EMBREEGPU_EMBREE
@ BVH_LAYOUT_MULTI_OPTIX_EMBREE
#define SOCKET_NODE_ARRAY(name, ui_name, node_type,...)
#define SOCKET_UINT(name, ui_name, default_value,...)
#define SOCKET_BOOLEAN(name, ui_name, default_value,...)
#define NODE_ABSTRACT_DEFINE(structname)
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
static void update_device_flags_attribute(uint32_t &device_update_flags, const AttributeSet &attributes)
static void update_attribute_realloc_flags(uint32_t &device_update_flags, const AttributeSet &attributes)
@ DEVICE_MESH_DATA_NEEDS_REALLOC
@ DEVICE_POINT_DATA_MODIFIED
@ DEVICE_POINT_DATA_NEEDS_REALLOC
@ ATTR_FLOAT4_NEEDS_REALLOC
@ ATTR_UCHAR4_NEEDS_REALLOC
@ ATTR_FLOAT2_NEEDS_REALLOC
@ DEVICE_MESH_DATA_MODIFIED
@ DEVICE_CURVE_DATA_MODIFIED
@ ATTR_FLOAT_NEEDS_REALLOC
@ DEVICE_CURVE_DATA_NEEDS_REALLOC
@ ATTR_FLOAT3_NEEDS_REALLOC
@ SHADER_SPECIAL_TYPE_IMAGE_SLOT
@ SHADER_SPECIAL_TYPE_OSL
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
void set_screen_size(int width_, int height_)
void update(Scene *scene)
int num_ptex_faces() const
AttributeSet subd_attributes
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=NULL)
void dereference_all_used_nodes()
size_t num_points() const
string full_report() const
void push(TaskRunFunction &&task)
void wait_work(Summary *stats=NULL)