28#include <fmt/format.h>
76 const int max_index =
mask.min_array_size();
80 mask.to_indices<
int>(
data.cast<
int>());
92 float a = 1.0f -
w *
w;
93 float b = 1.0f /
sqrt(a + 1.0e-8f);
115 const float3 &bounded_log_scale,
116 bool log_scale_is_zero,
123 uint3 su = log_scale_is_zero ?
139 w.x = (pu.x & 0x3FFFFFu) |
140 ((pu.y & 0x0003FFu) << 22);
141 w.y = ((pu.y >> 10) & 0x000FFFu) |
142 ((pu.z & 0x0FFFFFu) << 12);
143 w.z = ((pu.z >> 20) & 0x000003u) |
144 ((ru.x & 0x0001FFu) << 2) |
145 ((ru.y & 0x0001FFu) << 11) |
146 ((ru.z & 0x0001FFu) << 20) |
147 ((su.x & 0x000007u) << 29);
148 w.w = ((su.x >> 3) & 0x00003Fu) |
149 ((su.y & 0x0001FFu) << 6) |
150 ((su.z & 0x0001FFu) << 15) |
151 ((au & 0x0000FFu) << 24);
184 uchar3 *shu_data =
reinterpret_cast<uchar3 *
>(pack.radiance_sh + (3 * i));
204 arrays.
append(std::move(array_i));
233 static constexpr float zero_log_scale = -1e6f;
236 for (const int i : range) {
237 scale[i] = math::is_any_zero(exp_scale[i]) ? float3(zero_log_scale) :
238 math::log(math::abs(exp_scale[i]));
243 std::optional<Bounds<float3>> splat_scale_bounds_opt;
245 if (value.x == zero_log_scale) {
248 splat_scale_bounds_opt = splat_scale_bounds_opt ?
254 Bounds<float3> splat_mean_bounds = pointcloud.bounds_min_max(
false).value_or(Bounds<float3>());
255 Bounds<float3> splat_scale_bounds = splat_scale_bounds_opt.value_or(Bounds<float3>());
256 auto radiance_rgba_bounds =
bounds::min_max(radiance_base).value_or(Bounds<float4>());
258 Bounds<float3> radiance_base_bounds =
Bounds(radiance_rgba_bounds.min.xyz(),
259 radiance_rgba_bounds.max.xyz());
261 for (
const VArraySpan<float3> &radiance_sh_i : radiance_sh) {
262 if (
auto bounds =
bounds::min_max(radiance_sh_i); bounds.has_value()) {
264 radiance_sh_bounds =
bounds::merge(radiance_sh_bounds, *bounds);
269 ScalingRange splat_mean_range = {.range_add = splat_mean_bounds.min,
270 .range_mul = splat_mean_bounds.size()};
271 ScalingRange splat_scale_range = {.range_add = splat_scale_bounds.min,
272 .range_mul = splat_scale_bounds.size()};
273 ScalingRange radiance_base_range = {.range_add = radiance_base_bounds.min,
274 .range_mul = radiance_base_bounds.size()};
275 ScalingRange radiance_sh_range = {.range_add = radiance_sh_bounds.min,
276 .range_mul = radiance_sh_bounds.size()};
279 GSplatInfos ubo_data = {.splat_mean_range = splat_mean_range,
280 .splat_scale_range = splat_scale_range,
281 .radiance_base_range = radiance_base_range,
282 .radiance_sh_range = radiance_sh_range};
287 shape_data_buf->init(gpu::GenericVertexFormat<uint4>::format(), usage_flag);
288 shape_data_buf->allocate(mean.size());
289 radiance_data_buf->init(gpu::GenericVertexFormat<uint4>::format(), usage_flag);
290 radiance_data_buf->allocate(mean.size() * 3);
293 MutableSpan shape_span = shape_data_buf->data<
uint4>();
295 for (const int i : range) {
296 const float3 value_mean = splat_mean_range.scale_to_unit(mean[i]);
297 const float3 value_scale = splat_scale_range.scale_to_unit(scale[i]);
298 const bool log_scale_is_zero = math::is_equal(scale[i], float3(zero_log_scale));
300 shape_span[i] = detail::pack_gaussian(
301 value_mean, value_scale, log_scale_is_zero, quaternion[i], radiance_base[i].w);
306 MutableSpan radiance_span = radiance_data_buf->
data<detail::RadiancePack>();
309 for (const int i : range) {
310 Array<float3, radiance_coeffs_max> value_radiance(radiance_coeffs_max, radiance_sh_default);
311 value_radiance[0] = radiance_base_range.scale_to_unit(radiance_base[i].xyz());
312 for (uint j = 0; j < radiance_sh.size(); ++j) {
313 value_radiance[j + 1] = radiance_sh_range.scale_to_unit(radiance_sh[j][i]);
315 radiance_span[i] = detail::pack_radiance(value_radiance);
328 if (
mask.is_empty()) {
419 for (
int i = 0; i <
mat_len; ++i) {
430 for (
const int j :
IndexRange(GPU_MAX_ATTR)) {
536 ptr = MEM_new<GSplatBatchCache>(__func__);
625 if (ptr ==
nullptr) {
664 bool do_discard =
false;
General operations, lookup, etc. for materials.
General operations for point clouds.
Object is a sort of wrapper for general info.
#define GPU_BATCH_DISCARD_SAFE(batch)
#define GPU_INDEXBUF_DISCARD_SAFE(elem)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr IndexRange()=default
constexpr T * data() const
IndexRange index_range() const
IndexRange index_range() const
void append(const T &value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
GAttributeReader lookup(const StringRef name) const
constexpr bool is_empty() const
void init(const GPUVertFormat &format, GPUUsageType usage)
void allocate(uint vert_len)
Utilities for rendering attributes.
#define DRW_GSPLAT_STRIP_TILE_SIZE
constexpr T clamp(T, U, U) RET
float3x3 scale(float3x3 mat, float2 scale)
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
std::optional< Bounds< T > > min_max(const std::optional< Bounds< T > > &a, const T &b)
BLI_INLINE float3 pack_quaternion_4_to_3(const float4 &q)
static Vector< VArraySpan< float3 > > read_radiance_sh_attributes(const bke::AttributeAccessor &attributes)
BLI_INLINE RadiancePack pack_radiance(const Array< float3, radiance_coeffs_max > &radiance_sh)
static void index_mask_to_ibo(const IndexMask &mask, gpu::IndexBuf &ibo)
BLI_INLINE uint4 pack_gaussian(const float3 &bounded_mean, const float3 &bounded_log_scale, bool log_scale_is_zero, const math::Quaternion &rotation, float opacity)
void drw_attributes_add_request(VectorSet< std::string > *attrs, const StringRef name)
gpu::Batch * DRW_gsplat_batch_cache_get_dots(Object *ob)
constexpr uint32_t radiance_coeffs_max
void DRW_gsplat_batch_cache_create_requested(Object *ob)
void DRW_gsplat_batch_cache_validate(PointCloud *pointcloud)
bool drw_attributes_overlap(const VectorSet< std::string > *a, const VectorSet< std::string > *b)
gpu::VertBuf ** DRW_gsplat_evaluated_attribute(PointCloud *pointcloud, StringRef name)
constexpr float value_scale_default
void DRW_gsplat_batch_cache_free(PointCloud *pointcloud)
void drw_attributes_merge(VectorSet< std::string > *dst, const VectorSet< std::string > *src)
gpu::Batch * DRW_gsplat_batch_cache_get_edit_dots(Object *ob)
constexpr uint32_t radiance_degs_max
void DRW_gsplat_batch_cache_free_old(PointCloud *pointcloud, int ctime)
void DRW_gsplat_batch_cache_dirty_tag(PointCloud *pointcloud, int mode)
constexpr float value_opacity_default
QuaternionBase< float > Quaternion
T clamp(const T &a, const T &min, const T &max)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ BKE_POINTCLOUD_BATCH_DIRTY_ALL
bool DRW_vbo_requested(gpu::VertBuf *vbo)
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
void GPU_vertbuf_init_with_format_ex(gpu::VertBuf &verts, const GPUVertFormat &format, GPUUsageType)
bool DRW_batch_requested(gpu::Batch *batch, GPUPrimType prim_type)
VecBase< uint32_t, 4 > uint4
VecBase< uint32_t, 3 > uint3
VecBase< float, 4 > float4
int BKE_id_material_used_with_fallback_eval(const ID &id)
void DRW_ibo_request(gpu::Batch *batch, gpu::IndexBuf **ibo)
void GPU_indexbuf_build_in_place_ex(GPUIndexBufBuilder *builder, uint index_min, uint index_max, bool uses_restart_indices, gpu::IndexBuf *elem)
T & DRW_object_get_data_for_drawing(const Object &object)
BMesh const char void * data
MutableSpan< uint32_t > GPU_indexbuf_get_data(GPUIndexBufBuilder *)
gpu::UniformBuf * GPU_uniformbuf_create_ex(size_t size, const void *data, const char *name)
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void GPU_uniformbuf_update(gpu::UniformBuf *ubo, const void *data)
gpu::Batch * DRW_batch_request(gpu::Batch **batch)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
VecBase< uint8_t, 3 > uchar3
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
void DRW_vbo_request(gpu::Batch *batch, gpu::VertBuf **vbo)
@ GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool DRW_ibo_requested(gpu::IndexBuf *ibo)
float3 scale_to_unit(float3 value) const
draw::GSplatBatchCache * gsplat_batch_cache
static bool is_valid(PointCloud &pointcloud)
static void clear(PointCloud &pointcloud)
GSplatEvalCache eval_cache
static GSplatBatchCache * get_ptr(PointCloud &pointcloud)
static void init(PointCloud &pointcloud)
VectorSet< std::string > attr_used
void discard_attributes()
gpu::VertBuf ** radiance_comp_buf_get()
void ensure_compute_buffers(PointCloud &pointcloud)
gpu::VertBuf * radiance_comp_buf
void ensure_builtin_buffers(PointCloud &pointcloud)
VectorSet< std::string > attr_used_over_time
gpu::Batch ** surface_per_mat
void ensure_requested(PointCloud &pointcloud)
gpu::VertBuf * attr_viewer
gpu::UniformBuf * infos_buf_get()
gpu::IndexBuf * edit_dots_indices
gpu::VertBuf * shape_data_buf
void ensure_attribute(PointCloud &pointcloud, int attrib_i)
gpu::Batch * surface_get(const PointCloud &pointcloud)
gpu::UniformBuf * infos_buf
int last_attr_matching_time
gpu::VertBuf * shape_data_buf_get()
gpu::VertBuf ** attributes_get(uint request_i)
void ensure_edit_dots_indices(PointCloud &pointcloud)
static GSplatEvalCache & get(PointCloud &pointcloud)
gpu::VertBuf * radiance_data_buf
gpu::VertBuf ** ellipses_comp_buf_get()
gpu::Batch * edit_dots_get()
gpu::VertBuf * attributes_buf[GPU_MAX_ATTR]
gpu::VertBuf * radiance_data_buf_get()
gpu::VertBuf * ellipses_comp_buf
static QuaternionBase identity()