On this page
  1. tecs.math.noise
  2. Module contents
    1. Constructors
    2. Types
  3. Constructors
    1. new
  4. Types
    1. Algorithm
    2. Fractal
    3. Noise
    4. Options

tecs.math.noise

Native procedural scalar fields in two and three dimensions.

local terrain <const> = tecs.math.noise.new({
    algorithm = "perlin",
    fractal = "fbm",
    seed = 1234,
    frequency = 0.01,
    octaves = 4,
})

local height <const> = terrain:sample2(worldX, worldY)

A field is immutable after construction. The seed, algorithm, and options therefore determine every sample, and sampling carries no snapshot state. fill2 crosses into native code once for a complete row-major grid and reuses native scratch storage when the same field fills another grid.

FastNoise Lite supplies the algorithms. Its output is stable within the version Tecs pins, but upgrading that dependency may change a generated field. Persist the seed and options rather than generated values only when accepting that versioned behavior.

Module contents

Constructors

Constructor Description
new Creates an immutable native procedural field.

Types

Type Kind Description
Algorithm enum Selects the native scalar-field algorithm.
Fractal enum Selects how the field combines frequency octaves.
Noise record Represents an immutable native procedural field.
Options record Configures one immutable native noise field.

Constructors

tecs.math.noise.new Static

Creates an immutable native procedural field.

Invalid enum names, non-finite numeric options, a seed outside the signed 32-bit range, an octave count outside 1..32, or a weighted strength outside [0, 1] raise at the call site.

function tecs.math.noise.new(options: Options): Noise

Arguments

Name Type Description
options Options The field configuration. Nil takes every documented default.

Returns

Type Description
Noise A field whose native allocation the Lua collector releases.

Types

tecs.math.noise.Algorithm enum

Selects the native scalar-field algorithm.

enum tecs.math.noise.Algorithm
    "cellular"
    "perlin"
    "simplex"
    "simplexSmooth"
    "value"
    "valueCubic"
end

tecs.math.noise.Fractal enum

Selects how the field combines frequency octaves.

enum tecs.math.noise.Fractal
    "fbm"
    "none"
    "pingPong"
    "ridged"
end

tecs.math.noise.Noise record

Represents an immutable native procedural field.

record tecs.math.noise.Noise
    fill2: function(
        self,
        values: {number},
        width: integer,
        height: integer,
        originX: number,
        originY: number,
        stepX: number,
        stepY: number
    ): {number}
    sample2: function(self, x: number, y: number): number
    sample3: function(self, x: number, y: number, z: number): number
end

tecs.math.noise.Noise:fill2 Instance

Fills a list with a row-major two-dimensional grid.

Rows advance by stepY; columns advance by stepX. The method replaces indices 1..width*height, removes any old trailing entries, and retains the table and native scratch allocation for reuse.

function tecs.math.noise.Noise.fill2(
    self,
    values: {number},
    width: integer,
    height: integer,
    originX: number,
    originY: number,
    stepX: number,
    stepY: number
): {number}
Arguments
Name Type Description
self Noise
values {number} The caller-owned list the method fills and returns.
width integer The number of columns, as an integer in [0, 2147483647].
height integer The number of rows, as an integer in [0, 2147483647].
originX number The first column's coordinate. Defaults to zero.
originY number The first row's coordinate. Defaults to zero.
stepX number The coordinate distance between columns. Defaults to one.
stepY number The coordinate distance between rows. Defaults to one.
Returns
Type Description
{number} values itself after replacing its contents.

tecs.math.noise.Noise:sample2 Instance

Samples the field at a two-dimensional coordinate.

function tecs.math.noise.Noise.sample2(
    self, x: number, y: number
): number
Arguments
Name Type Description
self Noise
x number A finite horizontal coordinate, scaled by the field's frequency.
y number A finite vertical coordinate, scaled by the field's frequency.
Returns
Type Description
number A value in [-1, 1].

tecs.math.noise.Noise:sample3 Instance

Samples the field at a three-dimensional coordinate.

function tecs.math.noise.Noise.sample3(
    self, x: number, y: number, z: number
): number
Arguments
Name Type Description
self Noise
x number A finite horizontal coordinate, scaled by the field's frequency.
y number A finite vertical coordinate, scaled by the field's frequency.
z number A finite depth coordinate, scaled by the field's frequency.
Returns
Type Description
number A value in [-1, 1].

tecs.math.noise.Options record

Configures one immutable native noise field.

record tecs.math.noise.Options
    algorithm: Algorithm
    fractal: Fractal
    seed: integer
    frequency: number
    octaves: integer
    lacunarity: number
    gain: number
    weightedStrength: number
    pingPongStrength: number
end

tecs.math.noise.Options.algorithm field

Caller-writable. Selects the field algorithm. Defaults to "perlin".

tecs.math.noise.Options.algorithm: Algorithm

tecs.math.noise.Options.fractal field

Caller-writable. Selects octave composition. Defaults to "none".

tecs.math.noise.Options.fractal: Fractal

tecs.math.noise.Options.seed field

Caller-writable. Selects the repeatable field. Defaults to 0x5EED1234.

tecs.math.noise.Options.seed: integer

tecs.math.noise.Options.frequency field

Caller-writable. Scales every coordinate before sampling. Defaults to 0.01.

tecs.math.noise.Options.frequency: number

tecs.math.noise.Options.octaves field

Caller-writable. Sets the octave count for a fractal field. Defaults to three.

tecs.math.noise.Options.octaves: integer

tecs.math.noise.Options.lacunarity field

Caller-writable. Multiplies frequency between octaves. Defaults to two.

tecs.math.noise.Options.lacunarity: number

tecs.math.noise.Options.gain field

Caller-writable. Multiplies amplitude between octaves. Defaults to 0.5.

tecs.math.noise.Options.gain: number

tecs.math.noise.Options.weightedStrength field

Caller-writable. Lets one octave's value influence the next octave's amplitude. Defaults to zero and accepts values in [0, 1].

tecs.math.noise.Options.weightedStrength: number

tecs.math.noise.Options.pingPongStrength field

Caller-writable. Sets the fold strength for "pingPong". Defaults to two.

tecs.math.noise.Options.pingPongStrength: number