melonJS
    Preparing search index...

    Class NoiseTexture2d

    A Texture2d that bakes a Noise field into a drawable canvas — usable directly as a sprite image, a normal map, an image layer, or a custom shader sampler.

    The bake runs on the CPU (renderer-agnostic, works under both the Canvas and WebGL backends) and produces an HTMLCanvasElement returned by NoiseTexture2d#getTexture. Three output modes:

    • grayscale (default) — the noise value mapped to [0, 255].
    • colorRamp — the noise value mapped through a Gradient.
    • asNormalMap — the noise treated as a height field and encoded as tangent-space surface normals (RGB), for per-pixel lighting via Sprite#normalMap + Light2d.

    With seamless: true the texture's edges are cross-faded so it tiles with a much-reduced seam (an approximate, not pixel-exact, wrap); seamlessBlendSkirt controls how wide that edge blend band is. With animated: true the field is sampled in 3D (getNoise3d) using an internal time as the third axis — call NoiseTexture2d#update from your update loop to evolve it. Each re-bake bumps a version the renderer reads, so the GPU texture re-uploads automatically (and only when it actually changed — the three.js Texture.needsUpdate model).

    Note: live re-upload is currently wired through the lit normal-map pipeline (Sprite#normalMap + Light2d). An animated texture used as a plain color image bakes a static snapshot — the color texture cache does not yet honor version — so animate normals, not albedos, for now.

    // a seamless water normal map fed to a lit sprite
    const ripples = new me.NoiseTexture2d({
    width: 256, height: 256,
    type: "simplex", octaves: 4, frequency: 0.03,
    seamless: true, asNormalMap: true, bumpStrength: 2, animated: true, speed: 0.6,
    });
    const water = new me.Sprite(x, y, { image: albedo, normalMap: ripples });
    // drive it yourself from your Stage's update(dt):
    ripples.update(dt);

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionalsettings: {
            animated?: boolean;
            asNormalMap?: boolean;
            bumpStrength?: number;
            colorRamp?: any;
            height?: number;
            invert?: boolean;
            noise?: Noise;
            seamless?: boolean;
            seamlessBlendSkirt?: number;
            speed?: number;
            width?: number;
        } = {}

        configuration; any Noise setting (type, seed, frequency/scale, octaves, gain/persistence, lacunarity, fractalType, domain-warp settings) is forwarded when no noise instance is given.

        • Optionalanimated?: boolean

          sample in 3D (getNoise3d) using an internal time as the third axis, advanced by NoiseTexture2d#update

        • OptionalasNormalMap?: boolean

          encode as a normal map

        • OptionalbumpStrength?: number

          normal steepness when asNormalMap

        • OptionalcolorRamp?: any

          map the noise value to a color

        • Optionalheight?: number

          baked texture height in pixels

        • Optionalinvert?: boolean

          invert the noise value (1 - v)

        • Optionalnoise?: Noise

          an existing Noise to bake; when omitted one is built from the forwarded settings

        • Optionalseamless?: boolean

          tile cleanly in both axes

        • OptionalseamlessBlendSkirt?: number

          edge blend band width as a fraction (0..1) of the smaller dimension, when seamless

        • Optionalspeed?: number

          animation speed in noise z-units per second (only used while animated)

        • Optionalwidth?: number

          baked texture width in pixels

      Returns NoiseTexture2d

    Properties

    animated: boolean

    sample the field in 3D using time as the third axis

    asNormalMap: boolean

    encode the field as a tangent-space normal map

    bumpStrength: number

    normal steepness when asNormalMap

    colorRamp: any

    optional color ramp applied to the noise value

    height: number

    baked texture height in pixels

    invert: boolean

    invert the noise value

    noise: Noise

    the noise field baked by this texture

    seamless: boolean

    tile cleanly in both axes

    seamlessBlendSkirt: number

    edge blend band width (0..1 of the smaller dimension)

    speed: number

    animation speed in noise z-units per second

    time: number

    the current animation time (third sampling axis)

    width: number

    baked texture width in pixels

    Accessors

    Methods

    • Advance an animated texture by dt milliseconds and re-bake it. The re-bake bumps the texture's version, so the renderer re-uploads the GPU texture automatically on the next draw — no renderer/app handle needed.

      This is NOT auto-called by the engine; drive it from your own update loop (e.g. Stage#update) for animated textures. No-op when not animated.

      Parameters

      • dt: number

        elapsed time since the last update, in milliseconds

      Returns NoiseTexture2d

      this texture for chaining