threejs-worldgen
    Preparing search index...

    Class Rivers

    River water surfaces for a world's noise rivers, streamed in camera-centred tiles.

    Each tile samples the world on a grid; wherever there is river water it builds a surface at the river's level, extended a little so it tucks under the banks. The flow direction comes from the slope of the river surface (with the across-channel part removed), and drives flow-mapped ripples and foam that move downstream. Tiles build within a per-frame time budget, nearest first; most tiles are rejected after a 3×3 probe, and only cells near water are sampled at full resolution. On planets, tiles live in a local frame that is re-centred on the camera every reframeDistance.

    const rivers = await Rivers.create({ camera, scene, renderer, world, maxDistance: 2000 })
    
    Index
    camera: Camera

    Camera the tiles follow.

    frame: LocalFrame

    The frame tiles are built in (the world itself on flat worlds).

    object: Group<Object3DEventMap> = ...

    Root of all river tiles (placed in the current frame).

    settings: RiversSettings

    Resolved settings. Change them with Rivers.set / Rivers.reset.

    stats: RiversStats = ...

    Live counters, refreshed by Rivers.update.

    time: number = 0

    Seconds of flow time.

    uniforms: {
        crest: UniformNode<"float", number>;
        deepColor: UniformNode<"color", Color>;
        detail: UniformNode<"float", number>;
        detailDirection: UniformNode<"vec2", Vector2>;
        detailScale: UniformNode<"float", number>;
        detailSpeed: UniformNode<"float", number>;
        environmentIntensity: UniformNode<"float", number>;
        flowPeriod: UniformNode<"float", number>;
        foam: UniformNode<"float", number>;
        foamColor: UniformNode<"color", Color>;
        foamWidth: UniformNode<"float", number>;
        gridAngle: UniformNode<"float", number>;
        gridMinSpacing: UniformNode<"float", number>;
        gridScale: UniformNode<"float", number>;
        horizonColor: UniformNode<"color", Color>;
        maxArc: UniformNode<"float", number>;
        radius: UniformNode<"float", number>;
        rapids: UniformNode<"float", number>;
        reflectivity: UniformNode<"float", number>;
        refraction: UniformNode<"float", number>;
        roughness: UniformNode<"float", number>;
        shallowColor: UniformNode<"color", Color>;
        skyColor: UniformNode<"color", Color>;
        specular: UniformNode<"float", number>;
        sunColor: UniformNode<"color", Color>;
        sunDirection: UniformNode<"vec3", Vector3>;
        tanHalfFov: UniformNode<"float", number>;
        time: UniformNode<"float", number>;
        visibility: UniformNode<"float", number>;
        waveA: UniformArrayNode<string>;
        waveB: UniformArrayNode<string>;
        waveCount: UniformNode<"int", number>;
        whitecaps: UniformNode<"float", number>;
    } = ...

    Shader uniforms (for advanced tweaks).

    Type Declaration

    • crest: UniformNode<"float", number>

      Σ k·chop of the waves (normalises whitecaps).

    • deepColor: UniformNode<"color", Color>

      deepColor.

    • detail: UniformNode<"float", number>

      detail.

    • detailDirection: UniformNode<"vec2", Vector2>

      Unit drift direction of the ripples (x, z).

    • detailScale: UniformNode<"float", number>

      detailScale, metres.

    • detailSpeed: UniformNode<"float", number>

      detailSpeed, m/s.

    • environmentIntensity: UniformNode<"float", number>

      environmentIntensity.

    • flowPeriod: UniformNode<"float", number>

      Seconds per flow-map cycle (rivers).

    • foam: UniformNode<"float", number>

      foam, 0 … 1.

    • foamColor: UniformNode<"color", Color>

      foamColor.

    • foamWidth: UniformNode<"float", number>

      foamWidth, metres.

    • gridAngle: UniformNode<"float", number>

      Vertex spacing per metre of distance (2π / segments for the ocean rings; 0 = uniform grid).

    • gridMinSpacing: UniformNode<"float", number>

      Smallest vertex spacing, metres. Waves shorter than ~3 spacings fade out in the vertex stage.

    • gridScale: UniformNode<"float", number>

      Multiplier from geometry x/z to tangent-plane metres (the ocean's ring scale).

    • horizonColor: UniformNode<"color", Color>

      horizonColor.

    • maxArc: UniformNode<"float", number>

      Surface distance beyond which vertices are clamped (the horizon on planets).

    • radius: UniformNode<"float", number>

      Sphere radius the surface bends to (sea radius on planets; huge = flat).

    • rapids: UniformNode<"float", number>

      Flow speed (m/s) where river rapids start foaming.

    • reflectivity: UniformNode<"float", number>

      reflectivity (F0).

    • refraction: UniformNode<"float", number>

      refraction.

    • roughness: UniformNode<"float", number>

      roughness.

    • shallowColor: UniformNode<"color", Color>

      shallowColor.

    • skyColor: UniformNode<"color", Color>

      skyColor.

    • specular: UniformNode<"float", number>

      specular.

    • sunColor: UniformNode<"color", Color>

      Sun colour × intensity.

    • sunDirection: UniformNode<"vec3", Vector3>

      Direction towards the sun, world space.

    • tanHalfFov: UniformNode<"float", number>

      tan(fov / 2) of the camera, for the per-pixel detail fade.

    • time: UniformNode<"float", number>

      Seconds, advanced by the owner's update().

    • visibility: UniformNode<"float", number>

      visibility, metres.

    • waveA: UniformArrayNode<string>

      Per wave: direction x, direction z, wavenumber k, amplitude.

    • waveB: UniformArrayNode<string>

      Per wave: horizontal amplitude (chop), phase (radians, includes −ωt), unused, unused.

    • waveCount: UniformNode<"int", number>

      Active entries in waveA/waveB.

    • whitecaps: UniformNode<"float", number>

      Whitecap amount 0 … 1 (oceans and lakes).

    world: World

    The world.

    • Removes the rivers from the scene and frees their GPU resources.

      Returns void

    • Changes settings, merging into earlier ones. Look settings apply instantly; layout and flow settings rebuild tiles (old ones stay until replaced).

      Parameters

      Returns this

    • Moves the floating origin. Same as set({ origin }).

      Parameters

      • origin: readonly number[]

      Returns this

    • Streams tiles around the camera, builds within the time budget and advances the flow. Called automatically when a scene was given (and by <Rivers>); otherwise call it once per frame.

      Parameters

      • delta: number = ...

        Seconds since the last frame; measured if omitted.

      • budget: number = ...

        Milliseconds for tile building this frame. Defaults to settings.buildBudget.

      Returns void