Page MenuHome

Geometry Nodes: Use read-only instances in point distribute node
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Mar 3 2021, 1:53 AM.

Details

Summary

This patch refactors the point distribute node to skip realizing
the instances created by the point distribute node, or the collection
and object info nodes. Realizing instances is not necessary here
because it will copy all the mesh data and and interpolate all
attributes from the instances.

In the WIP trees test file this patch improved the performance of the
node by about 14%. That's not very much, but I expect the gain is larger
for more complicated input instances with more attributes. Especially
attributes on different domains, where interpolation would be necessary
in the realize code.

The point distribution code unfortunately gets quite a bit more
complicated. Some further restructing might help in the future, but I
think this is a good first step.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Mar 3 2021, 1:53 AM
Hans Goudey (HooglyBoogly) created this revision.
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
114–117

Unfortunately even non-instances will still have to do this matrix multiplication. It could be templated to be skipped when the transform is a unit transform, but I would just be guessing, I haven't profiled to see if it's actually a bottleneck.

162

This function looks a little harder to parallelize now, I might have to think about restructuring this some.

Hans Goudey (HooglyBoogly) retitled this revision from Geometry Nodes: Use read-only instance in point distribute node to Geometry Nodes: Use read-only instances in point distribute node.Mar 3 2021, 2:26 AM

Generally looks fine. Still want to do a few more tests, but didn't find major issues.

source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
635

Did you want to call this geo_groups or something like that?

639

typo (note)

640

How about you just remove all the groups from the vector above, that don't have a mesh. Then you don't need to check for it everywhere.

648

Looks like it would be a good idea to extract this loop to a separate function.

source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
640

That's a good idea, I'll do that.

Hans Goudey (HooglyBoogly) marked 4 inline comments as done.
  • Rename some variables (_array to _all)
  • Remove some unessary index variables
  • Transform normals also
  • Generally simplify some code
  • Split up random and poisson disk methods more
  • Completely remove set groups with no mesh component
source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
187

Should this be offset + i?

351

We shouldn't assert that anymore. We might get issues where point clouds have different builtin attributes than mesh.

376

same here

434

Is this as_span() necessary?

456

Don't change the parentheses here, because it will trigger an asan overflow warning sometimes. The addition should be done on unsigned integers (which allow overflow).

474

Can use a const Map?

690

Can use uninitialized_fill_n.

Hans Goudey (HooglyBoogly) marked 6 inline comments as done.
  • Merge branch 'master' into geometry-nodes-point-distribute-read-only
  • Review updates, and fix poisson disk mode (pass vectors by reference)
source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
456

Oops, I didn't mean to change that. Good catch.

635

Oops, that's a typo of set_groups

I'd still like the see the "attribute default" (which is 0) vs "node default" (which is 1), but then this seems to work fine.

source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
633

I don't really think we should warn in such cases. There are probably valid cases where in some frames there will be a mesh and in others there is not.
However, that can be changed separately.

This revision is now accepted and ready to land.Mar 8 2021, 4:33 PM

I changed the default based on whether the attribute field is empty like you suggested.

source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc
633

Yes, I'm fine with removing this message, best to check if there are other places that have similar errors though.