25 const float motion_scale)
27 const int num_points = pointcloud->
num_points();
30 pointcloud->set_motion_steps(3);
38 const float *radius = pointcloud->
get_radius();
41 const float motion_times[2] = {-1.0f, 1.0f};
43 const float relative_time = motion_times[
step - 1] * 0.5f * motion_scale;
47 for (
int i = 0; i < num_points; i++) {
49 make_float3(b_attribute[i][0], b_attribute[i][1], b_attribute[i][2]) * relative_time;
57 const bool need_motion,
58 const float motion_scale)
66 static const ustring u_velocity(
"velocity");
68 const ustring name{std::string_view(iter.
name)};
70 if (need_motion && name == u_velocity) {
75 if (attributes.
find(name)) {
81 using Converter = typename ccl::AttributeConverter<BlenderT>;
82 using CyclesT = typename Converter::CyclesT;
83 if constexpr (!std::is_void_v<CyclesT>) {
84 const blender::VArray<BlenderT> src_varray = b_attr.varray.typed<BlenderT>();
85 const blender::CommonVArrayInfo info = b_attr.varray.common_info();
87 if (info.type == blender::CommonVArrayInfo::Type::Single) {
88 const auto &single_value = *static_cast<const BlenderT *>(info.data);
89 Attribute *attr = attributes.add(name, Converter::type_desc, ATTR_ELEMENT_MESH);
90 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
91 *data = Converter::convert(single_value);
95 if constexpr (Converter::layout_compatible) {
96 if (info.type == blender::CommonVArrayInfo::Type::Span && b_attr.sharing_info) {
97 attributes.add_shared(name,
102 b_attr.sharing_info);
107 Attribute *attr = attributes.add(name, Converter::type_desc, ATTR_ELEMENT_VERTEX);
108 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
110 const blender::VArraySpan src = src_varray;
111 for (const int i : src.index_range()) {
112 data[i] = Converter::convert(src[i]);
122 const size_t num_points = pointcloud->
num_points();
149 const string sh_attr_name =
"radiance:sh_" + std::to_string(i);
155 sh_attribute_readers.push_back(std::move(reader));
156 sh_attribute_spans.push_back(
159 if (!sh_attribute_readers.empty()) {
163 parallel_for(blocked_range<size_t>(0, num_points, 32), [&](
const blocked_range<size_t> &r) {
164 for (
size_t point_index = r.begin(); point_index != r.end(); point_index++) {
166 for (
int sh_index = 0; sh_index < int(sh_attribute_readers.size()); ++sh_index) {
168 sh_data[point_index],
170 make_float3(sh_attribute_spans[sh_index][point_index].
x,
171 sh_attribute_spans[sh_index][point_index].
y,
172 sh_attribute_spans[sh_index][point_index].
z));
191 const int num_points = pointcloud->
num_points();
192 const bool size_matches = (b_positions.
size() == num_points);
236 parallel_for(blocked_range<size_t>(0, std::min<int>(num_points, b_positions.
size()), 32),
237 [&](
const blocked_range<size_t> &r) {
238 for (size_t i = r.begin(); i != r.end(); i++) {
239 motion_radiance_base[i] = b_radiance_base.is_empty() ?
240 PointCloud::DEFAULT_GSPLAT_RADIANCE_BASE :
241 make_float4(b_radiance_base[i][0],
242 b_radiance_base[i][1],
243 b_radiance_base[i][2],
244 b_radiance_base[i][3]);
245 motion_scale[i] = b_scale.is_empty() ?
246 PointCloud::DEFAULT_GSPLAT_SCALE :
247 make_float3(b_scale[i][0], b_scale[i][1], b_scale[i][2]);
248 motion_rotation[i] = b_rotation.is_empty() ? identity_quaternion() :
249 make_quaternion(b_rotation[i][0],
260 const bool need_motion,
261 const float motion_scale)
287 std::fill(radius, radius + b_positions.
size(), 0.01f);
290 int *shader = pointcloud->get_shader().data();
291 std::fill(shader, shader + b_positions.
size(), 0);
311 const int motion_step)
318 Attribute *attr_radiance_base = is_gsplat ?
324 const bool has_gsplat_attributes = (attr_radiance_base && attr_scale && attr_rotation);
325 bool new_attribute =
false;
330 if (is_gsplat && has_gsplat_attributes) {
335 new_attribute =
true;
338 const int num_points = pointcloud->
num_points();
339 const int attr_step = motion_step + 1;
342 const bool size_matches = (b_positions.
size() == num_points);
344 bool have_motion =
false;
359 std::fill(mR, mR + num_points, 0.01f);
366 have_motion = motion_P != center_P &&
367 std::memcmp(motion_P, center_P, num_points *
sizeof(
packed_float3)) != 0;
378 for (
int i = 0; i < std::min<int>(num_points, b_positions.
size()); i++) {
379 mP[i] =
make_float3(b_positions[i][0], b_positions[i][1], b_positions[i][2]);
380 mR[i] = b_radius.
is_empty() ? 0.01f : b_radius[i];
384 if (is_gsplat && has_gsplat_attributes) {
397 if (!size_matches || !have_motion) {
400 if (is_gsplat && has_gsplat_attributes) {
406 else if (motion_step > 0) {
421 const size_t old_numpoints = pointcloud->
num_points();
423 array<Node *> used_shaders = pointcloud->get_used_shaders();
426 new_pointcloud.set_used_shaders(used_shaders);
432 const bool need_motion = object_need_motion_attribute(b_ob_info, scene);
433 const float motion_scale = (need_motion) ? scene->motion_shutter_time() /
434 (b_scene->r.frs_sec / b_scene->r.frs_sec_base) :
436 export_pointcloud(scene, &new_pointcloud, *b_pointcloud, need_motion, motion_scale);
441 new_pointcloud.set_motion_steps(2);
458 for (
const SocketType &socket : new_pointcloud.
type->
inputs) {
460 if (socket.
name ==
"use_motion_blur" || socket.
name ==
"used_shaders") {
463 pointcloud->
set_value(socket, new_pointcloud, socket);
469 const bool rebuild = (pointcloud && old_numpoints != pointcloud->
num_points());
473void BlenderSync::sync_pointcloud_motion(
PointCloud *pointcloud,
475 const int motion_step)
483 if (ccl::BKE_object_is_deform_modified(b_ob_info, *b_scene, preview)) {
bool sync_attribute_from_blender(AttributeSet &attributes, const AttributeStandard std, const blender::bke::AttributeReader< BlenderT > &b_reader, const int size)
bool sync_attribute_motion_step_from_blender(Attribute &attr, const int motion_step, const blender::bke::AttributeReader< BlenderT > &b_reader)
static void attr_create_motion_from_velocity(Hair *hair, const blender::Span< blender::float3 > src, const float motion_scale)
static void export_pointcloud_motion_gsplat_attributes(PointCloud *pointcloud, Attribute *attr_radiance_base, Attribute *attr_scale, Attribute *attr_rotation, const blender::PointCloud &b_pointcloud, const blender::bke::AttributeAccessor &b_attributes, const int attr_step)
static void export_pointcloud_motion(PointCloud *pointcloud, const blender::PointCloud &b_pointcloud, const int motion_step)
static void export_pointcloud_gsplat_attributes(PointCloud *pointcloud, const blender::bke::AttributeAccessor &b_attributes)
static void export_pointcloud(Scene *scene, PointCloud *pointcloud, const blender::PointCloud &b_pointcloud, const bool need_motion, const float motion_scale)
static void copy_attributes(PointCloud *pointcloud, const blender::PointCloud &b_pointcloud, const bool need_motion, const float motion_scale)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
void update(AttributeSet &&new_attributes)
Attribute * find(ustring name) const
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
void take_motion_from(Attribute &other)
const T * data(const int step=0) const
T * data_for_write(const int step=0)
void add_motion(const Geometry *geom)
void tag_position_modified()
const packed_float3 * get_position() const
void tag_update(Scene *scene, bool rebuild)
float * get_radius_for_write()
const float * get_radius() const
bool need_attribute(const Scene *scene, AttributeStandard std)
void tag_radius_modified()
void resize(const int numpoints)
void create_missing_gsplat_attributes()
size_t num_points() const
static const float4 DEFAULT_GSPLAT_RADIANCE_BASE
void copy_center_to_motion_step(const int motion_step)
static const float3 DEFAULT_GSPLAT_SCALE
@ MOTION_PASS_INTERACTIVE
const CPPType & type() const
constexpr int64_t size() const
constexpr IndexRange index_range() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef name) const
int domain_size(const AttrDomain domain) const
GAttributeReader get() const
constexpr bool is_empty() const
#define CCL_NAMESPACE_END
float hash_uint2_to_float(uint kx, uint ky)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
@ ATTR_STD_GSPLAT_RADIANCE_BASE
@ ATTR_STD_GSPLAT_ROTATION
@ ATTR_STD_GSPLAT_RADIANCE_SPHERICAL_HARMONICS_REST
void to_static_type(const CPPType &cpp_type, Fn &&fn)
QuaternionBase< float > Quaternion
VecBase< float, 4 > float4
VecBase< float, 3 > float3
blender::ID * object_data
vector< SocketType, std::allocator< SocketType > > inputs
void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
ccl_static_constexpr int MAX_COEFFICIENTS
ccl_device_inline Quaternion identity_quaternion()
ccl_device_forceinline void spherical_harmonics_rest_fill_zero(ccl_global PackedSphericalHarmonicsRest &packed_spherical_harmonics_rest)
ccl_device_forceinline void spherical_harmonics_rest_set_coefficient(ccl_global PackedSphericalHarmonicsRest &packed_spherical_harmonics_rest, const int index, const float3 value)