3
$\begingroup$

Here's a geometry node problem, how could we "shuffle" an attribute? (Randomly mixing the indices of the field values)

In the illustratory shuffle_example_problem.blend below, we'd like to only display N points of our distribution in the viewport, to do so we compare the index value of the points and cull every points whose indices are exceeding N value, however, the default Index of the distribution is bias to our surface geometry, we need a shuffle node to work with a truly random index value.

i tried various techniques already, see shuffle_by_offsetting_index.blend consisting of "offsetting" or "mirroring" indices depending on odd/even numbers or random ranges.

This technique wasn't quite successful, because picking random ranges might not be noticeable on a large number of points, and the even/odd (modulo) numbers are too regular, not random enough for this case.

I'm curious if someone has a more "elegant" solution for shuffling attributes?

enter image description here

$\endgroup$
1

2 Answers 2

2
$\begingroup$

Here's how you can solve it:

enter image description here

  1. Get the number of points with the node Domain Size.

  2. Divide the number of points you want with the number of points of your mesh.

  3. Feed this value into Probability of the node Random Value and set it to Boolean.

PS: It won't get exactly the amount of points you want at every resolution, but it should work precisely enough.

$\endgroup$
5
  • $\begingroup$ Thanks for your input @quellenform Unfortunately, division tricks or using the random values node aren't precise enough, i concluded that the only way to solve this solution would be to have some ways to shuffle our indices $\endgroup$
    – Fox
    Commented Jun 22, 2022 at 12:59
  • $\begingroup$ @DB3D So you need exactly 10K points? $\endgroup$
    – quellenform
    Commented Jun 22, 2022 at 13:09
  • $\begingroup$ That's the goal of the illustratory .blend file yes, (but the question is about shuffling attributes). There is another solution to get exactly 10k points, is by creating a mesh line of 10k verts and transferring by index the position of the point to our original distribution, however this solution isn't valid either because it will destroy all attributes of the users, users won't be able to use his vgroup/vcolor/uvs with such set up $\endgroup$
    – Fox
    Commented Jun 22, 2022 at 13:14
  • 1
    $\begingroup$ @DB3D Ah, OK, then it gets tricky. The problem is that Random Value does not generate unique numbers. The only solution I currently know is this one: blender.stackexchange.com/questions/265202/… $\endgroup$
    – quellenform
    Commented Jun 22, 2022 at 13:18
  • $\begingroup$ Thanks, @quellenform this is a good (slow) solution! thank you very much $\endgroup$
    – Fox
    Commented Jun 22, 2022 at 13:26
0
$\begingroup$

In order to shuffle we need an alternative non repeating index value, please see my post here Geonodes mix position with random index values - How to make random values unique?

Here's the logic behind the shuffling: 1) generate a random field integer of values ranging from 0 to 3, these will be our 4 distinct "groups", we could work with more groups if needed but i believe 4 is a sweetspot 2) With the accumulate field nodes we could distinctly enumerate our groups indices and get each group length 3) For each group, we compensate the enumeration with the total length consecutively

https://i.sstatic.net/rmpff.jpg

Once we have such shuffled index, we could use the Field at Index node to swap our Field with our new index and the shuffle is done

Note that the context domain here is per points

enter image description here

$\endgroup$
1
  • $\begingroup$ Hi, please include at least some of the answer information in this answer. If that other question gets deleted at some point this answer will have very little information in it. Thanks. $\endgroup$ Commented Jun 22, 2022 at 18:30

You must log in to answer this question.

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