diff options
author | Brecht Van Lommel <brecht@blender.org> | 2021-12-01 19:30:46 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2021-12-16 22:54:04 +0300 |
commit | 35b1e9fc3acd6db565e7e54252a4a4152d8343d9 (patch) | |
tree | 8599df3b2be192d1fe19d30a8afb7e8d8729499e /intern/cycles/scene/alembic.cpp | |
parent | 2229179faa44e2c685b4eabd0c51d4c7d5c1f193 (diff) |
Cycles: pointcloud rendering
This add support for rendering of the point cloud object in Blender, as a native
geometry type in Cycles that is more memory and time efficient than instancing
sphere meshes. This can be useful for rendering sand, water splashes, particles,
motion graphics, etc.
Points are currently always rendered as spheres, with backface culling. More
shapes are likely to be added later, but this is the most important one and can
be customized with shaders.
For CPU rendering the Embree primitive is used, for GPU there is our own
intersection code. Motion blur is suppored. Volumes inside points are not
currently supported.
Implemented with help from:
* Kévin Dietrich: Alembic procedural integration
* Patrick Mourse: OptiX integration
* Josh Whelchel: update for cycles-x changes
Ref T92573
Differential Revision: https://developer.blender.org/D9887
Diffstat (limited to 'intern/cycles/scene/alembic.cpp')
-rw-r--r-- | intern/cycles/scene/alembic.cpp | 87 |
1 files changed, 86 insertions, 1 deletions
diff --git a/intern/cycles/scene/alembic.cpp b/intern/cycles/scene/alembic.cpp index 39b5f467736..71fa1863b8b 100644 --- a/intern/cycles/scene/alembic.cpp +++ b/intern/cycles/scene/alembic.cpp @@ -21,6 +21,7 @@ #include "scene/curves.h" #include "scene/mesh.h" #include "scene/object.h" +#include "scene/pointcloud.h" #include "scene/scene.h" #include "scene/shader.h" @@ -99,6 +100,9 @@ void CachedData::clear() triangles.clear(); uv_loops.clear(); vertices.clear(); + points.clear(); + radiuses.clear(); + points_shader.clear(); for (CachedAttribute &attr : attributes) { attr.data.clear(); @@ -146,6 +150,9 @@ bool CachedData::is_constant() const CHECK_IF_CONSTANT(triangles) CHECK_IF_CONSTANT(uv_loops) CHECK_IF_CONSTANT(vertices) + CHECK_IF_CONSTANT(points) + CHECK_IF_CONSTANT(radiuses) + CHECK_IF_CONSTANT(points_shader) for (const CachedAttribute &attr : attributes) { if (!attr.data.is_constant()) { @@ -185,6 +192,9 @@ void CachedData::invalidate_last_loaded_time(bool attributes_only) triangles.invalidate_last_loaded_time(); uv_loops.invalidate_last_loaded_time(); vertices.invalidate_last_loaded_time(); + points.invalidate_last_loaded_time(); + radiuses.invalidate_last_loaded_time(); + points_shader.invalidate_last_loaded_time(); } void CachedData::set_time_sampling(TimeSampling time_sampling) @@ -206,6 +216,9 @@ void CachedData::set_time_sampling(TimeSampling time_sampling) triangles.set_time_sampling(time_sampling); uv_loops.set_time_sampling(time_sampling); vertices.set_time_sampling(time_sampling); + points.set_time_sampling(time_sampling); + radiuses.set_time_sampling(time_sampling); + points_shader.set_time_sampling(time_sampling); for (CachedAttribute &attr : attributes) { attr.data.set_time_sampling(time_sampling); @@ -233,6 +246,9 @@ size_t CachedData::memory_used() const mem_used += triangles.memory_used(); mem_used += uv_loops.memory_used(); mem_used += vertices.memory_used(); + mem_used += points.memory_used(); + mem_used += radiuses.memory_used(); + mem_used += points_shader.memory_used(); for (const CachedAttribute &attr : attributes) { mem_used += attr.data.memory_used(); @@ -901,6 +917,9 @@ void AlembicProcedural::generate(Scene *scene, Progress &progress) else if (object->schema_type == AlembicObject::CURVES) { read_curves(object, frame_time); } + else if (object->schema_type == AlembicObject::POINTS) { + read_points(object, frame_time); + } else if (object->schema_type == AlembicObject::SUBD) { read_subd(object, frame_time); } @@ -970,6 +989,9 @@ void AlembicProcedural::load_objects(Progress &progress) if (abc_object->schema_type == AlembicObject::CURVES) { geometry = scene_->create_node<Hair>(); } + else if (abc_object->schema_type == AlembicObject::POINTS) { + geometry = scene_->create_node<PointCloud>(); + } else if (abc_object->schema_type == AlembicObject::POLY_MESH || abc_object->schema_type == AlembicObject::SUBD) { geometry = scene_->create_node<Mesh>(); @@ -1202,6 +1224,45 @@ void AlembicProcedural::read_curves(AlembicObject *abc_object, Abc::chrono_t fra hair->tag_update(scene_, rebuild); } +void AlembicProcedural::read_points(AlembicObject *abc_object, Abc::chrono_t frame_time) +{ + CachedData &cached_data = abc_object->get_cached_data(); + + /* update sockets */ + + Object *object = abc_object->get_object(); + cached_data.transforms.copy_to_socket(frame_time, object, object->get_tfm_socket()); + + if (object->is_modified()) { + object->tag_update(scene_); + } + + /* Only update sockets for the original Geometry. */ + if (abc_object->instance_of) { + return; + } + + PointCloud *point_cloud = static_cast<PointCloud *>(object->get_geometry()); + + /* Make sure shader ids are also updated. */ + if (point_cloud->used_shaders_is_modified()) { + point_cloud->tag_shader_modified(); + } + + cached_data.points.copy_to_socket(frame_time, point_cloud, point_cloud->get_points_socket()); + cached_data.radiuses.copy_to_socket(frame_time, point_cloud, point_cloud->get_radius_socket()); + cached_data.points_shader.copy_to_socket( + frame_time, point_cloud, point_cloud->get_shader_socket()); + + /* update attributes */ + + update_attributes(point_cloud->attributes, cached_data, frame_time); + + const bool rebuild = (point_cloud->points_is_modified() || point_cloud->radius_is_modified() || + point_cloud->shader_is_modified()); + point_cloud->tag_update(scene_, rebuild); +} + void AlembicProcedural::walk_hierarchy( IObject parent, const ObjectHeader &header, @@ -1314,7 +1375,23 @@ void AlembicProcedural::walk_hierarchy( // ignore the face set, it will be read along with the data } else if (IPoints::matches(header)) { - // unsupported for now + IPoints points(parent, header.getName()); + + unordered_map<std::string, AlembicObject *>::const_iterator iter; + iter = object_map.find(points.getFullName()); + + if (iter != object_map.end()) { + AlembicObject *abc_object = iter->second; + abc_object->iobject = points; + abc_object->schema_type = AlembicObject::POINTS; + + if (matrix_samples_data.samples) { + abc_object->xform_samples = *matrix_samples_data.samples; + abc_object->xform_time_sampling = matrix_samples_data.time_sampling; + } + } + + next_object = points; } else if (INuPatch::matches(header)) { // unsupported for now @@ -1391,6 +1468,14 @@ void AlembicProcedural::build_caches(Progress &progress) object->load_data_in_cache(object->get_cached_data(), this, schema, progress); } } + else if (object->schema_type == AlembicObject::POINTS) { + if (!object->has_data_loaded() || default_radius_is_modified() || + object->radius_scale_is_modified()) { + IPoints points(object->iobject, Alembic::Abc::kWrapExisting); + IPointsSchema schema = points.getSchema(); + object->load_data_in_cache(object->get_cached_data(), this, schema, progress); + } + } else if (object->schema_type == AlembicObject::SUBD) { if (!object->has_data_loaded()) { ISubD subd_mesh(object->iobject, Alembic::Abc::kWrapExisting); |