|
Core 1.0
|
Procedural phasor noise in the plane. More...
#include <phasornoise.h>
Public Types | |
| enum class | Profile { Sine , Sawtooth , Triangle , Square } |
| Periodic profiles applied to the phase field. More... | |
Public Member Functions | |
| Phasor2 (const double &=10.0, const double &=8.0, const double &=0.0, const double &=0.0, int=16, unsigned int=0) | |
| Create a phasor noise. | |
| virtual | ~Phasor2 () |
| Empty. | |
| double | Value (const Vector2 &) const override |
| Compute the phasor noise at a given point, in [0,1]. | |
| Vector2 | Phasor (const Vector2 &) const |
| Compute the complex sum of kernels at a given point. | |
| double | Phase (const Vector2 &) const |
| Compute the phase at a given point, in [-π, π]. | |
| double | Gabor (const Vector2 &) const |
| Compute the Gabor noise at a given point, which is the real part of the complex sum. | |
| double | Intensity (const Vector2 &) const |
| Compute the intensity at a given point, which is the modulus of the complex sum. | |
| void | SetProfile (Profile, const double &=0.5) |
| Set the periodic profile applied to the phase. | |
| double | KernelRadius () const |
| Return the radius of the truncated kernels. | |
| virtual double | Orientation (const Vector2 &) const |
| Orientation of the kernels at a given point. | |
| virtual double | Frequency (const Vector2 &) const |
| Frequency of the kernels at a given point. | |
| Public Member Functions inherited from AnalyticScalarField2 | |
| AnalyticScalarField2 (bool=true) | |
| Constructor. | |
| virtual Vector2 | Gradient (const Vector2 &) const |
| Compute the gradient of the field. | |
| virtual Matrix2 | Hessian (const Vector2 &) const |
| Compute the hessian at a given point. | |
| virtual ScalarField2 | Sample (const Array2 &) const |
| Create a discrete scalar field by sampling a given domain. | |
| bool | Inside (const double &) const |
| Check if the value is considered as inside or outside. | |
| void | Curvature (const Vector2 &, double &, double &) const |
| Compute the gaussian and mean curvatures. | |
| virtual Box2 | GetBox () const |
| Return the bounding box. | |
Protected Member Functions | |
| Vector2 | Cell (const Vec2I &, const Vector2 &) const |
| Compute the sum of the complex kernels of a cell at a given point. | |
| double | Periodic (const double &) const |
| Apply the periodic profile to a phase. | |
| Protected Member Functions inherited from AnalyticScalarField2 | |
| Matrix | Local (const Vector2 &) const |
| Compute the local neighborhood in the one-ring aroung a point. | |
Protected Attributes | |
| double | frequency = 10.0 |
| Frequency, number of oscillations per unit length. | |
| double | bandwidth = 8.0 |
| Bandwidth b of the Gaussian envelope \( \exp(-\pi b^2 r^2) \) of the kernels. | |
| double | angle = 0.0 |
| Main orientation of the oscillations, in radians. | |
| double | spread = 0.0 |
| Angular spread factor in [0,1], 0 for an oriented noise, 1 for an isotropic noise. | |
| int | kernels = 16 |
| Number of kernels per cell. | |
| unsigned int | seed = 0 |
| Random seed. | |
| Profile | profile = Profile::Sine |
| Periodic profile. | |
| double | density = 0.5 |
| Duty cycle of the square profile, in [0,1]. | |
| double | radius = 0.0 |
| Radius of the truncated kernels. | |
| Protected Attributes inherited from AnalyticScalarField2 | |
| bool | sign = true |
| Sign convention, used for normal computation. | |
| Box2 | box = Box2::Infinity |
| Domain, set as infinite for base class. | |
Static Protected Attributes | |
| static const double | truncation = 0.01 |
| Value of the Gaussian envelope at the kernel radius. | |
| Static Protected Attributes inherited from AnalyticScalarField2 | |
| static const double | epsilon = 1e-6 |
| \( \varepsilon \) value for first order partial derivatives (gradient). | |
| static const double | epsilonhessian = 1e-4 |
| Larger \( \varepsilon \) value for second order partial derivatives (hessian). | |
Procedural phasor noise in the plane.
Phasor noise is a sparse convolution noise that sums complex Gabor kernels and only keeps the phase of the resulting complex field. Contrary to Gabor noise, whose amplitude fluctuates, the phase field yields oscillations with a constant contrast, and an arbitrary periodic profile (sine, sawtooth, triangle, square) can be applied to it.
After Thibault Tricard, Semyon Efremov, Cédric Zanni, Fabrice Neyret, Jonàs Martínez and Sylvain Lefebvre, Procedural phasor noise, ACM Transactions on Graphics, 38(4), 2019. The reference implementation by the authors is available at https://github.com/mfx-inria/phasornoise.
The complex field is defined as a sum of kernels:
\[ G(\mathbf{p}) = \sum_k \exp\left(-\pi b^2 \|\mathbf{p}-\mathbf{p}_k\|^2\right) \exp\left(i \left(2 \pi f\, \mathbf{d}_k \cdot (\mathbf{p}-\mathbf{p}_k) + \varphi_k\right)\right) \]
where \( \mathbf{p}_k \) are random kernel centers, \( \mathbf{d}_k \) unit directions, \( \varphi_k \) random phases, \( f \) the frequency and \( b \) the bandwidth. The phasor noise is the phase \( \phi(\mathbf{p}) = \arg G(\mathbf{p}) \), and the value of the field is a periodic profile of this phase.
Kernels are truncated at the radius \( r = \sqrt{-\ln(t)/\pi}/b \) where the Gaussian envelope reaches the truncation value t. The plane is partitioned into square cells of size 2r, each one containing a fixed number of kernels with random positions, directions and phases. Because the kernel radius is half the cell size, a point is only influenced by the 2×2 cells closest to it, which makes the evaluation cost equal to four times the number of kernels per cell.
The ratio between frequency and bandwidth controls the number of oscillations within a kernel: with \( f\,r \) about 1.5, kernels hold a few periods, which yields well defined oscillations.
The orientation and the frequency of the kernels can be locally controlled by overloading Phasor2::Orientation() and Phasor2::Frequency(), which are evaluated at the kernel centers.
|
strong |
Periodic profiles applied to the phase field.
| Enumerator | |
|---|---|
| Sine | Sine wave. |
| Sawtooth | Sawtooth, linear ramp of the phase. |
| Triangle | Triangle wave. |
| Square | Square wave, whose duty cycle is defined by the density. |
|
explicit |
Create a phasor noise.
| f | Frequency, number of oscillations per unit length. |
| b | Bandwidth of the Gaussian envelope of the kernels, which should be strictly positive. |
| a | Main orientation of the oscillations, in radians. |
| s | Angular spread factor in [0,1], 0 for an oriented noise, 1 for an isotropic noise. |
| n | Number of kernels per cell. |
| seed | Random seed. |
Compute the sum of the complex kernels of a cell at a given point.
The random number generator of the cell is seeded by hashing the cell coordinates with Vec2I::pcg2d(), combined with the hashed seed of the noise, so that every cell and every seed get an independent sequence of kernels.
| ij | Integer coordinates of the cell. |
| q | Coordinates of the point relative to the cell, scaled so that the cell is the unit square. |
|
virtual |
Frequency of the kernels at a given point.
The default implementation returns the constant frequency; overload this function to define a frequency field.
| p | Point, center of the kernel. |
| double Phasor2::Gabor | ( | const Vector2 & | p | ) | const |
Compute the Gabor noise at a given point, which is the real part of the complex sum.
| p | Point. |
| double Phasor2::Intensity | ( | const Vector2 & | p | ) | const |
Compute the intensity at a given point, which is the modulus of the complex sum.
The phase is ill defined where the intensity is close to zero, which happens at isolated singular points.
| p | Point. |
|
virtual |
Orientation of the kernels at a given point.
The default implementation returns the constant main orientation; overload this function to define an orientation field.
| p | Point, center of the kernel. |
|
protected |
Apply the periodic profile to a phase.
| phi | Phase, in [-π, π]. |
| double Phasor2::Phase | ( | const Vector2 & | p | ) | const |
Compute the phase at a given point, in [-π, π].
| p | Point. |
Compute the complex sum of kernels at a given point.
The real part is a Gabor noise, the argument is the phasor noise.
| p | Point. |
| void Phasor2::SetProfile | ( | Profile | p, |
| const double & | d = 0.5 ) |
Set the periodic profile applied to the phase.
| p | Profile. |
| d | Duty cycle of the square profile, in [0,1], ignored for the other profiles. |
|
overridevirtual |
Compute the phasor noise at a given point, in [0,1].
| p | Point. |
Reimplemented from AnalyticScalarField2.