Page MenuHome

Geometry Nodes: Volume Cube node
ClosedPublic

Authored by Chris Clyne (lateasusual) on Jun 14 2022, 10:12 PM.
Tokens
"Love" token, awarded by damian."Love" token, awarded by juaogeneroso."Love" token, awarded by Bit."Burninate" token, awarded by Bariboy."Burninate" token, awarded by angelbpineda."Love" token, awarded by Baga."Love" token, awarded by D0ppelgaenger."Burninate" token, awarded by Francis_Jasmin."Love" token, awarded by GifCo."Love" token, awarded by Draise."100" token, awarded by dupoxy."Burninate" token, awarded by MasterNurmi."Burninate" token, awarded by baoyu."Love" token, awarded by blueprintrandom."Love" token, awarded by zNight."Love" token, awarded by amoose136."Love" token, awarded by gurpreetsingh."Love" token, awarded by cmzw."Love" token, awarded by Leul."Love" token, awarded by belich."Love" token, awarded by davidmcsween."Love" token, awarded by silex.

Details

Summary

This patch adds a Volume Cube primitive, with a field input to set the density at each grid voxel. This can be used to create procedural SDF-based meshes using the Volume To Mesh node:

Possible future improvements:

  • Output an anonymous grid instead of hardcoding the name "density". Also see T91668.
  • Support creating multiple grids at the same time (requires adding more sockets dynamically, we don't have that yet).
  • Possibly allow specifying whether the grid is an fog volume or SDF.
  • Support for grids with different data types (vector, int, ...).
  • Support a selection input which is possibly evaluated at a lower resolution, so that the main grid values don't have to be evaluated at all positions.
  • Support different resolution modes like in the Volume to Mesh node.

Diff Detail

Repository
rB Blender

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Jacques Lucke (JacquesLucke) requested changes to this revision.Jun 15 2022, 1:21 PM

Nice patch, thanks for working on that.
Some notes:

  • Please use clang-format and our comment style (/* Full sentence. */).
  • Use a new FieldContext instead of using a PointCloud. This is actually the first time we use a field context that is not based on a geometry, but that's fine or even good. I implemented it here for reference: P3009.
  • Generating the positions and copying it over to the volume should be parallelized. In the future this could potentially be improved by writing to the volume grid directly and by generating the positions lazily in batches.
  • This is also a bit related to T91668. So the node might need some versioning once that is implemented, which is fine.
source/blender/nodes/geometry/nodes/node_geo_field_to_volume.cc
56 ↗(On Diff #52530)

Not that I know of.

59 ↗(On Diff #52530)

Make sure to protect against division by zero (outside of this function).

This revision now requires changes to proceed.Jun 15 2022, 1:21 PM
source/blender/nodes/geometry/nodes/node_geo_field_to_volume.cc
1 ↗(On Diff #52530)

Use the new license header: /* SPDX-License-Identifier: GPL-2.0-or-later */

Looks to me like it needs more protection against WITH_OPENVDB not being true?

Chris Clyne (lateasusual) edited the summary of this revision. (Show Details)
  • Added #ifdef WITH_OPENVDB checks
  • Use Grid3DFieldContext and parallelise it
  • Bounding volume > 0 check (no divide by zero)
  • Rename to "Volume Grid" as per meeting notes
  • Remove min clamp of Volume To Mesh threshold to allow interior SDF distances to work
  • clang-format

Copying the field evaluation results to the OpenVDB grid isn't parallelised, the grid->getAccessor() isn't thread safe and I don't know enough about OpenVDB to know an alternative.

I suspect this is a little overkill. Your position will be virtually used, which doesn't make me feel like allocate is necessary.

*edit:

VArray<float3>::ForFunc([resolution_, bounds_min_, bounds_max_](const int index){...});
source/blender/nodes/geometry/nodes/node_geo_volume_grid.cc
58–74 ↗(On Diff #52548)

Isn't it possible to use VArrya<int>::ForFunc and not do array allocation by position?

This comment was removed by Iliya Katueshenock (Moder).
source/blender/nodes/geometry/nodes/node_geo_volume_grid.cc
91 ↗(On Diff #52548)

It seems to me that the protection should change the logic of work

Jacques Lucke (JacquesLucke) requested changes to this revision.Jun 16 2022, 11:58 AM

Copying the field evaluation results to the OpenVDB grid isn't parallelised, the grid->getAccessor() isn't thread safe and I don't know enough about OpenVDB to know an alternative.

I implemented that here: P3011.

source/blender/nodes/geometry/nodes/node_geo_volume_grid.cc
39 ↗(On Diff #52548)

This comment is unnecessary.

58–74 ↗(On Diff #52548)

Would in theory be possible, but might make performance worse right now. Think this explicit array construction is fine for now (also given that we know that all values will be needed). I'll look into generating the points in batches (and never allocating the big array) separately.

77 ↗(On Diff #52548)

Move this to the top of the file (as in other nodes).

79 ↗(On Diff #52548)

Shouldn't be an implicit field.

96 ↗(On Diff #52548)

could use int3 to store resolution.

128 ↗(On Diff #52548)

It's ok when you just assume eval_idx to be 0 here, as we do in other places.

143 ↗(On Diff #52548)

const

This revision now requires changes to proceed.Jun 16 2022, 11:58 AM
Jacques Lucke (JacquesLucke) retitled this revision from Geometry Nodes: Field to Mesh node to Geometry Nodes: Volume Grid node.Jun 16 2022, 12:02 PM
Jacques Lucke (JacquesLucke) edited the summary of this revision. (Show Details)
Chris Clyne (lateasusual) marked 9 inline comments as done.
  • use openvdb::tools::Dense to copy results
  • address other feedback
source/blender/nodes/geometry/nodes/node_geo_volume_grid.cc
120–122 ↗(On Diff #52578)

A small improvement would be to give Grid3DFieldContext a points_num() method, which could be reused above where the positions array is built.

Chris Clyne (lateasusual) marked an inline comment as done.
  • Add points_num() to Grid3DFieldContext
This revision is now accepted and ready to land.Jun 16 2022, 3:53 PM
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_volume_grid.cc
40 ↗(On Diff #52579)

Theoretically this should be a function in BLI_math_base.hh, or it could have a more specialized name. But just a thought, not a strong opinion.

Hans Goudey (HooglyBoogly) requested changes to this revision.Jun 16 2022, 4:25 PM

We just talked in the geometry nodes chat, and Dalai talked to Brecht in person. The conclusion was that "Volume Cube" might make a bit more sense as a name.
"Cube" describes the shape of the evaluation domain, and it also describes the visual default output of the node, and the shape of the active voxels in the volume.

This revision now requires changes to proceed.Jun 16 2022, 4:25 PM
Chris Clyne (lateasusual) retitled this revision from Geometry Nodes: Volume Grid node to Geometry Nodes: Volume Cube node.
Chris Clyne (lateasusual) edited the summary of this revision. (Show Details)

Rename to Volume Cube

Missed a function when refactoring ("volume_grid" gets used too often elsewhere to just find/replace automatically lol)

This revision is now accepted and ready to land.Jun 16 2022, 4:45 PM
source/blender/nodes/NOD_geometry.h
56–57

Seems a bit out of place here? and missing geo?

(third time's the charm - volume_cube -> geo_volume_cube)

source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
43

missing newline

74

use this-> when calling methods

source/blender/nodes/geometry/nodes/node_geo_volume_cube.cc
77

Missing .

Chris Clyne (lateasusual) marked 3 inline comments as done.

Address comments in chat

Fix "Bounds Min/Max" -> "Min/Max" in params access

ordering in CMakeLists.txt, NOD_static_types.h

A couple fixes after some users testing the patch:

  • Fix that connecting to a VolumeToMesh node meshes the *outside* of the volume (as it was being treated as an SDF instead of like regular volumes. Now for SDF behaviour, i.e. negative values inside, users should multiply the density by -1). Fixed by setting the Background Value of the grid to be negative instead of positive. Fixes output face normals being flipped also.
  • Fix off-by-one error in grid scaling leading to changes in scale with resolution:

this fix also requires the resolution to be clamped to >1, as otherwise a plane is generated instead of a cube.

Went with Hans over the patch again, we did a few small changes:

  • Split up changes in Volume to Mesh node.
  • Add background value input.
  • Evaluate field into previously allocated array.