As a long-time user of the free, open-source raytracer POV-Ray, I'm trying to understand some of the source code used to compute and perturb surface normals. The method uses the evaluation of 4 points, offset from a point on the surface in a regular tetrahedral arrangement. https://news.povray.org/povray.general/message/%3C5c45e632%241%40news.povray.org%3E/#%3C5c45e632%241%40news.povray.org% 3E
I have only found one mention of this method:
https://iquilezles.org/articles/normalsSDF/
which only provides a brief summary of how it works.
The four sampling points are arranged in a tetrahedron with vertices k0 = {1,-1,-1}, k1 = {-1,-1,1}, k2 = {-1,1,-1} and k3 = {1,1,1}. Evaluating the sum "m = Sum ki * f (p + hki)" (see equation in link) on those four vertices produces some nice cancellations that results in m = Sum ki (f (p + hki) - f(p)) (see equation in link) which are four directional derivatives, meaning we can rewrite the sum as ....
m = Sum ki * Del ki * f(p) = Sum ki (ki * Del f(P)) and mx = Sum kix Del ki f(p) = Del f(p) (dot) Sum kix*ki = Del f(p) * <4, 0, 0>
And then normalizing this result gives the surface normal at the point of interest.
I would like to know the origin of this method, hopefully in a reference.
I would like to understand how summing the product of 4 vectors with 4 scalar function results gives the cancellations and "directional derivatives".
(I have a sneaking suspicion that it may be related to calculating the divergence of the vector field defined by the tetrahedron, but that's math that's just a step ahead of anything that I formally studied and am sufficiently familiar with to work out on my own.)
However, I haven't been able to independently come up with a way to operate on the terms that results in anything that would cancel out and give me what appears to be a new f(p) term as shown in that next step.
I tried to implement the method myself in code http://news.povray.org/povray.pov4.discussion.general/message/%3Cweb.6552db6d61b9f4951f9dae3025979125%40news.povray.org%3E/#%3Cweb.6552db6d61b9f4951f9dae3025979125%40news.povray.org%3E but it doesn't seem to fully work - some of the normals seem to point in the wrong direction.
Finally, it's unclear to me how such a method can be implemented to perturb the normals of a smooth surface to simulate a an actual surface deformation using only a scalar function result to control the normal pattern. The way I'm thinking about it is that I can take a surface normal and make it point anywhere around a sphere centered on that point on the surface - which requires 2 dimensional spherical coordinates. A scalar value has no directional component to direct which way to perturb the normal of the surface.
Thanks you for any insights, leads, or explanations that you can offer,
- Bill