Page MenuHome

Geometry Nodes: Boolean Attribute Type
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Dec 10 2020, 5:32 PM.

Details

Summary

This adds a boolean attribute and custom data type, to be used for the point
separate node (DXXXX). It also adds it as supported data types to the random
attribute and attribute fill nodes.

Though there are many more clever ways of storing a boolean attribute that make
more sense in certain situations-- sets, bitfields, and others, this patch keeps
it simple, saving those changes for when there is a proper use case for them.
In any case, we will still probably always want the idea of a boolean attribute.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Dec 10 2020, 5:32 PM
Hans Goudey (HooglyBoogly) created this revision.

If we do this as is, we should probably have a static assert somewhere that checks sizeof(bool) == 1. Not sure if there is a realistic change that any of the compilers we use, uses a different size, I hope not.

source/blender/nodes/intern/node_tree_multi_function.cc
212

I guess it would be good to have some kind of conversion from bool to float3?

Also, use a.length_squared() instead of a.length(). This can end up in hot loops.

Geometry Nodes: attribute_exists helper function

Just a simple helper function to check if an attribute exists in the component.

  • Remove "attribute_exists" change added by mistake (committed it to master)
  • Use length_squared, add conversion from bool to float3

@Jacques Lucke (JacquesLucke) I think the only thing actually required for this is that C and C++ use the same
size for bool? Which I think we can assume to be true. Such an assert might be useful just to
make sure we aren't using 4x the amount of memory I suppose. Though I do wonder how we'll handle
groups and boolean attributes in the future, if this makes sense as a first step.

Well, since these arrays are stored in .blend files, it is also important that different compilers on different platforms use the same size for booleans.
I'm not absolutely sure how to handle that right now.

Another option could be to make an int8 attribute instead and to just call it bool in the ui. That will probably result in other issues with CPPType though..

Maybe assuming sizeof(bool) == 1 is just fine in the context of blender...

Hi @Brecht Van Lommel (brecht), what do you think about this? The context is that there need to be a mask attribute to tell a "point separate" node which points or vertices to move to a different geometry.
It could be done with a regular int attribute, but it's nice to have the explicit boolean type here, and the idea is that it's a first step for the idea of selection attributes.

I don't fully understand the implications of this.

Is there automatic casting of attribute types? If the points separate node use a boolean attribute, does it work to set a float (or integer) attribute which will then be interpreted as a boolean? If you multiply a boolean with a float attribute, does the output automatically get promoted to float? Does randomizing a boolean attribute convert it to a float attribute?

Where does the boolean attribute come from, which node would it be created with? When thinking about points separate, that seems like something you might often do with a vertex group or texture. And in that case I guess you'd want to interpret the float as a probability of being true or false in practice, either as native feature of points distribute or another node before it.

For selection, we might want to support soft selections, which would be floats.

We've actually just recently settled on answers to most of these questions.

Attributes are implicitly converted when necessary, but the data type of an existing attribute won't be changed, whether it is a built in attribute or something created in the node tree. So the point separate node can read an attribute of any data type and it will be implicitly converted to boolean, but that isn't very flexible.

That's where the "Attribute Compare" node, T83057, becomes useful. It always outputs a boolean attribute. That node would use a vertex group attribute or an attribute sampled from a texture to create the mask. This patch also allows creation of boolean attributes with the random attribute node.

This revision is now accepted and ready to land.Dec 16 2020, 7:22 PM
This revision was automatically updated to reflect the committed changes.