WIP: Volume grid attribute support in geometry nodes #110044

Closed
Lukas Tönne wants to merge 130 commits from LukasTonne/blender:geometry-nodes-flip into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Adds attributes to the VolumeComponent in geometry sets. Each grid is presented as an attribute, with the condition that all grids in the VolumeGridVector must share the same transform, topology, and active voxel set.

A specialized VArray implementation is added for accessing values stored in a grid, and associated built-in values such as voxel coordinates/positions.
image

A number of dummy nodes have been added as well. For the most part these are "aspirational" and not yet implemented, but they provide a test bed and motivation for features. The set of nodes is roughly what would be required for a basic FLIP/PIC fluid solver, on top of attribute support.image

Adds attributes to the `VolumeComponent` in geometry sets. Each grid is presented as an attribute, with the condition that all grids in the `VolumeGridVector` must share the same transform, topology, and active voxel set. A specialized `VArray` implementation is added for accessing values stored in a grid, and associated built-in values such as voxel coordinates/positions. ![image](/attachments/a39a92c9-3dff-4cf0-a1dd-34f4620a90e0) A number of dummy nodes have been added as well. For the most part these are "aspirational" and not yet implemented, but they provide a test bed and motivation for features. The set of nodes is roughly what would be required for a basic FLIP/PIC fluid solver, on top of attribute support.![image](/attachments/71190c90-dbd6-4a92-b0af-c5b9ef35178b)
Lukas Tönne added 17 commits 2023-07-13 08:43:14 +02:00
Lukas Tönne added 1 commit 2023-07-13 09:31:54 +02:00
Lukas Tönne added 1 commit 2023-07-13 10:39:29 +02:00
Iliya Katushenock added the
Interest
Geometry Nodes
label 2023-07-13 10:53:52 +02:00
Iliya Katushenock added this to the Nodes & Physics project 2023-07-13 10:53:57 +02:00
Member

I think we should have some design discussions about this, because there are points where it diverges from #103248 in some fairly fundamental ways. I won't write that all here though, since it should probably happen elsewhere.

I think we should have some design discussions about this, because there are points where it diverges from #103248 in some fairly fundamental ways. I won't write that all here though, since it should probably happen elsewhere.
Author
Member

there are points where it diverges from #103248 in some fairly fundamental ways

If you are referring to the "Grid Value" and "Set Grid Value" nodes in the screenshot: Those are already outdated again. I was playing around with the idea of a single grid per volume, but went back to the "grids are attributes" concept from the #103248 design (e.g. grid lookup by attribute id). I wanted to update the screenshots but then ran into #110052 on my work machine. Besides that, i'm playing fast and loose with design here, i just want to get something working. It's more about learning how to access OpenVDB grids and integrate with the rest of GN.

> there are points where it diverges from #103248 in some fairly fundamental ways If you are referring to the "Grid Value" and "Set Grid Value" nodes in the screenshot: Those are already outdated again. I was playing around with the idea of a single grid per volume, but went back to the "grids are attributes" concept from the #103248 design (e.g. [grid lookup by attribute id](https://projects.blender.org/blender/blender/src/commit/0ae4ac4b64ea9235da11a0b9da07c7d282dce33a/source/blender/blenkernel/BKE_volume_attribute.hh#L228)). I wanted to update the screenshots but then ran into #110052 on my work machine. Besides that, i'm playing fast and loose with design here, i just want to get _something_ working. It's more about learning how to access OpenVDB grids and integrate with the rest of GN.
Author
Member

Had some discussion with Hans about how grids with different topology might work together as attributes. Grids don't necessarily have to have the same active voxel layout to work together, sampling grids is fast. If transforms are the same, which is easy to ensure, grid access should be well optimized by OpenVDB.

The difficulty is that domain size (number of active voxels) is not well defined when combining multiple grids. One possibility is to define domain size of the entire Volume as the maximum number of active voxels among all its grids. OpenVDB will use the background value when sampling at a coordinate that is not active on a grid. That leaves the question of what get(int64_t index) means, if index does not map to a consistent active voxel for different grids. The recommendation is to use (i,j,k) coordinates for openvdb grid sampling, but VArrays work with a 1D index space.

Another possibility i've been considering is to move up one conceptual layer and define a dedicated Field type for voxels instead of just a VArray. We'd probably need to specialize the FieldEvaluator, which could switch to grid evaluation based on the VolumeFieldContext.

Had some discussion with Hans about how grids with different topology might work together as attributes. Grids don't necessarily have to have the same active voxel layout to work together, sampling grids is fast. If transforms are the same, which is easy to ensure, grid access should be well optimized by OpenVDB. The difficulty is that domain size (number of active voxels) is not well defined when combining multiple grids. One possibility is to define domain size of the entire Volume as the maximum number of active voxels among all its grids. OpenVDB will use the background value when sampling at a coordinate that is not active on a grid. That leaves the question of what `get(int64_t index)` means, if `index` does not map to a consistent active voxel for different grids. The recommendation is to use (i,j,k) coordinates for openvdb grid sampling, but `VArrays` work with a 1D index space. Another possibility i've been considering is to move up one conceptual layer and define a dedicated `Field` type for voxels instead of just a `VArray`. We'd probably need to specialize the FieldEvaluator, which could switch to grid evaluation based on the `VolumeFieldContext`.
Member

The difficulty is that domain size (number of active voxels) is not well defined when combining multiple grids

I guess it's mostly necessary to know the domain size when creating the virtual array? That's essentially the problem with flattening things out I guess. I don't think we can really rely on having a meaningful domain size value for the whole volume data-block. That might be inconvenient with some attribute code that assumes this, but I think there's not much way around that.

Another possibility i've been considering is to move up one conceptual layer and define a dedicated Field type for voxels instead of just a VArray. We'd probably need to specialize the FieldEvaluator, which could switch to grid evaluation based on the VolumeFieldContext.

I think this makes a lot of sense!

This is also how I imagined evaluating an arbitrary field to create a grid in the capture and store named attribute nodes-- the values would be sampled on the topology of an existing grid that's part of the field context. If the field refers to a volume grid directly though, that's an important optimization that will probably be essential for simple cases like passing a grid to the sample volume node.

Going a bit further, I'd imagine this allows the divergence and gradient nodes to be field input nodes that don't require a volume input.

EDIT: we may still want to have a virtual array implementation for grids though, to simplify displaying values in the spreadsheet.

> The difficulty is that domain size (number of active voxels) is not well defined when combining multiple grids I guess it's mostly necessary to know the domain size when creating the virtual array? That's essentially the problem with flattening things out I guess. I don't think we can really rely on having a meaningful domain size value for the whole volume data-block. That might be inconvenient with some attribute code that assumes this, but I think there's not much way around that. > Another possibility i've been considering is to move up one conceptual layer and define a dedicated `Field` type for voxels instead of just a `VArray`. We'd probably need to specialize the FieldEvaluator, which could switch to grid evaluation based on the `VolumeFieldContext`. I think this makes a lot of sense! This is also how I imagined evaluating an arbitrary field to create a grid in the capture and store named attribute nodes-- the values would be sampled on the topology of an existing grid that's part of the field context. If the field refers to a volume grid directly though, that's an important optimization that will probably be essential for simple cases like passing a grid to the sample volume node. Going a bit further, I'd imagine this allows the divergence and gradient nodes to be field input nodes that don't require a volume input. EDIT: we may still want to have a virtual array implementation for grids though, to simplify displaying values in the spreadsheet.
Member

Also, I think for volumes the implicit position attribute you have here doesn't quite work, since it relies on the matching topology and "domain sizes".

Also, I think for volumes the implicit position attribute you have here doesn't quite work, since it relies on the matching topology and "domain sizes".
Lukas Tönne added 1 commit 2023-07-14 09:22:45 +02:00
Lukas Tönne added 1 commit 2023-07-15 02:19:27 +02:00
Lukas Tönne added 1 commit 2023-07-16 19:16:36 +02:00
Lukas Tönne added 1 commit 2023-07-16 19:50:34 +02:00
Lukas Tönne added 1 commit 2023-07-16 21:44:47 +02:00
Lukas Tönne added 1 commit 2023-07-17 00:11:45 +02:00
Lukas Tönne added 1 commit 2023-07-17 09:30:58 +02:00
Lukas Tönne added 1 commit 2023-07-18 01:14:29 +02:00
Lukas Tönne added 1 commit 2023-07-18 22:07:58 +02:00
831f492458 Renamed VolumeGrid and VolumeMask to avoid conflicts with BKE structs.
The new Grid and GridMask classes will act similar to VArrays during
field evaluation. The VolumeGrid struct is equivalent to
CustomDataLayers, it provides the attribute inputs for the field graph.
Lukas Tönne added 1 commit 2023-07-19 10:22:38 +02:00
Lukas Tönne added 2 commits 2023-07-19 18:32:11 +02:00
Lukas Tönne added 1 commit 2023-07-22 12:45:34 +02:00
Lukas Tönne added 2 commits 2023-07-22 17:08:54 +02:00
Lukas Tönne added 2 commits 2023-07-23 11:45:10 +02:00
Lukas Tönne added 1 commit 2023-07-23 16:14:03 +02:00
Lukas Tönne added 1 commit 2023-07-24 09:01:19 +02:00
Lukas Tönne added 1 commit 2023-07-24 14:19:55 +02:00
Lukas Tönne added 1 commit 2023-07-24 14:29:30 +02:00
Lukas Tönne added 1 commit 2023-07-24 15:18:14 +02:00
Lukas Tönne added 1 commit 2023-07-26 09:01:54 +02:00
Lukas Tönne added 2 commits 2023-07-26 20:14:51 +02:00
Lukas Tönne added 1 commit 2023-07-30 10:19:13 +02:00
Lukas Tönne added 1 commit 2023-08-05 12:45:07 +02:00
ce26803d3a Build improvement: Use forward declaration for OpenVDB types.
OpenVDB is heavily templated and can dramatically increase build times
and memory requirement, if OpenVDB headers are included in too many
places. The solution is to avoid including openvdb.h in other header
files and only do this in .cc source files where the implementation is
really needed. The BLI_volume.hh header now only forward-declares
the OpenVDB types.
Lukas Tönne added 2 commits 2023-08-05 13:34:09 +02:00
Lukas Tönne added 3 commits 2023-08-05 14:43:32 +02:00
Lukas Tönne added 1 commit 2023-08-05 16:19:49 +02:00
Lukas Tönne added 1 commit 2023-08-05 17:37:57 +02:00
Lukas Tönne added 1 commit 2023-08-06 13:52:05 +02:00
Lukas Tönne added 1 commit 2023-08-06 13:58:07 +02:00
Lukas Tönne added 1 commit 2023-08-06 16:35:42 +02:00
Lukas Tönne added 1 commit 2023-08-07 00:34:01 +02:00
Lukas Tönne added 1 commit 2023-08-07 09:07:38 +02:00
Lukas Tönne added 1 commit 2023-08-07 09:19:20 +02:00
Lukas Tönne added 1 commit 2023-08-07 09:24:35 +02:00
0ba80a7b23 Removed check for exact destination voxel count match in VolumeFieldEvaluator.
This assert makes sense for VArrays which are pre-allocated, but grids
change size dynamically and the destination can be just an empty grid.
Lukas Tönne added 1 commit 2023-08-07 10:30:49 +02:00
Lukas Tönne added 1 commit 2023-08-07 10:42:30 +02:00
Lukas Tönne added 1 commit 2023-08-07 14:05:44 +02:00
Lukas Tönne added 1 commit 2023-08-07 16:31:01 +02:00
d1c3cb152b Use a callback to avoid nesting static type dispatches.
Static type dispatchers like `field_to_static_type` and
`grid_to_static_type` generate a lot of code, leading to combinatorial
explosion when they are nested. This can easily overwhelm the linker
and break the build, in addition to making it slow.
Lukas Tönne added 1 commit 2023-08-07 16:42:59 +02:00
Lukas Tönne added 1 commit 2023-08-09 15:09:58 +02:00
Lukas Tönne added 1 commit 2023-08-10 08:00:10 +02:00
Lukas Tönne added 1 commit 2023-08-10 08:59:36 +02:00
b634aa6422 Make sure input fields are always valid when evaluating.
Moving a grid pointer to the resource scope invalidates the pointer,
have to use the result of scope.add to return the actual grid.
Lukas Tönne added 1 commit 2023-08-10 10:46:31 +02:00
Lukas Tönne added 4 commits 2023-08-13 14:45:59 +02:00
Lukas Tönne added 2 commits 2023-08-13 18:08:57 +02:00
Lukas Tönne added 1 commit 2023-08-14 09:44:44 +02:00
027f902488 Voxelize active nodes before evaluating the multifunction.
Grids can have active nodes with all-constant values, in which case
OpenVDB will optimize away leaf buffers. To be able to evaluate the
multifunction on each voxel we first need to voxelize the output grid.
Lukas Tönne added 1 commit 2023-08-14 10:17:00 +02:00
Lukas Tönne added 3 commits 2023-08-15 11:45:27 +02:00
Lukas Tönne added 1 commit 2023-08-17 08:53:51 +02:00
5aa82e52f7 Temp: Change grid types from custom blender value types to use OpenVDB default types again.
This makes it easier to load compatible grids from files and use
existing OpenVDB tools and algorithms. It requires some converter utils
to reinterpret vector types like `openvdb::Vec3f` as the equivalent
Blender vector types.
Lukas Tönne force-pushed geometry-nodes-flip from 9020dc99d2 to 3d99cd075d 2023-08-17 15:52:05 +02:00 Compare
Lukas Tönne added 1 commit 2023-08-17 17:35:32 +02:00
43d1589078 Need converter specialization for both MaskGrid and BoolGrid.
Bool grids also effectively use the same LeafBuffer type as MaskGrids,
which directly exposes the bit fields of the activation state (WordType,
unsigned long int).
Lukas Tönne force-pushed geometry-nodes-flip from d70d9ffa39 to 36fedfa64f 2023-08-17 18:32:49 +02:00 Compare
Lukas Tönne added 2 commits 2023-08-18 10:34:30 +02:00
Lukas Tönne force-pushed geometry-nodes-flip from 3a3532a0e4 to 67bd1671cf 2023-08-18 12:45:08 +02:00 Compare
Lukas Tönne added 1 commit 2023-08-18 13:57:38 +02:00
Lukas Tönne added 1 commit 2023-08-18 14:36:38 +02:00
Lukas Tönne added 1 commit 2023-08-18 14:41:29 +02:00
Lukas Tönne added 1 commit 2023-08-18 15:31:38 +02:00
360e70b974 Removed the GridMask class.
A MaskGrid can be represented simply as a volume::Grid<bool>.
Lukas Tönne added 2 commits 2023-08-21 09:25:52 +02:00
6aa68ee85b Added virtual grid classes to enable fields without implicit topology.
Example: voxel positions can be a virtual grid without actual voxel
values stored in a grid. As a virtual grid with a function
implementation they can be evaluated at any location without requiring
grid storage.
Lukas Tönne added 1 commit 2023-08-21 18:07:59 +02:00
Lukas Tönne added 2 commits 2023-08-27 18:52:28 +02:00
Lukas Tönne added 2 commits 2023-08-27 23:32:15 +02:00
Lukas Tönne added 2 commits 2023-08-28 16:44:57 +02:00
Lukas Tönne added 1 commit 2023-08-28 18:06:31 +02:00
e349de2841 Use the standard C++ allocator for grids to avoid incoherent free.
Grids are stored in shared_ptr and eventually freed using delete.
Lukas Tönne added 1 commit 2023-08-28 22:02:35 +02:00
Lukas Tönne added 1 commit 2023-08-29 09:12:50 +02:00
Lukas Tönne added 1 commit 2023-09-08 19:43:52 +02:00
Lukas Tönne added 1 commit 2023-09-08 22:10:11 +02:00
Lukas Tönne added 1 commit 2023-09-09 09:23:30 +02:00
Lukas Tönne added 1 commit 2023-09-09 10:01:28 +02:00
Lukas Tönne added 1 commit 2023-09-09 11:22:18 +02:00
23482e9583 Initialize buffer topology before evaluating input fields.
When evaluating input volume fields the output buffers are initialized
as empty grids. In order to have leaf node buffers to store values in
the output buffers needs to have the combined topology of all input
grids.
Lukas Tönne added 1 commit 2023-09-09 14:02:48 +02:00
Lukas Tönne added 1 commit 2023-09-09 19:00:25 +02:00
Lukas Tönne added 1 commit 2023-09-10 14:01:08 +02:00
bf7739fa7a Linker fix: Added a stub in makesrna for a missing reference.
It's unclear why makesrna needs this implementation in the first place
(maybe the source crawling preprocess adds this dependency somehow).
Linking to bf_blenlib does not solve the problem, the only thing that
seems to work is adding a stub in bf_rna itself.
Lukas Tönne added 1 commit 2023-09-10 14:09:11 +02:00
Lukas Tönne added 1 commit 2023-09-10 15:02:52 +02:00
Lukas Tönne added 1 commit 2023-09-10 15:41:45 +02:00
Lukas Tönne added 1 commit 2023-09-10 23:29:07 +02:00
Lukas Tönne added 1 commit 2023-09-11 10:35:30 +02:00
Lukas Tönne added 1 commit 2023-09-11 11:06:20 +02:00
Lukas Tönne added 1 commit 2023-09-12 09:30:44 +02:00
Lukas Tönne added 1 commit 2023-09-12 22:42:37 +02:00
Lukas Tönne added 1 commit 2023-09-13 08:10:50 +02:00
Lukas Tönne added 1 commit 2023-09-14 20:21:22 +02:00
Lukas Tönne added 1 commit 2023-09-15 12:01:07 +02:00
Lukas Tönne added 1 commit 2023-09-15 12:05:54 +02:00
Author
Member
@blender-bot
Lukas Tönne added 1 commit 2023-09-15 18:01:53 +02:00
Lukas Tönne added 1 commit 2023-09-16 10:26:17 +02:00
Lukas Tönne added 1 commit 2023-09-16 10:43:39 +02:00
Lukas Tönne added 1 commit 2023-09-16 23:37:27 +02:00
Lukas Tönne added 1 commit 2023-09-17 09:00:46 +02:00
Lukas Tönne added 1 commit 2023-09-17 09:01:20 +02:00
Member

Superseded by #116021

Superseded by #116021
Hans Goudey closed this pull request 2024-02-14 16:31:36 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110044
No description provided.