Signed Distance Fields 1.0
SDFWarpNoise2 Class Reference

Warping of the plane with a vector field built from a simplex noise, inside a disc. More...

#include <sdf.h>

Inheritance diagram for SDFWarpNoise2:
SDFUnary2 SDFNode2

Public Member Functions

 SDFWarpNoise2 (SDFNode2 *, const Vector2 &, double, double, double)
 Create a warping node.
virtual ~SDFWarpNoise2 ()
 Destructor.
virtual double Signed (const Vector2 &) const
 Compute the signed distance.
virtual Vector2 Gradient (const Vector2 &) const
 Compute the gradient of the field.
Vector2 Kernel (const Vector2 &) const
 Compute the displacement vector field.
Vector2 Warped (const Vector2 &) const
 Compute the deformed point \( W(p) = p + d(p) \).
Matrix2 Jacobian (const Vector2 &) const
 Compute the jacobian matrix of the deformation.
double WarpK () const
 Compute the Lipschitz constant of the deformation \( W \).
virtual double K () const
 Compute the Lipschitz constant of the node.
virtual void ComputeCostSigned (const Vector2 &)
 Compute the number of recursive calls to Signed().
virtual int Memory () const
 Return the size of a sub-tree.
virtual SDFNode2 * Copy () const
 Deep copy.
Public Member Functions inherited from SDFUnary2
 SDFUnary2 (SDFNode2 *)
 Create an unary planar node.
virtual ~SDFUnary2 ()
 Destroy the sub-tree.
virtual void SetShaderId (PrimitiveManager &primitives)
 Set up an id for generating GLSL code.
virtual void ResetShaderId ()
 Reset the id for generating GLSL code.
virtual QString GetCostShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to compute the cost of a call to sdf.
virtual int Nodes () const
 Compute the number of nodes in the sub-tree.
Public Member Functions inherited from SDFNode2
 SDFNode2 ()
 Create a generic node.
virtual ~SDFNode2 ()
 Destructor.
virtual bool Inside (const Vector2 &) const
 Check if a point is inside or outside.
virtual QString GetShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to render the node.
virtual QString GetGradientShader (PrimitiveManager &, std::list< QString > &, bool &) const
 Compute the GLSL code to compute the gradient the sdf.
virtual QJsonValue ToJson () const
 Conversion to JavaScript Object Notation.
Box2 GetBox () const
 Return the bounding box of the node.

Protected Member Functions

double Weight (const Vector2 &) const
 Compute the attenuation of the displacement.
Vector2 WeightGradient (const Vector2 &) const
 Compute the gradient of the attenuation of the displacement.

Protected Attributes

SimplexNoiseField2 field
 Random vector field.
Vector2 c
 Center of the disc where space is deformed.
double r
 Radius of the disc.
double amplitude
 Amplitude of the displacement.
double wavelength
 Wavelength of the noise.
Protected Attributes inherited from SDFUnary2
SDFNode2 * e = nullptr
 Sub-tree.
Protected Attributes inherited from SDFNode2
Box2 box = Box2::Infinity
 Box bounding the surface.
double k = 1.0
 Lipschitz constant.
int cost = 1
 Cost of the node.

Additional Inherited Members

Static Public Member Functions inherited from SDFNode2
static SDFNode2 * FromJson (const QJsonValue &json)
 Conversion from JavaScript Object Notation.
Static Protected Attributes inherited from SDFNode2
static constexpr double Epsilon = 0.01
 Small constant used for bounding volumes and as finite-difference step in Gradient().

Detailed Description

Warping of the plane with a vector field built from a simplex noise, inside a disc.

The plane is deformed by the map \( W(p) = p + d(p) \), and the node evaluates the sub-tree at the deformed point, \( f(p) = e(W(p)) \). The displacement field is the product of an amplitude, of an attenuation function and of a random vector field:

\[ d(p) = a \, w(p) \, F(p/\lambda) \]

where \( F \) is a SimplexNoiseField2, whose two components are two evaluations of a simplex noise at shifted points and take their values in \( [-1,1] \), \( \lambda \) is the wavelength and \( a \) the amplitude.

The deformation is limited to the disc of center \( c \) and radius \( r \). The attenuation depends on the distance \( \rho = \|p-c\| \) and is based on the smooth cubic of Cubic::Smooth():

\[ w(p) = 1 - \mathrm{SmoothStep}(\rho, 0, r) = 1 - \mathrm{Smooth}(\rho/r) \]

It equals one at the center, vanishes with a zero derivative on the circle of radius \( r \), and is zero beyond: the deformation is \( C^1 \) and the plane is not modified outside of the disc.

The jacobian matrix of the deformation is

\[ J(p) = I + a \left( F \, \nabla w^t + \frac{w}{\lambda} \, J_F \right) \]

where \( F \) and its jacobian matrix \( J_F \) are evaluated at \( p/\lambda \) (see SimplexNoiseField2::Jacobian()), and \( \nabla w = -\mathrm{Smooth}'(\rho/r) / r \; (p-c)/\rho \). The gradient of the field is \( \nabla f(p) = J(p)^t \, \nabla e(W(p)) \).

The deformation is not necessarily one to one. If WarpK() is smaller than 2, the norm of the derivative of the displacement is smaller than one and the deformation is a diffeomorphism, the determinant of the jacobian being positive. Beyond, the space may fold (for instance an amplitude of 0.15 with a wavelength of 0.7 yields negative determinants), although small foldings are not always produced as the condition is only sufficient. The signed field is Euclidean only where the deformation is an isometry, the Lipschitz constant K() takes into account the stretching.

See also
SDFNoise2, SDFTurbulence2, SimplexNoiseField2, Cubic::Smooth(), SDFWarpTurbulence

Constructor & Destructor Documentation

◆ SDFWarpNoise2()

SDFWarpNoise2::SDFWarpNoise2 ( SDFNode2 * n,
const Vector2 & c,
double r,
double a,
double w )
explicit

Create a warping node.

Parameters
nSub-tree.
cCenter of the disc where space is deformed.
rRadius of the disc, should be strictly positive.
aAmplitude of the displacement.
wWavelength of the noise, should be strictly positive.

Member Function Documentation

◆ Gradient()

Vector2 SDFWarpNoise2::Gradient ( const Vector2 & p) const
virtual

Compute the gradient of the field.

The gradient is \( J(p)^t \, \nabla e(W(p)) \), where \( J \) is the jacobian of the deformation, see Jacobian().

Parameters
pPoint.

Reimplemented from SDFNode2.

◆ Jacobian()

Matrix2 SDFWarpNoise2::Jacobian ( const Vector2 & p) const

Compute the jacobian matrix of the deformation.

The element \( (i,j) \) of the matrix is \( \partial W_i / \partial p_j \), where \( W(p) = p + d(p) \) is the deformation. It is the identity matrix outside of the disc.

Parameters
pPoint.
See also
Gradient(), Warped()

◆ K()

double SDFWarpNoise2::K ( ) const
virtual

Compute the Lipschitz constant of the node.

The constant is the product of the Lipschitz constant of the sub-tree and of that of the deformation, see WarpK().

Reimplemented from SDFUnary2.

◆ Kernel()

Vector2 SDFWarpNoise2::Kernel ( const Vector2 & p) const

Compute the displacement vector field.

The displacement is \( a \, w(p) \, F(p/\lambda) \), and is zero outside of the disc.

Parameters
pPoint.
See also
Warped(), Jacobian()

◆ Memory()

int SDFWarpNoise2::Memory ( ) const
virtual

Return the size of a sub-tree.

Reimplemented from SDFNode2.

◆ Signed()

double SDFWarpNoise2::Signed ( const Vector2 & p) const
virtual

Compute the signed distance.

Parameters
pPoint.

Reimplemented from SDFUnary2.

◆ Warped()

Vector2 SDFWarpNoise2::Warped ( const Vector2 & p) const

Compute the deformed point \( W(p) = p + d(p) \).

Parameters
pPoint.
See also
Kernel()

◆ WarpK()

double SDFWarpNoise2::WarpK ( ) const

Compute the Lipschitz constant of the deformation \( W \).

The spectral norm of the jacobian is bounded by

\[ 1 + |a| \left( \frac{3 \sqrt{2}}{2 r} + \frac{K_F}{\lambda} \right) \]

where \( K_F \) is the Lipschitz constant of the vector field, see SimplexNoiseField2::K(): the first term bounds the variation of the attenuation (the maximum slope of the smooth cubic is 3/2, and the norm of the field is at most \( \sqrt{2} \)), the second one the variation of the field. This is a conservative bound.

◆ Weight()

double SDFWarpNoise2::Weight ( const Vector2 & p) const
protected

Compute the attenuation of the displacement.

The attenuation is one at the center of the disc, and decreases to zero on its boundary with the smooth cubic \( 1 - \mathrm{Smooth}(\rho/r) \); it is zero outside of the disc.

Parameters
pPoint.

◆ WeightGradient()

Vector2 SDFWarpNoise2::WeightGradient ( const Vector2 & p) const
protected

Compute the gradient of the attenuation of the displacement.

The gradient is zero outside of the disc, and at its center where the attenuation is stationary.

Parameters
pPoint.