warp.curlnoise#

warp.curlnoise(
state: uint32,
xy: vec2f,
octaves: uint32,
lacunarity: float32,
gain: float32,
) vec2f#
  • Kernel

  • Python

  • Differentiable

Sample a divergence-free 2D vector field derived from Perlin noise.

Its continuous flow preserves area, although numerical advection may not.

Octave i uses frequency lacunarity ** i and weight gain ** i. With lacunarity > 1 and 0 < gain < 1, later octaves add finer, weaker detail. Contributions may cancel, so magnitude is not monotonic in the octave controls. Scale the coordinate for feature size and the result for speed.

state selects the field and is not advanced. For a given Warp version and device backend, results are deterministic for fixed inputs. Exact values may differ between CPU and CUDA or change between Warp versions. This function is differentiable with respect to the coordinate. Currently, lacunarity and gain receive no gradient.

Parameters:
  • state – RNG state that selects the noise field (see rand_init()); never advanced.

  • xy – Coordinate to sample.

  • octaves – Number of noise octaves to sum. Zero returns a zero vector.

  • lacunarity – Frequency multiplier between successive octaves.

  • gain – Amplitude multiplier between successive octaves.

Returns:

A rotated Perlin-noise gradient at xy. The resulting vector field is analytically divergence-free. The vector is not normalized.

Example

@wp.kernel
def advect(seed: int, positions: wp.array[wp.vec2], dt: float):
    tid = wp.tid()
    state = wp.rand_init(seed)
    positions[tid] = positions[tid] + wp.curlnoise(state, positions[tid]) * dt

positions = wp.array([[0.5, 0.5], [1.25, 2.0]], dtype=wp.vec2)

wp.launch(advect, dim=len(positions), inputs=[42, positions, 0.1])
warp.curlnoise(
state: uint32,
xyz: vec3f,
octaves: uint32,
lacunarity: float32,
gain: float32,
) vec3f
  • Kernel

  • Python

  • Differentiable

Sample a divergence-free 3D vector field derived from Perlin noise.

See curlnoise() for shared behavior, restrictions, and a usage example.

Parameters:
  • state – RNG state that selects the noise field (see rand_init()); never advanced.

  • xyz – Coordinate to sample.

  • octaves – Number of noise octaves to sum. Zero returns a zero vector.

  • lacunarity – Frequency multiplier between successive octaves.

  • gain – Amplitude multiplier between successive octaves.

Returns:

A warp.vec3 containing the spatial curl of three Perlin-noise potentials at xyz. The resulting vector field is divergence-free. The vector is not normalized.

warp.curlnoise(
state: uint32,
xyzt: vec4f,
octaves: uint32,
lacunarity: float32,
gain: float32,
) vec3f
  • Kernel

  • Python

  • Differentiable

Sample a divergence-free 3D vector field that also varies along a fourth axis.

The fourth input axis parametrizes the field and is commonly used as time. See curlnoise() for shared behavior, restrictions, and a usage example.

Parameters:
  • state – RNG state that selects the noise field (see rand_init()); never advanced.

  • xyzt – Coordinate to sample, with the fourth component usually time.

  • octaves – Number of noise octaves to sum. Zero returns a zero vector.

  • lacunarity – Frequency multiplier between successive octaves.

  • gain – Amplitude multiplier between successive octaves.

Returns:

A warp.vec3 containing the spatial curl of three Perlin-noise potentials at xyzt. The vector field is divergence-free in the first three axes. The vector is not normalized.