I don't understand logic behind Geo Nodes, can you help in this example?

Hi!

So, since I have some background in programming, I am very confused with
the logic in Geo Nodes, and I would be very thankful if someone would explain it to me! :slight_smile:

Here is very simple setup, one default cube, and I’ve created two self-explanatory materials: red and blue. Blue material is applied on the cube using the “Set material” node.

Then, after the first “Set material”, I insert another one in which I pick red color this time,
which of course overrides the blue material from the previous node, as expected.

Now, if I want to introduce some logic, to apply that red color based on some choice,
I can use simple integer comparison of two integers. In this example, if 2 and 2 are
equal, red color will be applied to the box.
Important thing to notice is that the “Selection” in the “Set material” node is Boolean type.
That means that red color should either be applied to the whole box mesh, or not applied,
based on the input received in the “Selection”.

But!
When I use index, which in this case is representing the index of the faces of the cube,
and when face with the index of 2 is compared to 2, red color will be applied only to the
face with that index.

Why is that?
If “Compare” node sends only boolean result, then the result should be only true or false.
But, obviously, not only boolean value, but also the index value is passed.

So, what bothers me is that I don’t really understand the background of this process and therefore
I’m not sure how to best use it. It seems that “Set material” node doesn’t really apply material to the
whole mesh, but in the background it applies material on the index by index basis, and therefore if
we introduce some kind of index based logic such as in this case, we can reference only certain
indexes?

Thanks!

You described this totally correct. Do you see the round and diamond shaped input and output sockets?
The round socket means: it is a “so called” field value - so it is not just one value, but multiple - as programmer you would say: an array.
Whatever you plugin in the selection input, GN will take the “right” thing. So you cannot “read” the node tree like regular coding from top to down and left to right, but you have to go along where something is put in and walk back where it comes from. What do i mean by that? if you come from the input selection of your set material node, you just now, it is a selection field (multiple values), but you have no idea what kind of values. if you now go back and follow the connections, you will see “equal” which doesn’t help you, but if you go further, you find “index”. So this selection depends on the “default” index. If you would have plugged in another value (e.g. instance index), then this is your comparison value. Hope that makes a bit sense.

in your “special” case, the index will be compared with every face there is in the GN, so GN will iterate through the “array” (field) and decide for each “entity” (face/instance) which color to choose.

2 Likes

Correction… diamond = field, round = constant.

3 Likes

Yes… See the manual.

The relevant section is underlined below telling you that the field’s evaluation domain (i.e. context) is Faces:

Selection

Whether to change the material of each face. True values mean the material will be changed, false values mean it will remain the same.

3 Likes

Ok, thanks guys very much!
Yes, to think of “Selection” input as an Array makes much more sense to me!