threejs-worldgen
    Preparing search index...

    Class Precipitation

    GPU rain streaks, snowflakes and splash rings around the camera, driven by a Weather: density from the precipitation rate, rain/sleet/snow from the snow fraction, slant and drift from the wind. All particles of a kind are one instanced draw call, positioned entirely in the vertex shader (wrapped in a box that follows the camera, so they never run out); only splashes are placed on the CPU (they need the ground height).

    const rain = new Precipitation({ weather, camera })
    scene.add(rain.object)
    // each frame: rain.update(time)
    Index
    camera: Camera

    Camera the particles surround.

    ground: ((x: number, z: number) => number) | null

    Ground height for splashes (frame coordinates).

    object: Group<Object3DEventMap> = ...

    Add this to your scene.

    Resolved settings.

    sample: WeatherSample = ...

    Weather read at the camera on the last update.

    uniforms: {
        anchor: UniformNode<"vec3", Vector3>;
        box: UniformNode<"vec3", Vector3>;
        camera: UniformNode<"vec3", Vector3>;
        cycle: UniformNode<"float", number>;
        drift: UniformNode<"vec3", Vector3>;
        flutter: UniformNode<"float", number>;
        rainColor: UniformNode<"color", Color>;
        rainOpacity: UniformNode<"float", number>;
        rainSpeed: UniformNode<"float", number>;
        rainWidth: UniformNode<"float", number>;
        shutter: UniformNode<"float", number>;
        snowColor: UniformNode<"color", Color>;
        snowOpacity: UniformNode<"float", number>;
        snowSize: UniformNode<"float", number>;
        snowSpeed: UniformNode<"float", number>;
        splashOpacity: UniformNode<"float", number>;
        splashSize: UniformNode<"float", number>;
        wind: UniformNode<"vec3", Vector3>;
    } = ...

    Shader uniforms, for advanced tweaks.

    Type Declaration

    • anchor: UniformNode<"vec3", Vector3>

      Camera frame position modulo the box, so particles stay put in the world.

    • box: UniformNode<"vec3", Vector3>

      Box size (2 radius, height, 2 radius).

    • camera: UniformNode<"vec3", Vector3>

      Camera position, render space.

    • cycle: UniformNode<"float", number>

      Animation clock (time modulo 600 s).

    • drift: UniformNode<"vec3", Vector3>

      Accumulated wind drift modulo the box.

    • flutter: UniformNode<"float", number>

      Flutter.

    • rainColor: UniformNode<"color", Color>

      Rain colour.

    • rainOpacity: UniformNode<"float", number>

      Rain opacity.

    • rainSpeed: UniformNode<"float", number>

      Rain fall speed.

    • rainWidth: UniformNode<"float", number>

      Rain width.

    • shutter: UniformNode<"float", number>

      Rain shutter.

    • snowColor: UniformNode<"color", Color>

      Snow colour.

    • snowOpacity: UniformNode<"float", number>

      Snow opacity.

    • snowSize: UniformNode<"float", number>

      Flake size.

    • snowSpeed: UniformNode<"float", number>

      Snow fall speed.

    • splashOpacity: UniformNode<"float", number>

      Splash opacity.

    • splashSize: UniformNode<"float", number>

      Splash size.

    • wind: UniformNode<"vec3", Vector3>

      Current wind velocity (x, 0, z), m/s.

    weather: Weather

    Weather to read.

    • Sets the frame position at render-space zero (floating origin), [x, y, z].

      Parameters

      • origin: readonly number[]

      Returns this

    • Reads the weather at the camera and animates everything to time seconds.

      Parameters

      • time: number

      Returns void