I'm trying to figure out how to compute something for a game I'm creating, and I'm having trouble finding a solution in language I can understand. The extent of my math education is that I'm just starting Calculus AB, so I would greatly appreciate if an answer could not assume that I know complex math.
I'm using the surface nets algorithm, which attempts to approximate an isosurface through a scalar field, defined by a three-dimensional grid of samples, with the spaces between the samples computed using trilinear interpolation. I'm trying to find a way to compute the gradient of this field at a given point (with reasonable efficiency).
The solution I've attempted so far is: - define the direction at a sample point as the values of the 6 adjacent samples, multiplied by the vectors from the main sample to the respective adjacent sample, and then averaged - define the direction at an arbitrary point by trilinearly interpolating the direction vectors, and then normalizing the result
Unfortunately, when I visualize the normals, they are obviously not correct:
The black and white lines on this image represent the normals, where the black end lines on the sample, and the white end points in the direction of the normal.
I would appreciate a solution to this problem, or at least a pointer in the right direction. Thanks.