2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2017 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup draw
|
|
|
|
|
*
|
|
|
|
|
* \brief PointCloud API for render engines
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-05 13:44:02 -05:00
|
|
|
#include <cstring>
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2023-09-01 21:37:11 +02:00
|
|
|
#include "BLI_listbase.h"
|
2022-08-09 11:10:44 -05:00
|
|
|
#include "BLI_math_base.h"
|
2023-08-13 10:50:52 +03:00
|
|
|
#include "BLI_math_color.hh"
|
2022-08-09 11:10:44 -05:00
|
|
|
#include "BLI_math_vector.h"
|
2022-08-09 12:33:46 -05:00
|
|
|
#include "BLI_task.hh"
|
2022-08-09 11:10:44 -05:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_pointcloud_types.h"
|
|
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
#include "BKE_attribute.hh"
|
2024-01-11 10:54:47 +01:00
|
|
|
#include "BKE_pointcloud.hh"
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
#include "GPU_batch.h"
|
2022-10-25 10:43:47 +02:00
|
|
|
#include "GPU_material.h"
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2023-02-13 20:56:24 +01:00
|
|
|
#include "draw_attributes.hh"
|
2023-08-03 20:04:50 -04:00
|
|
|
#include "draw_cache_impl.hh"
|
2024-01-05 11:16:57 -05:00
|
|
|
#include "draw_cache_inline.hh"
|
2022-10-25 10:43:47 +02:00
|
|
|
#include "draw_pointcloud_private.hh" /* own include */
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2024-01-05 12:20:30 -05:00
|
|
|
namespace blender::draw {
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name GPUBatch cache management
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
struct PointCloudEvalCache {
|
2022-10-25 10:43:47 +02:00
|
|
|
/* Dot primitive types. */
|
2022-08-09 11:10:44 -05:00
|
|
|
GPUBatch *dots;
|
2022-10-25 10:43:47 +02:00
|
|
|
/* Triangle primitive types. */
|
2022-08-09 11:10:44 -05:00
|
|
|
GPUBatch *surface;
|
|
|
|
|
GPUBatch **surface_per_mat;
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/* Triangles indices to draw the points. */
|
|
|
|
|
GPUIndexBuf *geom_indices;
|
|
|
|
|
|
|
|
|
|
/* Position and radius. */
|
|
|
|
|
GPUVertBuf *pos_rad;
|
|
|
|
|
/* Active attribute in 3D view. */
|
|
|
|
|
GPUVertBuf *attr_viewer;
|
|
|
|
|
/* Requested attributes */
|
|
|
|
|
GPUVertBuf *attributes_buf[GPU_MAX_ATTR];
|
|
|
|
|
|
|
|
|
|
/** Attributes currently being drawn or about to be drawn. */
|
|
|
|
|
DRW_Attributes attr_used;
|
|
|
|
|
/**
|
|
|
|
|
* Attributes that were used at some point. This is used for garbage collection, to remove
|
|
|
|
|
* attributes that are not used in shaders anymore due to user edits.
|
|
|
|
|
*/
|
|
|
|
|
DRW_Attributes attr_used_over_time;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The last time in seconds that the `attr_used` and `attr_used_over_time` were exactly the same.
|
|
|
|
|
* If the delta between this time and the current scene time is greater than the timeout set in
|
|
|
|
|
* user preferences (`U.vbotimeout`) then garbage collection is performed.
|
|
|
|
|
*/
|
|
|
|
|
int last_attr_matching_time;
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
int mat_len;
|
2022-11-03 19:34:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PointCloudBatchCache {
|
|
|
|
|
PointCloudEvalCache eval_cache;
|
|
|
|
|
|
|
|
|
|
/* settings to determine if cache is invalid */
|
|
|
|
|
bool is_dirty;
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/**
|
|
|
|
|
* The draw cache extraction is currently not multi-threaded for multiple objects, but if it was,
|
|
|
|
|
* some locking would be necessary because multiple objects can use the same object data with
|
|
|
|
|
* different materials, etc. This is a placeholder to make multi-threading easier in the future.
|
|
|
|
|
*/
|
|
|
|
|
std::mutex render_mutex;
|
|
|
|
|
};
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
static PointCloudBatchCache *pointcloud_batch_cache_get(PointCloud &pointcloud)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
2022-08-09 12:33:46 -05:00
|
|
|
return static_cast<PointCloudBatchCache *>(pointcloud.batch_cache);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
static bool pointcloud_batch_cache_valid(PointCloud &pointcloud)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(pointcloud);
|
|
|
|
|
|
2022-08-28 20:52:28 +10:00
|
|
|
if (cache == nullptr) {
|
2022-08-09 11:10:44 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
if (cache->eval_cache.mat_len != DRW_pointcloud_material_count_get(&pointcloud)) {
|
2022-08-09 11:10:44 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return cache->is_dirty == false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
static void pointcloud_batch_cache_init(PointCloud &pointcloud)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(pointcloud);
|
|
|
|
|
|
|
|
|
|
if (!cache) {
|
2022-10-25 10:43:47 +02:00
|
|
|
cache = MEM_new<PointCloudBatchCache>(__func__);
|
2022-08-09 12:33:46 -05:00
|
|
|
pointcloud.batch_cache = cache;
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
else {
|
2022-11-03 19:34:50 +01:00
|
|
|
cache->eval_cache = {};
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
cache->eval_cache.mat_len = DRW_pointcloud_material_count_get(&pointcloud);
|
|
|
|
|
cache->eval_cache.surface_per_mat = static_cast<GPUBatch **>(
|
|
|
|
|
MEM_callocN(sizeof(GPUBatch *) * cache->eval_cache.mat_len, __func__));
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
cache->is_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DRW_pointcloud_batch_cache_dirty_tag(PointCloud *pointcloud, int mode)
|
|
|
|
|
{
|
2022-08-09 12:33:46 -05:00
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
2022-08-28 20:52:28 +10:00
|
|
|
if (cache == nullptr) {
|
2022-08-09 11:10:44 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case BKE_POINTCLOUD_BATCH_DIRTY_ALL:
|
|
|
|
|
cache->is_dirty = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
static void pointcloud_discard_attributes(PointCloudBatchCache &cache)
|
|
|
|
|
{
|
|
|
|
|
for (const int j : IndexRange(GPU_MAX_ATTR)) {
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_VERTBUF_DISCARD_SAFE(cache.eval_cache.attributes_buf[j]);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
drw_attributes_clear(&cache.eval_cache.attr_used);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
static void pointcloud_batch_cache_clear(PointCloud &pointcloud)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(pointcloud);
|
|
|
|
|
if (!cache) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_BATCH_DISCARD_SAFE(cache->eval_cache.dots);
|
|
|
|
|
GPU_BATCH_DISCARD_SAFE(cache->eval_cache.surface);
|
|
|
|
|
GPU_VERTBUF_DISCARD_SAFE(cache->eval_cache.pos_rad);
|
|
|
|
|
GPU_VERTBUF_DISCARD_SAFE(cache->eval_cache.attr_viewer);
|
|
|
|
|
GPU_INDEXBUF_DISCARD_SAFE(cache->eval_cache.geom_indices);
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (cache->eval_cache.surface_per_mat) {
|
|
|
|
|
for (int i = 0; i < cache->eval_cache.mat_len; i++) {
|
|
|
|
|
GPU_BATCH_DISCARD_SAFE(cache->eval_cache.surface_per_mat[i]);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
MEM_SAFE_FREE(cache->eval_cache.surface_per_mat);
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
pointcloud_discard_attributes(*cache);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-08-09 12:33:46 -05:00
|
|
|
void DRW_pointcloud_batch_cache_validate(PointCloud *pointcloud)
|
|
|
|
|
{
|
|
|
|
|
if (!pointcloud_batch_cache_valid(*pointcloud)) {
|
|
|
|
|
pointcloud_batch_cache_clear(*pointcloud);
|
|
|
|
|
pointcloud_batch_cache_init(*pointcloud);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 11:10:44 -05:00
|
|
|
void DRW_pointcloud_batch_cache_free(PointCloud *pointcloud)
|
|
|
|
|
{
|
2022-08-09 12:33:46 -05:00
|
|
|
pointcloud_batch_cache_clear(*pointcloud);
|
2022-08-09 11:10:44 -05:00
|
|
|
MEM_SAFE_FREE(pointcloud->batch_cache);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
void DRW_pointcloud_batch_cache_free_old(PointCloud *pointcloud, int ctime)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
2022-10-25 10:43:47 +02:00
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
|
|
|
|
if (!cache) {
|
2022-08-09 11:10:44 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
bool do_discard = false;
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (drw_attributes_overlap(&cache->eval_cache.attr_used_over_time, &cache->eval_cache.attr_used))
|
|
|
|
|
{
|
|
|
|
|
cache->eval_cache.last_attr_matching_time = ctime;
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
2022-10-25 10:43:47 +02:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (ctime - cache->eval_cache.last_attr_matching_time > U.vbotimeout) {
|
2022-10-25 10:43:47 +02:00
|
|
|
do_discard = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
drw_attributes_clear(&cache->eval_cache.attr_used_over_time);
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
if (do_discard) {
|
|
|
|
|
pointcloud_discard_attributes(*cache);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name PointCloud extraction
|
|
|
|
|
* \{ */
|
2022-08-09 11:10:44 -05:00
|
|
|
|
|
|
|
|
static const uint half_octahedron_tris[4][3] = {
|
|
|
|
|
{0, 1, 2},
|
|
|
|
|
{0, 2, 3},
|
|
|
|
|
{0, 3, 4},
|
|
|
|
|
{0, 4, 1},
|
|
|
|
|
};
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
static void pointcloud_extract_indices(const PointCloud &pointcloud, PointCloudBatchCache &cache)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
2023-01-09 18:56:17 +11:00
|
|
|
/** \note Avoid modulo by non-power-of-two in shader. */
|
2022-10-25 10:43:47 +02:00
|
|
|
uint32_t vertid_max = pointcloud.totpoint * 32;
|
|
|
|
|
uint32_t index_len = pointcloud.totpoint * ARRAY_SIZE(half_octahedron_tris);
|
|
|
|
|
|
|
|
|
|
GPUIndexBufBuilder builder;
|
|
|
|
|
GPU_indexbuf_init(&builder, GPU_PRIM_TRIS, index_len, vertid_max);
|
|
|
|
|
|
|
|
|
|
for (int p = 0; p < pointcloud.totpoint; p++) {
|
|
|
|
|
for (int i = 0; i < ARRAY_SIZE(half_octahedron_tris); i++) {
|
|
|
|
|
GPU_indexbuf_add_tri_verts(&builder,
|
|
|
|
|
half_octahedron_tris[i][0] + p * 32,
|
|
|
|
|
half_octahedron_tris[i][1] + p * 32,
|
|
|
|
|
half_octahedron_tris[i][2] + p * 32);
|
|
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_indexbuf_build_in_place(&builder, cache.eval_cache.geom_indices);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void pointcloud_extract_position_and_radius(const PointCloud &pointcloud,
|
|
|
|
|
PointCloudBatchCache &cache)
|
|
|
|
|
{
|
|
|
|
|
const bke::AttributeAccessor attributes = pointcloud.attributes();
|
2023-04-13 11:55:32 -04:00
|
|
|
const Span<float3> positions = pointcloud.positions();
|
2023-04-19 11:21:06 +02:00
|
|
|
const VArray<float> radii = *attributes.lookup<float>("radius");
|
2022-08-09 11:10:44 -05:00
|
|
|
static GPUVertFormat format = {0};
|
|
|
|
|
if (format.attr_len == 0) {
|
2022-10-25 10:43:47 +02:00
|
|
|
GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUUsageType usage_flag = GPU_USAGE_STATIC | GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY;
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_vertbuf_init_with_format_ex(cache.eval_cache.pos_rad, &format, usage_flag);
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_vertbuf_data_alloc(cache.eval_cache.pos_rad, positions.size());
|
|
|
|
|
MutableSpan<float4> vbo_data{
|
|
|
|
|
static_cast<float4 *>(GPU_vertbuf_get_data(cache.eval_cache.pos_rad)), pointcloud.totpoint};
|
2022-10-25 10:43:47 +02:00
|
|
|
if (radii) {
|
|
|
|
|
const VArraySpan<float> radii_span(radii);
|
|
|
|
|
threading::parallel_for(vbo_data.index_range(), 4096, [&](IndexRange range) {
|
|
|
|
|
for (const int i : range) {
|
|
|
|
|
vbo_data[i].x = positions[i].x;
|
|
|
|
|
vbo_data[i].y = positions[i].y;
|
|
|
|
|
vbo_data[i].z = positions[i].z;
|
|
|
|
|
/* TODO(fclem): remove multiplication. Here only for keeping the size correct for now. */
|
|
|
|
|
vbo_data[i].w = radii_span[i] * 100.0f;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
threading::parallel_for(vbo_data.index_range(), 4096, [&](IndexRange range) {
|
|
|
|
|
for (const int i : range) {
|
|
|
|
|
vbo_data[i].x = positions[i].x;
|
|
|
|
|
vbo_data[i].y = positions[i].y;
|
|
|
|
|
vbo_data[i].z = positions[i].z;
|
|
|
|
|
vbo_data[i].w = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
static void pointcloud_extract_attribute(const PointCloud &pointcloud,
|
|
|
|
|
PointCloudBatchCache &cache,
|
|
|
|
|
const DRW_AttributeRequest &request,
|
|
|
|
|
int index)
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
{
|
2022-11-03 19:34:50 +01:00
|
|
|
GPUVertBuf *&attr_buf = cache.eval_cache.attributes_buf[index];
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
|
|
|
|
const bke::AttributeAccessor attributes = pointcloud.attributes();
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
/* TODO(@kevindietrich): float4 is used for scalar attributes as the implicit conversion done
|
|
|
|
|
* by OpenGL to vec4 for a scalar `s` will produce a `vec4(s, 0, 0, 1)`. However, following
|
|
|
|
|
* the Blender convention, it should be `vec4(s, s, s, 1)`. This could be resolved using a
|
|
|
|
|
* similar texture state swizzle to map the attribute correctly as for volume attributes, so we
|
|
|
|
|
* can control the conversion ourselves. */
|
2023-04-19 11:21:06 +02:00
|
|
|
bke::AttributeReader<ColorGeometry4f> attribute = attributes.lookup_or_default<ColorGeometry4f>(
|
2022-10-25 10:43:47 +02:00
|
|
|
request.attribute_name, request.domain, {0.0f, 0.0f, 0.0f, 1.0f});
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
|
|
|
|
static GPUVertFormat format = {0};
|
|
|
|
|
if (format.attr_len == 0) {
|
2022-10-25 10:43:47 +02:00
|
|
|
GPU_vertformat_attr_add(&format, "attr", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUUsageType usage_flag = GPU_USAGE_STATIC | GPU_USAGE_FLAG_BUFFER_TEXTURE_ONLY;
|
|
|
|
|
GPU_vertbuf_init_with_format_ex(attr_buf, &format, usage_flag);
|
|
|
|
|
GPU_vertbuf_data_alloc(attr_buf, pointcloud.totpoint);
|
|
|
|
|
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
MutableSpan<ColorGeometry4f> vbo_data{
|
2022-10-25 10:43:47 +02:00
|
|
|
static_cast<ColorGeometry4f *>(GPU_vertbuf_get_data(attr_buf)), pointcloud.totpoint};
|
2023-04-19 11:21:06 +02:00
|
|
|
attribute.varray.materialize(vbo_data);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/** \} */
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Private API
|
|
|
|
|
* \{ */
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUVertBuf *pointcloud_position_and_radius_get(PointCloud *pointcloud)
|
|
|
|
|
{
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
2022-11-03 19:34:50 +01:00
|
|
|
DRW_vbo_request(nullptr, &cache->eval_cache.pos_rad);
|
|
|
|
|
return cache->eval_cache.pos_rad;
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUBatch **pointcloud_surface_shaded_get(PointCloud *pointcloud,
|
|
|
|
|
GPUMaterial **gpu_materials,
|
|
|
|
|
int mat_len)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
2022-10-25 10:43:47 +02:00
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
|
|
|
|
DRW_Attributes attrs_needed;
|
|
|
|
|
drw_attributes_clear(&attrs_needed);
|
|
|
|
|
|
|
|
|
|
for (GPUMaterial *gpu_material : Span<GPUMaterial *>(gpu_materials, mat_len)) {
|
|
|
|
|
ListBase gpu_attrs = GPU_material_attributes(gpu_material);
|
|
|
|
|
LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
|
|
|
|
|
const char *name = gpu_attr->name;
|
|
|
|
|
|
|
|
|
|
int layer_index;
|
|
|
|
|
eCustomDataType type;
|
2023-12-20 13:13:16 -05:00
|
|
|
bke::AttrDomain domain = bke::AttrDomain::Point;
|
2022-10-25 10:43:47 +02:00
|
|
|
if (!drw_custom_data_match_attribute(&pointcloud->pdata, name, &layer_index, &type)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
drw_attributes_add_request(&attrs_needed, name, type, layer_index, domain);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (!drw_attributes_overlap(&cache->eval_cache.attr_used, &attrs_needed)) {
|
2022-10-25 10:43:47 +02:00
|
|
|
/* Some new attributes have been added, free all and start over. */
|
|
|
|
|
for (const int i : IndexRange(GPU_MAX_ATTR)) {
|
2022-11-03 19:34:50 +01:00
|
|
|
GPU_VERTBUF_DISCARD_SAFE(cache->eval_cache.attributes_buf[i]);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
drw_attributes_merge(&cache->eval_cache.attr_used, &attrs_needed, cache->render_mutex);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
drw_attributes_merge(&cache->eval_cache.attr_used_over_time, &attrs_needed, cache->render_mutex);
|
2022-10-25 10:43:47 +02:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
DRW_batch_request(&cache->eval_cache.surface_per_mat[0]);
|
|
|
|
|
return cache->eval_cache.surface_per_mat;
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUBatch *pointcloud_surface_get(PointCloud *pointcloud)
|
|
|
|
|
{
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(*pointcloud);
|
2022-11-03 19:34:50 +01:00
|
|
|
return DRW_batch_request(&cache->eval_cache.surface);
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name API
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
GPUBatch *DRW_pointcloud_batch_cache_get_dots(Object *ob)
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
{
|
|
|
|
|
PointCloud &pointcloud = *static_cast<PointCloud *>(ob->data);
|
|
|
|
|
PointCloudBatchCache *cache = pointcloud_batch_cache_get(pointcloud);
|
2022-11-03 19:34:50 +01:00
|
|
|
return DRW_batch_request(&cache->eval_cache.dots);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
2023-07-14 17:23:29 +02:00
|
|
|
GPUVertBuf *DRW_pointcloud_position_and_radius_buffer_get(Object *ob)
|
|
|
|
|
{
|
|
|
|
|
PointCloud &pointcloud = *static_cast<PointCloud *>(ob->data);
|
|
|
|
|
return pointcloud_position_and_radius_get(&pointcloud);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
GPUVertBuf **DRW_pointcloud_evaluated_attribute(PointCloud *pointcloud, const char *name)
|
|
|
|
|
{
|
|
|
|
|
PointCloudBatchCache &cache = *pointcloud_batch_cache_get(*pointcloud);
|
|
|
|
|
|
|
|
|
|
int layer_index;
|
|
|
|
|
eCustomDataType type;
|
2023-12-20 13:13:16 -05:00
|
|
|
bke::AttrDomain domain = bke::AttrDomain::Point;
|
2022-10-25 10:43:47 +02:00
|
|
|
if (drw_custom_data_match_attribute(&pointcloud->pdata, name, &layer_index, &type)) {
|
|
|
|
|
DRW_Attributes attributes{};
|
|
|
|
|
drw_attributes_add_request(&attributes, name, type, layer_index, domain);
|
2022-11-03 19:34:50 +01:00
|
|
|
drw_attributes_merge(&cache.eval_cache.attr_used, &attributes, cache.render_mutex);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
int request_i = -1;
|
2022-11-03 19:34:50 +01:00
|
|
|
for (const int i : IndexRange(cache.eval_cache.attr_used.num_requests)) {
|
|
|
|
|
if (STREQ(cache.eval_cache.attr_used.requests[i].attribute_name, name)) {
|
2022-10-25 10:43:47 +02:00
|
|
|
request_i = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (request_i == -1) {
|
|
|
|
|
return nullptr;
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
return &cache.eval_cache.attributes_buf[request_i];
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
|
2023-11-30 19:54:06 -05:00
|
|
|
int DRW_pointcloud_material_count_get(const PointCloud *pointcloud)
|
2022-10-25 10:43:47 +02:00
|
|
|
{
|
|
|
|
|
return max_ii(1, pointcloud->totcol);
|
Geometry Nodes: viewport preview
This adds support for showing geometry passed to the Viewer in the 3d
viewport (instead of just in the spreadsheet). The "viewer geometry"
bypasses the group output. So it is not necessary to change the final
output of the node group to be able to see the intermediate geometry.
**Activation and deactivation of a viewer node**
* A viewer node is activated by clicking on it.
* Ctrl+shift+click on any node/socket connects it to the viewer and
makes it active.
* Ctrl+shift+click in empty space deactivates the active viewer.
* When the active viewer is not visible anymore (e.g. another object
is selected, or the current node group is exit), it is deactivated.
* Clicking on the icon in the header of the Viewer node toggles whether
its active or not.
**Pinning**
* The spreadsheet still allows pinning the active viewer as before.
When pinned, the spreadsheet still references the viewer node even
when it becomes inactive.
* The viewport does not support pinning at the moment. It always shows
the active viewer.
**Attribute**
* When a field is linked to the second input of the viewer node it is
displayed as an overlay in the viewport.
* When possible the correct domain for the attribute is determined
automatically. This does not work in all cases. It falls back to the
face corner domain on meshes and the point domain on curves. When
necessary, the domain can be picked manually.
* The spreadsheet now only shows the "Viewer" column for the domain
that is selected in the Viewer node.
* Instance attributes are visualized as a constant color per instance.
**Viewport Options**
* The attribute overlay opacity can be controlled with the "Viewer Node"
setting in the overlays popover.
* A viewport can be configured not to show intermediate viewer-geometry
by disabling the "Viewer Node" option in the "View" menu.
**Implementation Details**
* The "spreadsheet context path" was generalized to a "viewer path" that
is used in more places now.
* The viewer node itself determines the attribute domain, evaluates the
field and stores the result in a `.viewer` attribute.
* A new "viewer attribute' overlay displays the data from the `.viewer`
attribute.
* The ground truth for the active viewer node is stored in the workspace
now. Node editors, spreadsheets and viewports retrieve the active
viewer from there unless they are pinned.
* The depsgraph object iterator has a new "viewer path" setting. When set,
the viewed geometry of the corresponding object is part of the iterator
instead of the final evaluated geometry.
* To support the instance attribute overlay `DupliObject` was extended
to contain the information necessary for drawing the overlay.
* The ctrl+shift+click operator has been refactored so that it can make
existing links to viewers active again.
* The auto-domain-detection in the Viewer node works by checking the
"preferred domain" for every field input. If there is not exactly one
preferred domain, the fallback is used.
Known limitations:
* Loose edges of meshes don't have the attribute overlay. This could be
added separately if necessary.
* Some attributes are hard to visualize as a color directly. For example,
the values might have to be normalized or some should be drawn as arrays.
For now, we encourage users to build node groups that generate appropriate
viewer-geometry. We might include some of that functionality in future versions.
Support for displaying attribute values as text in the viewport is planned as well.
* There seems to be an issue with the attribute overlay for pointclouds on
nvidia gpus, to be investigated.
Differential Revision: https://developer.blender.org/D15954
2022-09-28 17:54:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-25 10:43:47 +02:00
|
|
|
void DRW_pointcloud_batch_cache_create_requested(Object *ob)
|
2022-08-09 11:10:44 -05:00
|
|
|
{
|
2022-10-25 10:43:47 +02:00
|
|
|
PointCloud *pointcloud = static_cast<PointCloud *>(ob->data);
|
|
|
|
|
PointCloudBatchCache &cache = *pointcloud_batch_cache_get(*pointcloud);
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (DRW_batch_requested(cache.eval_cache.dots, GPU_PRIM_POINTS)) {
|
|
|
|
|
DRW_vbo_request(cache.eval_cache.dots, &cache.eval_cache.pos_rad);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (DRW_batch_requested(cache.eval_cache.surface, GPU_PRIM_TRIS)) {
|
|
|
|
|
DRW_ibo_request(cache.eval_cache.surface, &cache.eval_cache.geom_indices);
|
|
|
|
|
DRW_vbo_request(cache.eval_cache.surface, &cache.eval_cache.pos_rad);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
for (int i = 0; i < cache.eval_cache.mat_len; i++) {
|
|
|
|
|
if (DRW_batch_requested(cache.eval_cache.surface_per_mat[i], GPU_PRIM_TRIS)) {
|
2022-10-25 10:43:47 +02:00
|
|
|
/* TODO(fclem): Per material ranges. */
|
2022-11-03 19:34:50 +01:00
|
|
|
DRW_ibo_request(cache.eval_cache.surface_per_mat[i], &cache.eval_cache.geom_indices);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
2022-11-03 19:34:50 +01:00
|
|
|
for (int j = 0; j < cache.eval_cache.attr_used.num_requests; j++) {
|
|
|
|
|
DRW_vbo_request(nullptr, &cache.eval_cache.attributes_buf[j]);
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (DRW_vbo_requested(cache.eval_cache.attributes_buf[j])) {
|
|
|
|
|
pointcloud_extract_attribute(*pointcloud, cache, cache.eval_cache.attr_used.requests[j], j);
|
2022-10-25 10:43:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (DRW_ibo_requested(cache.eval_cache.geom_indices)) {
|
2022-10-25 10:43:47 +02:00
|
|
|
pointcloud_extract_indices(*pointcloud, cache);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 19:34:50 +01:00
|
|
|
if (DRW_vbo_requested(cache.eval_cache.pos_rad)) {
|
2022-10-25 10:43:47 +02:00
|
|
|
pointcloud_extract_position_and_radius(*pointcloud, cache);
|
|
|
|
|
}
|
2022-08-09 11:10:44 -05:00
|
|
|
}
|
2022-10-25 10:43:47 +02:00
|
|
|
|
|
|
|
|
/** \} */
|
2024-01-05 12:20:30 -05:00
|
|
|
|
|
|
|
|
} // namespace blender::draw
|