Page MenuHome

Geometry Nodes: Add alternative distribution options to the Attribute Randomize node
AbandonedPublic

Authored by Charlie Jolly (charlie) on Feb 18 2021, 3:20 AM.
Tokens
"Like" token, awarded by digim0nk."Love" token, awarded by HEYPictures."Burninate" token, awarded by ugosantana."Love" token, awarded by damian."Love" token, awarded by lone_noel."Like" token, awarded by GeorgiaPacific."Love" token, awarded by TimBrown.

Details

Summary

This provides additional options for distributing random values.

Uniform Default, distributes the values between these values.

Midpoint: Distribute values around the Midpoint plus/minus Variance.

Gaussian: Distribute values around a Mean value with a standard deviation of Sigma.

Triangular: Distribute between min and max with a mean.

(Removed) Exponential: Distribute exponentially.

(Removed) Spherical: Distribute across a sphere with min - max control for radius and angle.

Not applicable to Boolean data type.

Previous version

Diff Detail

Repository
rB Blender
Branch
master
Build Status
Buildable 13065
Build 13065: arc lint + arc unit

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Charlie Jolly (charlie) marked an inline comment as done.

Change Bipolar option to use Midpoint - Variance and add this as a distribution option instead of a checkbox.

Charlie Jolly (charlie) retitled this revision from Geometry Nodes: Add Bipolar option to the Attribute Randomize node to Geometry Nodes: Add distribution option to the Attribute Randomize node.Feb 18 2021, 2:03 PM
Charlie Jolly (charlie) edited the summary of this revision. (Show Details)
Charlie Jolly (charlie) updated this revision to Diff 34138.EditedFeb 18 2021, 5:31 PM

Add dynamic labels. No more changes planned.

Charlie Jolly (charlie) edited the summary of this revision. (Show Details)Feb 18 2021, 8:30 PM

I feel bad about being negative here, but I prefer the lower level node approach that Jacques described, with a built-in node group to handle this use-case.
We've already slightly violated that approach with the operation option, but that required using a temporary attribute, so there were performance considerations in addition to the need to type in the temporary attribute name twice. Those don't really apply here.

But I see this as the perfect use case for the built-in node group idea that has been discussed before, where it would appear in the add node list. IMO that idea should be explored more before we add options to nodes like this.

@Jacques Lucke (JacquesLucke) @Hans Goudey (HooglyBoogly) @Simon Thommes (simonthommes)

I understand the reluctance of adding options for the sake of it, but I can't bring myself to agree with the viewpoint of using Node Groups, they are just not fit for purpose for adding this type of option.

Below is a node group to create the Midpoint-Variance option.

This is just for vector attribute data type and Node Groups would need to be created for all data types.

In addition, it is not even possible to use anything but sockets in the Node Group. So there is no way to expose the Operation and Data Type enums.

Example of Node Group for Vector data type:

Example of real world nodes that would benefit from having this option (copied from Twitter feed by @Erindale (Erindale)):

+1 for more probability distributions! I've been thinking for a while now that adding more ways to sample random values would be very useful :)

I wouldn't use the names Min - Max and Midpoint Variance though, but the standard names of the probability distributions with their most common parametrizations, e.g:

  • Uniform (parameters: min and max)
  • Normal or Gaussian (parameters: mean and standard deviation)

Other distributions e.g. Exponential, Poisson, Gamma, Log-Normal, Weibull, Binomial, etc would definitely be useful too in the future! Just as an example to show how you could arrive at these distributions, here's a flow chart I found that helps you choose one:


(source)

Charlie Jolly (charlie) updated this revision to Diff 34301.EditedFeb 23 2021, 3:07 AM

Add Gaussian distribution based on comments from @Victor-Louis De Gusseme (victorlouis)

Min-Max > Midpoint > Gaussian

Charlie Jolly (charlie) retitled this revision from Geometry Nodes: Add distribution option to the Attribute Randomize node to Geometry Nodes: Add alternative distribution options to the Attribute Randomize node.Feb 23 2021, 3:10 AM
Charlie Jolly (charlie) edited the summary of this revision. (Show Details)
Hans Goudey (HooglyBoogly) requested changes to this revision.EditedFeb 23 2021, 4:58 AM

Thanks for the reasoning above, it makes sense to me. The point about not being able to expose the is important indeed. Having the gaussian distribution helps justify the option as well-- the idea of adding more useful distributions is interesting.

EDIT: Oops, didn't finish my comment.

source/blender/makesrna/intern/rna_nodetree.c
382

This can be defined inside of def_geo_attribute_randomize

386

Might make more sense to use "Uniform" instead of "Min Max"

387

There's some random capitalization in these descriptions. Only the first letter should be capitalized.

source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
202

I don't think this is quite enough to go by, maybe a brief description of the choice of algorithm?

212

It's a bit late, so I might not be thinking straight, but I'm not quite sure how this works. Since at this point the address gauss is a local variable, changing it wouldn't affect the next run of the function? Or if it did it would be an address of a local variable that would only happen to work?

377–389

These might as well be switches too. Unless we find a better way to reduce the repetition from the data types here.

This revision now requires changes to proceed.Feb 23 2021, 4:58 AM
Charlie Jolly (charlie) marked 6 inline comments as done.

Address comments.

Charlie Jolly (charlie) edited the summary of this revision. (Show Details)Feb 23 2021, 1:30 PM
Charlie Jolly (charlie) added inline comments.
source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
202

Added more information.

212

Renamed z2 to tmp for clarity. For optimisation the function generates two values, gauss is used to hold the value for the next call when it is reset.

Charlie Jolly (charlie) updated this revision to Diff 35413.EditedMar 20 2021, 6:32 AM

Add Triangular distribution

Left to right:
Uniform, Midpoint, Gaussian, Triangular

Add Triangular distribution

Left to right:
Uniform, Midpoint, Gaussian, Triangular

That gaussian distribution looks quite suspicious to me...
I haven't looked at the code but I looked at the patch and recreated a random 3D distribution and it looks to me like there is either some bias in the distribution itself or correlation between the components.
Judging from the fact that creating the vector from multiple different seeds gives the same result, I'd guess that there is something fishy with the values themselves.

Add Triangular distribution

Left to right:
Uniform, Midpoint, Gaussian, Triangular

That gaussian distribution looks quite suspicious to me...
I haven't looked at the code but I looked at the patch and recreated a random 3D distribution and it looks to me like there is either some bias in the distribution itself or correlation between the components.
Judging from the fact that creating the vector from multiple different seeds gives the same result, I'd guess that there is something fishy with the values themselves.

Sounds like a bug. I'll check through it again. Did you happen to have the test file to hand?

Charlie Jolly (charlie) updated this revision to Diff 35486.EditedMar 22 2021, 6:48 PM

Added exponential and spherical. Fix bug in gaussian. No more distribution methods planned.

Charlie Jolly (charlie) edited the summary of this revision. (Show Details)Mar 22 2021, 6:50 PM

@Charlie Jolly (charlie) thanks for looking into it that looks good now! I didn't really have an example file, sorry. Just seemed wrong to me when looking at it.

@Charlie Jolly (charlie) Is this patch ready to test? If so could you merge it with current master? It didn't build for me when I tried it just now.

Fix build on Linux.

Simon Thommes (simonthommes) requested changes to this revision.EditedMar 29 2021, 6:23 PM

Okay, I tested the patch and have a bunch of impressions.
First of all: I think it's super useful to have alternative random distributions, especially the symmetrical ones around a center directly inside of this node!

With some of these though I'm not sure how fundamental they are to this specific node (in terms of real-life use-cases). I think the options in this node should only feature essential randomization methods .
I think the ones that are in there right now are still different enough to be justifiable, but if we do want to go for for a broad variety of pre-defined or custom distributions and have a good case for going in that direction, I think we should split this idea off into [a] separate, dedicated node[s]. That could take uniformly distributed attributes and turn them into any given other distribution. Just a thought.

The ones I personally see as giving an essential benefit to this node itself are: Uniform, Midpoint Variance, Gaussian, maybe Triangular

Let me go over some specific issues that I see:

First of all in terms of user interaction and defaults:

  • I think the order of Sigma and Mean should be replaced as an equivalent of Midpoint and Variance. Mean first, Sigma second.

  • For the Gaussian distibution I would expect the defaults to be Mean = 0; Sigma = 1.
  • For the Triangular distribution I would set the default mean to 0.5 .

I see multiple issues with the Spherical distribution:

  • I'm honestly not exactly sure what it is meant for.
  • for Float it does not seem to have any additional value to me. It looks like it is simply doing a uniform distribution between min and max angle in radians. (Correct me if I'm wrong.) I would expect it to actually have a spherically shaped distribution between to values (not angular). Just like the Triangular method.

  • I think this distribution does not fit into the concept of the others and it, in general, seems very niche to me. Quite frankly I am not sure what to expect given the parameters.
  • If the idea is to generate evenly distributed values within a given spherical volume (with set angular and radial limits) it is lacking spatial uniformity as it is right now. This shows as a strong draw towards the poles, when limiting the radius to a single value for example, as it's not corrected for the zenith angle:

  • That point actually bleeds into an idea that I personally find more interesting as a potential randomization method: Isotropic Randomization of Rotation Vectors. Right now there is no easy way of getting randomized angles in 3D with a uniform distribution. I don't think this has to be solved with this node, but for me it is more use-case oriented and practical than the idea of the spherical distribution. (But again, I am still not sure what it is exactly supposed to solve.) Having the spherical distribution as spatially uniform withing the defined spherical limits could accomplish this with the Align Rotation to Vector node.

  • this method is the only one that does not randomize every vector component in the same way. That alone gives me reason to believe that this should not be part of this node.

File with used examples:

Concluding: I think the Spherical method should either be adapted and/or renamed or removed. Unless I missed an important use-case. Then please let me know what that is.

Sorry if my points are a bit all over the place and not presenting a great solution. I don't have more time to invest into making things more clear right now.

This revision now requires changes to proceed.Mar 29 2021, 6:23 PM

@Simon Thommes (simonthommes) this is really good feedback. I agree with pretty much everything you've said.

The spherical distribution certainly needs more work to make it spatially uniform.

The use case for the spherical distribution is to provide a way to randomize a vector by angle/direction and length. This can be used to distribute points radially. spherically in angular space.

In this example, spherical distribution is used to randomly point the cones in a 40 degree arc. This is much easier to control and natural than using euler rotations. I see this in a comparable way to the Axis Angle vs Euler rotation methods in the vector rotate node.

@Simon Thommes (simonthommes) this is really good feedback. I agree with pretty much everything you've said.

Great, I'm glad!

The spherical distribution certainly needs more work to make it spatially uniform.

The use case for the spherical distribution is to provide a way to randomize a vector by angle/direction and length. This can be used to distribute points radially. spherically in angular space.

In this example, spherical distribution is used to randomly point the cones in a 40 degree arc. This is much easier to control and natural than using euler rotations. I see this in a comparable way to the Axis Angle vs Euler rotation methods in the vector rotate node.

Okay, so it is what I was thinking then. Hm, I'm not sure this should be in this node then, to be honest. To me this is a special case, just as well as randomization of colors. It goes beyond just simply randomizing an attribute's components according to a distribution and correlates the components.

My proposal would be to remove this distribution from the node and create a new task for this case (we might actually still have one for randomizing rotations uniformly). It would probably be a new node, but the design would still need to be figured out.

And yeah, it should be spatially uniform for this, so it would need more work anyways. My initial idea would just be to re-roll random values uniformly if they are not meeting the angle and radius constraints, but there is probably a more elegant solution.

Address comments from @Simon Thommes (simonthommes).

Change default values and reorder inputs.
Remove Exponential and Spherical modes. (Spherical will be implemented in a seperate patch)

Charlie Jolly (charlie) edited the summary of this revision. (Show Details)Apr 2 2021, 4:53 PM

Thanks for addressing my feedback!
I'm pretty happy with what we have with this node now!

There are two minor things that I am wondering about:

  • Min/Max inputs are shared by the Uniform and Triangular distribution type, which makes sense. I feel like the same way it would be nice to have shared inputs for Gaussian and Midpoint Variance. That way the distribution method can easily be changed while keeping the wire connections/set values intact. Actually, after reviewing the behaviour again I see that the inputs are shared between all methods except Gaussian even though the labels change for Midpoint Variance. I think, either should the Gaussian method share the inputs as well, or, if possible, the pairs of Uniform/Triangular and Gaussian/Midpoint Variance should have shared inputs, as they are conceptually similar. (I'd personally go for the latter) The labeling should stay the same though.
  • I am wondering if the Triangular method would benefit from the Mode input being relative to Min and Max. I can see both option being useful depending on the case and I'm not sure. I do feel like the relative method would be more intuitive to use, as usually I would use this method to bias a distribution towards either side, rather than place the area of maximum likelihood around a point. So I'd propose to do it relative as in:
Mode(0,0,0)=Min
Mode(0.5,0.5,0.5)=(Min+Max)/2
Mode(1,1,1)=Max

@Simon Thommes (simonthommes) I think it makes sense to share the inputs in this way. The idea about the mode as a factor is also good. I'll make these changes and update the patch.

I've also uploaded a WIP patch for the spherical distribution here: D10883: Geometry Nodes: Attribute Randomize Spherical Node

Charlie Jolly (charlie) updated this revision to Diff 37928.EditedJun 6 2021, 7:53 PM

Rebase to master and add parallel_for

Simon, I did try the suggestions for the variable sharing but they didn't work out as well. Mode already works as a factor type variable in the triangular distribution.

Rebase to master and add Triangular Factor distribution as suggested by Simon.

I think we should put this patch on hold until we have the details of the new attribute workflow settled, which will hopefully be soon.
The implementation would probably be quite simpler in that case, which is very nice.

I still think the functionality in this patch is important though.

EDIT: To clarify, I think this node could be "preemptively" implemented as a function node so that it was ready when function nodes can be used for attributes.

Hans Goudey (HooglyBoogly) requested changes to this revision.Aug 12 2021, 6:18 AM
This revision now requires changes to proceed.Aug 12 2021, 6:18 AM

New random fields version D12603: Geometry Nodes: Fields version of Attribute Randomize as a Function Node developed by @Johnny Matthews (guitargeek) will hopefully include the extra distibutions from this patch

This revision now requires changes to proceed.Oct 4 2021, 12:42 AM