9

I've created a Group node that acts as a geometry switch. Plug in a few different geometries, and the integer you give it determines which geometry actually comes out. It works fine with a Value input, but I want to give it a random value. Feeling clever, I assume this is what the Random Value node is for... however when I connect it the output wire turns red.

Looking to the Blender Manual, I tried to understand more about how the Random Value Node works. The ID input socket is perplexing me:

Random Value Node

Inputs

ID

An ID to drive the random number generator seed. By default, this input uses the same value as of the ID Node, which is the id attribute of the context geometry if it exists, and otherwise the index.

Okay... next stop the ID Node

ID Node

The ID node gives an integer value indicating the stable random identifier of each element on the point domain, which is stored in the id attribute.

The node to set this data is the Set ID Node node.

On to the Set ID Node then...

Set ID node

The Set ID node fills the id attribute on the input geometry. If the attribute does not exist yet, it will be created with a default value of zero. The ID is also created by the Distribute Points on Faces, and it is used in the Random Value Node and other nodes if it exists.

The input node for this data is the ID Node.

From all that, what I gather is that the Random Value Node has an ID socket that is for accepting a value that drives the random number generator seed, and the ID Node also deals with this ID, and the Set ID Node can set such a value, and this is used by the Random Number Value Node... so we are right back at the beginning.

None of this documentation really explains how to use these nodes with one another, and plugging both the ID Node and the Set ID Node into the Random Value Node's ID socket have made no difference in the output. It is still red.

The fundamental question:

How are these nodes all supposed to work with one another to produce a random integer/float/etc that can actually produce a valid value that works with other nodes?

Thanks!

Robert Gützkow
  • 25,622
  • 3
  • 47
  • 78
Mentalist
  • 19,092
  • 7
  • 94
  • 166

2 Answers2

8

if you use it like this you should get what you want:

enter image description here

The output now has the cirlce.

3.0 example:

enter image description here

Chris
  • 59,454
  • 6
  • 30
  • 84
  • Is it 3.1? I tried this in 3.0 and it doesn't work – Crantisz Feb 24 '22 at 10:02
  • yes, it is 3.1....but it works on 3.0 too – Chris Feb 24 '22 at 10:03
  • Ah, yes. Thanks – Crantisz Feb 24 '22 at 10:08
  • no problem ;) you are welcome – Chris Feb 24 '22 at 10:09
  • Thank you! BTW, if you (or anyone) can explain what kind of data the dark green sockets signify, I'd love to understand that better. – Mentalist Feb 24 '22 at 11:17
  • 1
    AFAIK the dark green round socket is just an integer. You can "test" that out on the group nodes by just changing the type and you will see it will change the color [1]: https://i.stack.imgur.com/S9WS3.png Of course there is also a difference between round and diamond: round is one value, diamond are multiple values (might be instances, vertices...) – Chris Feb 24 '22 at 11:21
  • Thank you for the info about sockets. Actually, I found an entry in the manual for socket types, but it seems it hasn't been updated yet as of the time of this writing. That is to say, dark green sockets and diamond shaped sockets are not mentioned. Although lime green sockets are listed as integer type, so who who knows... – Mentalist Feb 24 '22 at 12:52
  • Also, your screen shots show sockets as circular that are diamond shaped for me in 3.0.1 (I guess this will be changing in 3.1? I'll get it once the official release is out.) – Mentalist Feb 24 '22 at 13:05
  • the first screenshot is 3.1. The second one is 3.0 (i included the version number in the screenshot in the bottom right, as you can see) – Chris Feb 24 '22 at 13:08
  • @Mentalist The shape can also change according to what you plug in, it's not necessarily the Blender version why it's round in one screenshot and diamond in another. Here they are explained: Geometry Nodes: Fields I guess you got it already, but anyway, here's an overview of the socket shapes and how the same nodes can switch the appearance of their sockets: Shapes – Gordon Brinkmann Feb 24 '22 at 14:40
8

I think @Chris gave a good answer to help solve your problem. I think the main reason why the output wire turned red was that the input expected a single value while the Random Value node produced a list of values.

This answer is not meant as a solution (see Chris' answer), it's something for your understanding of the ID and Seed sockets of the Random Value node. By the way, I'll use the term ID, but if no IDs were assigned these nodes use the Index.

Let's say you have a geometry consisting of 4 points. They have the IDs 0, 1, 2, 3. The Random Value node now creates for example random float values depending on the Seed. Now imagine each ID gets an own random float assigned, e.g.

  • 0: 0.2
  • 1: 0.3
  • 2: 0.7
  • 3: 0.4

To change the rassigned values you can change the Seed value. As long as the Seed isn't changed, each ID has stable random value, i.e. each value is firmly assigned to the ID.

If you now plug an ID node into the ID socket of the Random Value node, nothing changes. Because it only tells the node, give these IDs from 0 to 3 random values based on the seed.

However, if you would now plug an integer into the ID socket - for example, 2, then the assigned values would be random based on the seed and the ID:

  • 0: 0.7
  • 1: 0.7
  • 2: 0.7
  • 3: 0.7

Now that doesn't look random, since they are all the same - but it is the random value that was given to the ID chosen by the value in the ID socket. To get a different random value to all points, you could switch to another ID. Or change the Seed. Or both. You can even enter values higher than the actual number of IDs.

This can for example be used with the Random Value node set to Vector and plugged into a Rotation socket: maybe you have many points, and want them all to be rotated randomly - but all the same random rotation. You could also animate the ID value and so jump between different random values but they are still the same for every point.

Gordon Brinkmann
  • 28,589
  • 1
  • 19
  • 49
  • 2
    Thank you! You just inadvertently solved a problem I asked about in a comment on an answer to another question only yesterday! :-D – Mentalist Feb 24 '22 at 13:35
  • @Mentalist Oh, I didn't come across this, great I could help you. – Gordon Brinkmann Feb 24 '22 at 14:42
  • The random node is a pseudo-random generator (PRG) initialized with a seed computed from ID and Seed sockets values. ID value is the ID of the element being evaluated, if no ID exists then it's the index of that element, and if no index, it's 0. In addition ID accepts a user provided value. Ok... Still this is not clear, in particular when is the PRG reset to the seed? If we knew that we wouldn't need a ton of explanations. Unfortunately Blender documentation is very similar to Microsoft documentation, it exists, it's correct, but being so laconic it's often not useful. – mins Jul 21 '22 at 15:11
  • @mins Well, of course it's a PRG, since software implementations cannot create non-deterministic random numbers, hence working with seed values. I don't understand what you mean with "reset to the seed"? Every value created by the Random Value node is always determined by the seed, no matter which ID you plug in etc. To simplify it, just imagine a specific seed value generates a list of numbers which are lined up in a row. The ID/index tells you how far to go along the line of random values and where to stop and pick a number. Btw, no index = no random value, but indices start at 0. – Gordon Brinkmann Jul 22 '22 at 12:19
  • @mins There are different implementations of a PRG (or PRNG actually), but usually a PRNG generates a sequence of seemingly random numbers which are all based on the seed - that's why it's deterministic. The way it generates the random numbers in the sequence may vary in implementations - but the ID or index doesn't change the sequence. It just determines which number to pick from that sequence. That's why you can only use integers in the ID field - there is no random value assigned between index 0 and 1 at 0.5, it's not computed from ID and seed - it's computed from seed and picked by ID. – Gordon Brinkmann Jul 22 '22 at 13:19
  • @mins For example, if you have 10 instances and scale them randomly, then take an Index node and plug it into a Set ID node. Nothing changes since by default ID and index are the same. Now with a Math node set to Add, you can add 1 to the index and therefore set the ID to 1, 2, 3... instead of 0, 1, 2... as the index is. Now that there is an ID, the Random Value uses it instead of the ID. You can see the random scaling of the instances shifts by 1. Add 2 and it shifts by 2. But if you multiply by 2, now the scaling picks the values from what were the even numbers in the index. – Gordon Brinkmann Jul 22 '22 at 13:32
  • @mins However, there is no "first value" in any way. You could argue that 0 is the first value, but entering -1 in the ID socket will get a random value, too. The indices of any points, instances or whatever you have in the node tree will never be lower than 0, but since you can assign IDs that's not true for IDs. Plugging nothing into the ID socket of the Random Value node doesn't reset it either - if there's some kind of point, instance etc. there will always be at least an index number 0. If there is not, there is nothing to attach a random value to from the sequence no matter which seed. – Gordon Brinkmann Jul 22 '22 at 13:42
  • @mins It is quite misleading when you were talking about a different kind of problem the whole time as I can see in the linked question. Yes, it is a sequence,meaning it is sequential, and picking the same ID always gives the same value, that's why it's deterministic and called pseudorandom instead of random. In the other question you use the node to randomize four vertices in a cube, index 0, 1, 2, 3. If you create instances of this cubes they are all duplicates of the first. They maybe have index x = 0, 1, 2, 3 but the vertices are still 0, 1, 2, 3 of cube x. so they are the same. – Gordon Brinkmann Jul 22 '22 at 13:59
  • @GordonBrinkmann: Actually what I didn't get is when you draw a PRN from the Random Value node, you don't actually draw a new PRN (as in classical function rand()), you provide an index and you get the same result for the same index. To me it's a deviation huge enough to be mentioned in the documentation, instead of describing ID as "An ID to drive the random number generator seed" which (after your explanation) seems actually a wrong statement, as ID doesn't drive the PR generation at all. – mins Jul 22 '22 at 14:17