0

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: enter image description here

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.

Phoenix
  • 145

1 Answers1

0

I found a solution for approximating this quickly. I pick a small 'delta' value, such as 0.01. Then, for each of the six axis-aligned unit vectors, which I'll call direction vectors, I multiply the direction vector by delta and add it to the sample coordinates, use trilinear interpolation to sample the density at that point, and multiply the sampled density by the direction vector, yielding six vectors. I then average these vectors and normalize the result to get my approximation of the gradient direction.

Phoenix
  • 145
  • Can you please detail "use trilinear interpolation to sample the density at that point". Are you suggestion to use trilinear interpolation to get the density for each direction? That sounds very expensive in terms of computations? It seems I am trying to accomplish the same thing at :https://math.stackexchange.com/questions/2542558/compute-gradient-local-normals-during-trilinear-interpolation – Nicolas Nov 29 '17 at 09:59
  • Yes, unfortunately, that's what I'm currently doing – Phoenix Nov 29 '17 at 14:15