# 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!

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!