Page MenuHome

Geometry Nodes: Generalized Compare Node
ClosedPublic

Authored by Johnny Matthews (guitargeek) on Nov 16 2021, 12:02 AM.

Details

Summary

Replace the float compare node with a generalized compare node. The node allows for the comparison of float, int, string, color, and vector.

The datatypes support the following operators:
Float, Int: <, >, <=, >=, ==, !=
String: ==, !=
Color: ==, !=, lighter, darker (using rgb_to_grayscale value as the brightness value)

Vector Supports 5 comparison modes for: ==, !=, <, >, <=, >=

  • Average: The average of the components of the vectors are compared.
  • Dot Product: The dot product of the vectors are compared.
  • Direction: The angle between the vectors is compared to an angle
  • Element-wise: The individual components of the vectors are compared.
  • Length: The lengths of the vectors are compared.

T92729

Diff Detail

Repository
rB Blender
Branch
general_compare (branched from master)
Build Status
Buildable 18671
Build 18671: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
  • Finish adding functions for string and color
  • formatting
  • Menus now update correctly
  • Merge branch 'master' into general_compare
  • Versioning WIP - I will need help.
Johnny Matthews (guitargeek) retitled this revision from Geometry Nodes: Generalized Compare Node - WIP to Geometry Nodes: Generalized Compare Node.Nov 16 2021, 5:35 PM
Johnny Matthews (guitargeek) edited the summary of this revision. (Show Details)
  • cleanup
  • Re-add label function
Hans Goudey (HooglyBoogly) requested changes to this revision.Nov 16 2021, 9:19 PM
  • Generally this is working well for me!
  • I think epsilon should always come last, even in the dot product mode.
  • I'm getting some unexpected behavior in the dot product equal mode:

  • Switching from vector to color can give an invalid "operation" enum. The enum's update method would have to automatically change the enum when switching to color.

As for code prettiness, I just investigated templating the type and operation, at least for the basic comparisons, but I didn't get anywhere yet.
IMO templating only really feels worth it if both the type and the operation could be templated.

source/blender/nodes/function/nodes/node_fn_compare.cc
164

For directions, I think angle_v3v3 is simpler here, since the dot product doesn't give you the angle directly.

297โ€“302

I think rgb_to_grayscale would be right here

405
/home/hans/Blender-Git/blender/source/blender/nodes/function/nodes/node_fn_compare.cc:379:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
  379 |           switch (data->mode) {
      |           ^~~~~~

I think there should be a break at the end of the subcases.

This revision now requires changes to proceed.Nov 16 2021, 9:19 PM
Johnny Matthews (guitargeek) marked 3 inline comments as done.

Several Fixes:

  • Fix order of extra inputs vs function signatures
  • Missing breaks
  • Better evals for color and vector direction
  • Fix operation to valid type when switching to color

This looks pretty close now! Though there is a merge conflict with master.

Initially I liked the idea of a dot product mode, but now I'm finding it a bit less intuitive than I expected. Maybe I just need to get used to it, not sure. What do you think about it? Generally I like the idea of the vector comparison nodes, I think they will be useful.

When I played around with the code a bit, I didn't find a great way to template the operations and the types. Could be that it's a difficult problem, or it could just be that I didn't understand it well enough. Maybe @Jacques Lucke (JacquesLucke) has better ideas there.

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

This one can be defined inside of def_compare, since it isn't used elsewhere.

source/blender/nodes/function/nodes/node_fn_compare.cc
81โ€“83

Suggest snake_case naming, maybe even just comp, angle, and epsilon

Initially I liked the idea of a dot product mode, but now I'm finding it a bit less intuitive than I expected. Maybe I just need to get used to it, not sure. What do you think about it? Generally I like the idea of the vector comparison nodes, I think they will be useful.

I don't think it hurts to leave it in. I guess angle comparison does the same thing but on a scale of 0 to 180 rather than -1 to 1. Your call.

Johnny Matthews (guitargeek) marked 2 inline comments as done.
  • minor cleanup
  • Merge branch 'master' into general_compare
  • Fix nodeSetSocketAvailability
  • Merge branch 'master' into general_compare
source/blender/nodes/function/nodes/node_fn_compare.cc
78

This should be done in an update function in rna.

130โ€“131

Would it make sense to move the function definitions into the switch statement below? Then every function would be in its own little scope and you could just name it fn.
Furthermore, you wouldn't need comments like /* Float Functions */ because this structure would be provided by the switch statement.

274

add some utility method to compute the average, this is repeated a lot here

292

Comment style.

source/blender/nodes/function/nodes/node_fn_compare.cc
130โ€“131

I like this idea too, seems the code will self-document a little more this way.

Johnny Matthews (guitargeek) marked 4 inline comments as done.
  • Merge branch 'master' into general_compare
  • Add file namespace
  • Move functions further down
source/blender/nodes/function/nodes/node_fn_compare.cc
78

Not sure how I should go about that.

source/blender/nodes/function/nodes/node_fn_compare.cc
78

For example, rna_GeometryNodeAttributeRandomize_data_type_update does something similar.

  • Merge branch 'master' into general_compare
Johnny Matthews (guitargeek) marked 2 inline comments as done.
  • Move type change default to rna
source/blender/nodes/function/nodes/node_fn_compare.cc
78

Awesome, thanks!

Hans Goudey (HooglyBoogly) requested changes to this revision.Nov 29 2021, 5:19 PM

The code looks okay to me now. I think I won't have any comments after this.

source/blender/makesdna/DNA_node_types.h
1611โ€“1614

Add comments for the types of the other enums.

1903

Maybe this comment should be removed?

source/blender/nodes/function/nodes/node_fn_compare.cc
52

Maybe a default of 0.9f makes more sense? Since usually you are comparing to see if the dot products are equal-ish.

Also, maybe the name "Threshold" would make more sense, since the dot product has to be higher than that value.

53

I think a default of 5 degrees makes a bit more sense.

86

Hmm, I don't think casting from CustomDataType to eNodeSocketDatatype is correct.

Ah, it seems that the comment in NodeFunctionCompare is incorrect, it should say eNodeSocketDatatype

143

Unnecessary newline. There are some below too.

This revision now requires changes to proceed.Nov 29 2021, 5:19 PM
Johnny Matthews (guitargeek) marked 6 inline comments as done.
  • Final Cleanup
Jacques Lucke (JacquesLucke) requested changes to this revision.Nov 30 2021, 1:36 PM

Looks mostly good now, I'm just not sure about the string comparison. There are so many ways to order strings, that it seems wrong to just use the default behavior of comparing std::string without further consideration. I'd be fine with keeping the equal and not-equal check for strings, but the other once I'd remove for now. Maybe we need more options for those.

/home/jacques/blender-git/blender/source/blender/makesrna/intern/rna_nodetree.c: In function โ€˜compare_other_operation_supportedโ€™:
/home/jacques/blender-git/blender/source/blender/makesrna/intern/rna_nodetree.c:2122:71: warning: unused parameter โ€˜itemโ€™ [-Wunused-parameter]
 2122 | static bool compare_other_operation_supported(const EnumPropertyItem *item)
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
source/blender/makesdna/DNA_node_types.h
411โ€“412

Various unrelated changes.

This revision now requires changes to proceed.Nov 30 2021, 1:36 PM
Johnny Matthews (guitargeek) marked an inline comment as done.
  • formatting
  • cleanup
  • Merge branch 'master' into general_compare
  • Remove extra functions for string
Hans Goudey (HooglyBoogly) added inline comments.
source/blender/blenloader/intern/versioning_300.c
2175

Add a comment above this block: /* Convert float compare into a more general compare node. */

source/blender/nodes/function/nodes/node_fn_compare.cc
52
This revision is now accepted and ready to land.Dec 1 2021, 3:41 PM
This revision was automatically updated to reflect the committed changes.
Johnny Matthews (guitargeek) marked 2 inline comments as done.