hex-world
    Preparing search index...

    Class GodRays

    Crepuscular rays: light shafts fanning out from the sun around whatever blocks it — a ridgeline, a forest, a cliff edge.

    The pass is the cheap classic. The scene is re-rendered at a fraction of the resolution with every material replaced by flat black on a white clear, which costs a depth-only-ish pass and yields a mask of where the sky is visible. Each pixel of a full-screen quad then marches that mask toward the sun's screen position, accumulating open sky with a per-step decay, and the result is added to the frame.

    Deliberately not a composer: the main render never goes through a target, so the renderer's MSAA survives and nothing re-encodes an already-final image. Call GodRays.render straight after your own renderer.render(scene, camera).

    It is a sink, not a clock, exactly like SkyDome — feed it a DayNightState (directly, or by naming it as a DayNightCycle target) and it takes the sun from the same source the dome draws it from, so the shafts always start where the sun disc is. Scattered light is what these are, so they scale with daylight and die out under overcast: no shafts from the moon, none through a solid cloud deck. When the gate closes the whole pass is skipped, so a night frame costs nothing.

    const rays = new GodRays({ sky });
    // per frame:
    cycle.applyTo({ sunRig, terrainMaterial, sky, godRays: rays });
    renderer.render(scene, camera);
    rays.render(renderer, scene, camera);
    Index

    Constructors

    Properties

    material: ShaderMaterial

    Accessors

    • get enabled(): boolean

      Whether the rays are drawn at all.

      Returns boolean

    • get resolutionScale(): number

      Occlusion buffer size as a fraction of the drawing buffer.

      Returns number

    • get sunScreenPosition(): Vector2

      The sun's position on screen in uv (0–1, y up), the point the shafts fan out from — hand it to a lens flare to put the two in the same place. Reused between calls; may fall outside 0–1 with the sun off frame.

      Returns Vector2

    Methods

    • Show or hide the rays.

      Parameters

      • enabled: boolean

      Returns void

    • Swap (or drop, with null) the dome the rays belong to — the overcast gate and the mesh kept out of the occlusion pass move with it.

      Parameters

      Returns void

    • Stop an object from blocking the light (particles, overlays, your own sky).

      Parameters

      • object: Object3D

      Returns void

    • Let an excluded object block the light again.

      Parameters

      • object: Object3D

      Returns void

    • Point the rays by hand — the standalone path for scenes without a day/night cycle. dirTowardSun is the same vector the sky dome's sun is drawn along, so the shafts start at the disc.

      Parameters

      • dirTowardSun: Vector3
      • Optionalcolor: Color
      • daylight: number = 1

      Returns void

    • Adopt one moment of a DayNightCycle. Named as the cycle's godRays target this is called for you every frame.

      It takes sunDir, never lightDir: the moon is the active light after dark and pointing the shafts at it would fan them from the wrong side of the sky. Below the horizon the sun's own height closes the gate instead.

      Parameters

      Returns void

    • How overcast the sky reads, 0–1 — a WeatherSystem's overcast, making this an overcast target like the dome. With a dome attached its value wins, since the weather already drives it there.

      Parameters

      • overcast: number

      Returns void

    • Recompute everything the composite reads — the sun's screen position, the ray color, the gain — and return the resulting GodRays.strength. GodRays.render calls this itself; reach for it directly only to drive something else off the same numbers.

      Parameters

      • camera: Camera

      Returns number

    • Draw the rays over the frame. Call after renderer.render(scene, camera) with the same three arguments — the pass reads the scene again for its occlusion mask and adds to the image already on the canvas.

      A no-op while the gate is shut (night, heavy overcast, sun behind you), so there is nothing to switch off outside daylight.

      Parameters

      • renderer: WebGLRenderer
      • scene: Scene
      • camera: Camera

      Returns void

    • Free the occlusion buffer, the quad, and the override material.

      Returns void