9
$\begingroup$

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!

$\endgroup$
0

2 Answers 2

8
$\begingroup$

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

$\endgroup$
10
  • $\begingroup$ Is it 3.1? I tried this in 3.0 and it doesn't work $\endgroup$
    – Crantisz
    Commented Feb 24, 2022 at 10:02
  • $\begingroup$ yes, it is 3.1....but it works on 3.0 too $\endgroup$
    – Chris
    Commented Feb 24, 2022 at 10:03
  • $\begingroup$ Ah, yes. Thanks $\endgroup$
    – Crantisz
    Commented Feb 24, 2022 at 10:08
  • $\begingroup$ no problem ;) you are welcome $\endgroup$
    – Chris
    Commented Feb 24, 2022 at 10:09
  • 1
    $\begingroup$ 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]: i.sstatic.net/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...) $\endgroup$
    – Chris
    Commented Feb 24, 2022 at 11:21
8
$\begingroup$

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.

$\endgroup$
10
  • 2
    $\begingroup$ Thank you! You just inadvertently solved a problem I asked about in a comment on an answer to another question only yesterday! :-D $\endgroup$
    – Mentalist
    Commented Feb 24, 2022 at 13:35
  • $\begingroup$ @Mentalist Oh, I didn't come across this, great I could help you. $\endgroup$ Commented Feb 24, 2022 at 14:42
  • $\begingroup$ 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. $\endgroup$
    – mins
    Commented Jul 21, 2022 at 15:11
  • $\begingroup$ @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. $\endgroup$ Commented Jul 22, 2022 at 12:19
  • $\begingroup$ @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. $\endgroup$ Commented Jul 22, 2022 at 13:19

Not the answer you're looking for? Browse other questions tagged .