1 MINUTE VEX XII
Attrib Gradient Estimation From Neighbours
In this example, we explore point attrib gradients in Houdini, and a quick and cheap method in which we can estimate the gradient direction of an attribute by looking at our point neighbours.
First we begin by finding three variables - our attrib (gradient) name, the attrib value (from name), and the point position. We then generate an array containing the point numbers for all neighbours.
Once we have all of our initial variables, we create two empty arrays - one for incoming weights, and another for incoming directions found.
Iterating over the neighbours in a foreach loop, we find the attrib value of each neighbour and determine how different the neighbour’s point position ‘P’ is using the fit() function. The fit function will clamp gradient values that are less than the current point’s at 0, and will create a weight in the range of 0-1 for values between the current gradient and 1.
Now that we have our weight, we can append it to our ‘weights’ array and, after finding the direction of this neighbour to our point, append the weight-multiplied direction to our ‘dirs’ array.
With all of our neighbouring directions and weights found, we divide the the sum of all directions by the sum of all weights to find the ‘weighted’ average gradient direction.