7
$\begingroup$

I have this Geometry Nodes setup:

enter image description here

But the indexes are like this, even if I use a random seed for the Distribute Points node at the volume:

enter image description here

How to obtain truly randomized indices?

(In order to view the indices, I used this GN modifier on top of my first GN modifier: https://artofriaz3d.gumroad.com/l/indexviewerfields)

$\endgroup$
0

4 Answers 4

10
+50
$\begingroup$

$\hspace{15pt}$Using sorting nodes like Points of Curve works perfectly and results in simple node trees, but as domain size increases, like thousands of indices and more, sorting will slow down significantly, so if anyone wants faster methods for these cases, I recommend the methods provided in this answer.

$$\text{Pick Discard Repeat (PDR)}$$

$$\text{Timing comparison}\\\tiny{_\text{made on my potato laptop}}$$

$\hspace{15pt}$2.5 K points

Native Sorting:

Native Sorting multiple timings

PDR Shuffle (4 steps):

PDR multiple timings

$\hspace{15pt}$10 K points

Native Sorting:

enter image description here

PDR Shuffle (4 steps):

enter image description here

$$\text{How it works}$$

enter image description here

$\hspace{15pt}$The nodes are separated in three node groups, one which can be chained for more steps.


  • PDR Shuffle Prepare

$\hspace{15pt}$Generates the initial point cloud storing all indices as available indices. Their positions is set to $(0, 0, i_{ndex})$ and their IDs are set to their indices.

PDR Shuffle Prepare node group


  • PDR Shuffle Step

$\hspace{15pt}$For points in Available Indices, set their ID to the ID of a random point and then, for points with repeated IDs, leave only one per ID by deleting all of the others. After that set their position to $(0, 0, I_D)$ and join them to Shuffled Indices before outputting in the Shuffled Indices socket.

$\hspace{15pt}$Also for points in Available Indices, remove all points whose IDs had been picked in the process above before outputting the result in the Available Indices socket, this is done using the Geometry Proximity node, which is why point positions are being set to $(0, 0, I_D)$.

PDR Shuffle Step node group


  • PDR Shuffle End

$\hspace{15pt}$If any remaining available indices, sort them with random weights ('Native Sorting') and join to Shuffled indices.

$\hspace{15pt}$The resulting point cloud is from where ID will be sampled using the index of the current context (The geometry and domain that are using the shuffled indices output).

$\hspace{15pt}$ I also added another output called Pointed By, which has the index that got the current index after shuffling.

PDR Shuffle End node group

$_\text{Blender 3.6 (but can be opened on 3.4)}$


Update: The Separate and Rejoin method pointed by Robin Betts is many times faster than PDR with hundreds of thousands of indices, since it does not depend on distance calculation nodes like Geometry Proximity.

$$\text{Separate and Rejoin}$$

$$\text{Timing comparison}\\\tiny{_\text{also made on my potato laptop}}$$

$\hspace{15pt}$100 K points

PDR (4 steps):

PDR multiple timings

Separate and Rejoin (8 steps):

S&R multiple timings

$$\text{How it works}$$

enter image description here

$\hspace{15pt}$Like PDR, Separate and Rejoin operates with three different node groups, one which can be chained for more steps.

  • S&R Shuffle Prepare

$\hspace{15pt}$Generates the initial point cloud setting their IDs are to their indices.

S&R Shuffle Prepare node tree


  • S&R Shuffle Step

$\hspace{15pt}$Selects random points and move them to the end of the domain, this action is performed by separating them and then appending to the unselected points with the Separate Geometry and Join Geometry node.

S&R Shuffle Step node tree


  • S&R Shuffle End

$\hspace{15pt}$From the shuffled points, samples the ID attribute at the current index.

S&R Shuffle End node tree


$\hspace{15pt}$ The only disadvantage compared to PDR, is that you cannot use Native Sorting to randomize indices that weren't shuffled, the cause is that Separate and Rejoin operates on all points in every step, increasing disorder of all.

  • 100K points, 4 steps. (Second image is displaying UV of index which has a shuffled index equal to the current index)

$\hspace{15pt}$ But, with Blender 4.0, with Repeat zones, the number of steps could be made to depend on the number of indices.

For me, $\lceil\ln{T}\rceil$, where $T$ is the index count, already gives a good number of steps. For PDR, $\lceil\frac{\ln{T}}{2}\rceil$;

$_\text{Blender 3.6 (but can be opened on 3.4)}$

$\endgroup$
4
  • $\begingroup$ Great stuff .. I haven't managed to get the separate and rejoin method to be any better than 3x slower than this.. yet :) .. on 10k . And that one's very iteration-dependent. $\endgroup$
    – Robin Betts
    Commented Oct 16, 2023 at 7:34
  • $\begingroup$ Fantastic! This was very easy to use in order to set new IDs in order to randomize my points distributed in the volume mesh. And so nice if it's even more optimized than the other good answer. Great! $\endgroup$ Commented Oct 16, 2023 at 10:22
  • $\begingroup$ @RobinBetts I made a test right now and one variation of separate and rejoin with 8 steps seems to be about 1.5x faster than PDR (with 4 steps) on my laptop with 10k points. 8 steps were used to get a good random shuffle and remove any visual patterns. I will update this answer later today. $\endgroup$
    – Hulifier
    Commented Oct 16, 2023 at 14:31
  • $\begingroup$ @Hulifier good spot! I modified my version a bit to make it what I thought would be a bit quicker, using Vector random.. I seem to have made it slower, if you're getting better times. The rejoins are taking most of it, for me. $\endgroup$
    – Robin Betts
    Commented Oct 16, 2023 at 14:45
11
$\begingroup$

There is a technique that can be used to re-sort points based on a specific value.

I have called this Native Sorting Technique, because it uses only a small node trick that does not require any quadratic complexity.

It is described in more detail here: How can I re-sort the points/indexes of an object in geometry nodes?.

This post is about the opposite, sorting points, but with the same technique you can also mess up the order of points.

The sorting criterion is crucial here. To achieve a random order, you would simply have to insert the node Random Value at this point.

enter image description here

But keep in mind: A rearrangement of indices is only possible by recreating the object. So the points you created are only used as a starting point, and new points are created instead with the same positions, but only with different indices.


(Blender 3.4+)

$\endgroup$
4
$\begingroup$

How about separating randomly selected points and joining them back?

This reshuffles partially the indices so this process can be repeated multiple times for a good shuffle.

On the figure bellow are shown two objects converted to mesh. The left one has the "Reshuffle point indices" group off - the right one - it is on. Both in edit mode with indices on. A third object shows the simple node setup.

enter image description here

Here is an example blend file:

$\endgroup$
3
  • $\begingroup$ This is literally shuffling, and is surprisingly effective, but I'm not sure what's the proper way to test it - the .blend file I linked to checks if the horizontal gradient disappears, but some statistic measurement would be better... $\endgroup$ Commented Oct 17, 2023 at 19:26
  • 1
    $\begingroup$ Exactly. It is like shuffling a deck of cards. Remove 50% randomly selected cards and add them to the top of the deck. With 3 or 4 repeats you get pretty random distribution (gradient completely destroyed). It is important to use different seed. There is a Hurl Noise filter in Gimp that does the same thing. You can try it on grayscale image with gradient. I suppose with Blender 4.0's Repeat node it could get even easier to set up. $\endgroup$ Commented Oct 17, 2023 at 20:05
  • 1
    $\begingroup$ Awesome! This is also very easily understandable for a layman like me :) Simple answers are sometimes the best answers. $\endgroup$ Commented Oct 18, 2023 at 10:26
0
$\begingroup$

I just started thinking, though, that why THIS super-simple answer actually doesn't work for my initial problem? It seems to work, but, is there something I'm missing?

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ This can (and very likely will) produce gaps and duplicates amongst the indices. $\endgroup$ Commented Oct 16, 2023 at 12:52
  • 1
    $\begingroup$ @AlpineWorldCup Thank you for the clarification! $\endgroup$ Commented Oct 18, 2023 at 10:24

You must log in to answer this question.

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