Page MenuHome

Geometry Nodes: Upgrade Attribute Randomize node with operation
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Feb 1 2021, 6:46 AM.

Details

Summary

This commit rewrites the attribute randomize node to be more flexible
with attribute data types, and supports basic blending operations
similar to the vertex weight mix modifier's operations.

The data types are templated to make supporting new attribute data types
in the future simple. This required adding a few new methods to the
Color4f and float3 classes.

I tried templating the operations too, similar to how the attribute
vector math node works, but I didn't think the complexity increase was
worth it in that case.

I still have to get the difference operation working, it doesn't use the
absolute value yet, which is what I think it's meant to do.

Resolves T84970

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Feb 1 2021, 6:46 AM
Hans Goudey (HooglyBoogly) created this revision.
source/blender/blenkernel/BKE_attribute_math.hh
101 ↗(On Diff #33377)

Comment is at wrong place.

102 ↗(On Diff #33377)

The naming is a bit tricky here. random_value has different meanings for different type. The behavior is basically determined by the needs of the Random Attribute node and might not apply to different contexts. Therefore it might be better to leave these functions in node_geo_attribute_random.cc.

109 ↗(On Diff #33377)

That doesn't seem to make too much sense.. Not sure if the seed is randomized before already.

128 ↗(On Diff #33377)

Random colors shouldn't be generated like this. Usually you don't want transparency to be random.
Just remove it for now.

source/blender/blenlib/BLI_color.hh
64 ↗(On Diff #33377)

I'm not too fond of adding these methods to colors. Not sure..
Generally these are not operations one should do with colors.

It might be best to just not support colors in this node yet.

source/blender/blenlib/BLI_float3.hh
124 ↗(On Diff #33377)

This operation also isn't well defined, but I guess it's fine. There should be an assert that checks for division by zero.

source/blender/makesdna/DNA_node_types.h
1671

I'm not sure about the usefulness of the and and or modes. They basically set/unset approximately half of the elements that aren't already set/unset. I'd expect that usually when this behavior is needed, the user would want to have more control over the percentage. This should not be something the Random Attribute node is concerned about.

Do you have a use case for the difference and average mode?

1673

The xor mode does not seem to be very useful. In practice it should behave exactly the same as GEO_NODE_ATTRIBUTE_RANDOMIZE_REPLACE_CREATE, if I'm not mistaken.

source/blender/makesrna/intern/rna_nodetree.c
408

Interesting, this was my first ASAN crash at compile time :D
The {0, NULL, 0, NULL, NULL} entry is missing.

Hans Goudey (HooglyBoogly) marked 9 inline comments as done.
  • Remove color attribute support for now
  • Remove special boolean operations that didn't really make sense
  • Remove some of the operations that don't have an obvious use case and are more complex to implement
  • Simplify attribute noise functions
  • Move random value code back to the attribute math node
source/blender/blenlib/BLI_color.hh
64 ↗(On Diff #33377)

Alright, I removed them for now. Maybe the mixer in attribute_math is a step in the right direction, because this problem will come up again.

source/blender/blenlib/BLI_float3.hh
124 ↗(On Diff #33377)

Hmm, I can't assert here because it might actually be dividing by 0, oops... At this point I'm just going to remove the operations that require division from this patch. I don't know of a use case for them anyway.

Eventually we might want to add a attribute_math::safe_divide<T>

source/blender/makesrna/intern/rna_nodetree.c
408

Interesting, worked for me somehow! Thanks.

  • Fix return used instead of break
Jacques Lucke (JacquesLucke) added inline comments.
source/blender/makesdna/DNA_node_types.h
1119

one byte of padding should be enough

source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
104–147

What would make the code much shorter?

This revision is now accepted and ready to land.Feb 12 2021, 12:42 PM
source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
104–147

Agh, I forgot the word "doesn't"