Transforming implicit surface (distance field) and their gradient
\( \renewcommand{\vec}[1]{ \mathbf{#1} } \)
Let \( f:\mathbb R^3 \rightarrow\mathbb R\) be any distance field. We can transform any implicit surface \( f(x,y,z) = c\) with a 4x4 transformation matrix as follows:
$$ \hat f(\vec p) = f( \mathbf T^{-1} \vec p)$$
Gradient
Sometimes you need to compute the normal of an implicit surface. You usually do this using the gradient \(\nabla f\) which needs to be transformed as well. Similar to the normal of a mesh use the inverse transpose of \( \mathbf T \):
$$ \hat{ \nabla f}(\vec p) = \left ( \mathbf T^{-1} \right )^{T} . \nabla f ( \mathbf T^{-1} \vec p )$$
Code
float transformed_value_and_gradient(Point pos, Vec3& grad) { Point p = T.inverse() * pos; float field_values = distance_field(p, grad); // original field function value grad = T.inverse().transpose() * grad; return field_values; }
Special transformations
Special space transformations such as bending, twisting, warping, wobbling, duplicating, mirroring are also possible and discussed at length in other articles
- Inigo Quilez provides a long list of manipulations (end of article)
- Ronja's tutorials also some other space manipulations
No comments