threejs-worldgen
    Preparing search index...

    Class Ocean

    A sea-level water surface for flat worlds and planets, at every scale from an ant on the beach to orbit, in one draw call.

    The surface is a camera-centred grid of concentric rings whose radii grow geometrically, so vertices are dense under the camera and sparse at the horizon, and the grid scales with the camera's height. It is built in the local tangent plane under the camera and, on planets, bent onto the sea sphere in the vertex shader (with float32-exact series), clamped at the horizon — so the same mesh covers a beach and a whole hemisphere seen from orbit. Waves are a sum of Gerstner waves whose phases are computed on the CPU in float64, so they stay smooth and stable millions of metres from the origin.

    const ocean = await Ocean.create({ camera, scene, renderer, world, sun, waves: { amplitude: 0.8 } })
    ocean.set({ deepColor: '#06283a', whitecaps: 0.6 }) // live
    floating.onRebase((origin) => ocean.setOrigin(origin)) // floating origin (threejs-biomes FloatingOrigin)
    Index
    camera: Camera

    Camera the grid follows. Can be swapped at any time.

    object: Mesh<
        BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
        MeshBasicNodeMaterial,
    >

    The ocean mesh. Added to scene for you when one is passed to Ocean.create.

    settings: OceanSettings

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

    stats: OceanStats = ...

    Live counters, refreshed by Ocean.update.

    time: number = 0

    Seconds of wave time. Advanced by Ocean.update; set it to sync clients.

    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 | null

    World providing sea level and planet radius, or null to use the seaLevel/radius settings.

    • Removes the ocean from its parent and frees its GPU resources.

      Returns void

    • Changes settings, merging into earlier ones (waves field by field). Colours and most numbers apply instantly; segments/range rebuild the grid.

      Parameters

      Returns this

    • Moves the floating origin: render-space (0, 0, 0) becomes this world position (e.g. from FloatingOrigin.onRebase). Same as set({ origin }).

      Parameters

      • origin: readonly number[]

      Returns this

    • Follows the camera, advances the waves and reads the sun. Called automatically when a scene was given (and by <Ocean>); otherwise call it once per frame.

      Parameters

      • delta: number = ...

        Seconds since the last frame; measured if omitted.

      Returns void

    • The wavy sea surface at a render-space point, for buoyancy and gameplay: how deep the point is under the surface, the surface point and its normal. Uses every wave (no distance fade), at the current Ocean.time.

      Parameters

      Returns OceanSample