Creating Gradients from the Edge of a Shape in Houdini
This was something which had me baffled for a few hours. I wanted to scatter points onto an irregular shape, but control the scatter in such a way so they could have a distance from the edge.
I knew I needed to create a density attribute and use that in the scatter SOP, but everything I tried just didn't seem to work quite right, instead creating radial gradients from a point. Then I read about using the xyzdist() function, and after some trial and error, I managed to achieve the effect I was going for.
The core of the solution was laying down a Point VOP. Connected to the first part of the Point VOP was the shape I want to use, which I had remeshed so the part was made up of many triangles. This is so the shape has plenty of points in which to calculate the density attribute. In the second input of the Point VOP I had the same shape, but used convert line to create a single line primitive. You may need to do some edge finding first to to only get a line with the outer edge before attaching it to the second input.
Diving into the VOP, I put down an xyzdist node and connected the second input to the file input and then connected the P input to the pos input. This will then calculate the distance from each point to the nearest primitive coming in via the second input.
I also connected a constant value of 10 to the maxdist input.
I then connect a ramp node so I can have fine grain control of this distance value coming from xyzdist, then finally I add a Bind Export node, with the name set to density, to output this value as a density attribute.
Back up outside the VOP I then add the all important Scatter node, making sure the Density Attribute checkbox is checked with the density as the attribute. This will now scatter the points using the density attribute we set using the VOP. By using the ramp parameter in the VOP we can configure how we want this scatter to distribute the points.
This is how my final network looked.