Jump to content

Controlling Scatter Density by Attractor Point


Recommended Posts

You can control the density of scattered points by an attribute, the scatter SOP defaults to a "density" attribute but you can use whatever you like.

For the distribution that you have in your top image you could make a black to white gradient on a grid then replace "density" with "Cd" in the Density Attribute parameter.

Link to comment
Share on other sites

I added some notes in the VEX code to explain what's going on, but I can elaborate a little further.

The first two examples are doing exactly the same thing, one in VEX and one in VOPs: generating a @density attribute based on the Y position of each point on the grid, relative to the bounding box. The `relbbox` function returns a vector with components ranging between 0 and 1, based on where the point is relative to the bounding box of the object on each axis. The y-component of that vector is used as the lookup value for a ramp, using the `chramp` function. The ramp parameter is auto-generated by the point wrangle if you click the little "+" button next to the VEX code. You can then use this ramp to control the value of the @density attribute, which exists on the points of the grid. If you want to visually see the results, you can use a Visualizer SOP to view density as color. The Scatter SOP by default will look for a @density attribute to determine where to prioritize scattering points, but you could use other attributes if you like; density is just a convention.

The third example is using the "attractor points" you were asking about. A number of points are scattered on the grid; these are the attractors. In the point wrangle, which runs over all points of the grid simultaneously, the nearest attractor point to the current iteration's point position is found using `nearpt`, and then the `point` function is used to get the position of that attractor. The distance between the current grid point and the nearest attractor point is computed and fit to a 0-1 range based on the "max_dist" channel, which is user-defined. The resulting 0-1 value is used with a ramp attribute lookup, and the result is bound to @density, same as the other examples. You could change the falloff ramp and the max distance to adjust exactly how the density is mapped to the grid points.

If you wanted to solve this without VEX, you could try scattering a few points onto a grid, giving them all a @density value of 1 or some other positive value, then using an Attribute Transfer to transfer this attribute back to the grid points. Then use a Scatter SOP as before.

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...