hex-world
    Preparing search index...

    Class PrecipitationLayer

    A camera-following volume of GPU-animated rain streaks or snowflakes.

    The volume (an area × height × area box) is repositioned to the camera target each frame, but the particles inside are world-anchored (see the vertex-shader note), so panning never drags precipitation along — drops fall over the same hexes regardless of the camera. All motion (fall, wind, snow sway, streaks) runs in the vertex shader from a single time uniform; per-frame CPU cost is two uniform writes.

    Pair with the terrain's cloud shadows through setCloudGate (a WeatherSystem does this automatically) so rain only falls under the denser clouds, and lighter clouds are just clouds.

    const rain = new PrecipitationLayer({ type: 'rain' }).addTo(scene);
    // per frame:
    rain.update(dt, controls.targetPosition);
    Index

    Constructors

    Properties

    object:
        | LineSegments<
            BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
            Material<MaterialEventMap> | Material<MaterialEventMap>[],
            Object3DEventMap,
        >
        | Points<
            BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>,
            Material<MaterialEventMap> | Material<MaterialEventMap>[],
            Object3DEventMap,
        >

    The drawable — LineSegments for rain, Points for snow. Already added by addTo.

    Accessors

    Methods

    • Add the layer to a scene (or any parent).

      Parameters

      • parent: Object3D

      Returns this

    • Fade precipitation: scales how many particles are drawn (drawRange — no reallocation) and their opacity, so weather can ramp smoothly from drizzle to downpour.

      Parameters

      • intensity: number

      Returns void

    • Set the horizontal wind drift (world units/sec). Streak direction follows.

      Safe to call every frame with a gusting wind: the drift it feeds is integrated in update, so a change of wind bends the fall from where it had got to rather than displacing the whole field.

      Parameters

      • wind: Vector2

      Returns void

    • Link (or unlink) precipitation to a cloud field: only where the field exceeds the coverage threshold does precipitation fall. Pass the SAME offset/scale the terrain cloud shadows use, and a coverage at or below the shadows' coverage — the difference is the "clouds that are just clouds" margin.

      Parameters

      • gate: { enabled: boolean; offset?: Vector2; scale?: number; coverage?: number }

      Returns void

    • Keep the cloud gate's drift in sync (called per frame by WeatherSystem).

      Parameters

      • offset: Vector2

      Returns void

    • Per-cell weather mask: a texture whose selected channel scales precipitation at each world position. rect is the world-space span of the texture (min corner + size). Pass null to clear.

      The seasons layer drives this with a ClimateData texture: snow gates on the snow channel ('b') and rain on the same channel inverted, so precipitation falls as snow exactly where snow is lying and as rain everywhere else, with no band where both or neither appear.

      Parameters

      • texture: Texture<unknown, TextureEventMap> | null
      • Optionalrect: { x: number; z: number; width: number; depth: number }
      • opts: { channel?: "r" | "a" | "b" | "g"; invert?: boolean } = {}

      Returns void

      snow.setMask(climate.texture, worldRect, { channel: 'b' });
      rain.setMask(climate.texture, worldRect, { channel: 'b', invert: true });
    • Advance the animation and recenter the volume — call once per frame with the camera's ground target (e.g. RtsCameraController.targetPosition).

      Parameters

      • dt: number
      • center: { x: number; y?: number; z: number }

      Returns void