hex-world
    Preparing search index...

    Class SunShadowRig

    A directional sun light with a shadow frustum that re-fits itself to the camera's ground footprint every frame — the counterpart to chunk streaming, where a static world-sized frustum would either waste the whole shadow map on unloaded chunks or miss the view entirely.

    Per update the visible ground area (frustum corners projected onto the ground plane, clamped to maxDistance) is wrapped in a bounding sphere and the ortho shadow camera is fitted to it. The fitted window is snapped to whole shadow-map texels in light space so panning the camera doesn't make shadow edges shimmer.

    The sun direction is mutable via setDirection so a day/night cycle can drive it; keep the terrain material's uLightDir in sync (HexWorld's setSunDirection does both).

    renderer.shadowMap.enabled = true;
    renderer.shadowMap.type = THREE.PCFSoftShadowMap;
    const rig = new SunShadowRig().addTo(scene);
    // per frame, after camera controls update:
    rig.update(camera);
    Index

    Constructors

    Properties

    light: DirectionalLight

    Accessors

    • get direction(): Vector3

      Current normalized direction pointing toward the sun.

      Returns Vector3

    Methods

    • Add the light AND its target to a scene (the target must be in the graph for the light to track it).

      Parameters

      • parent: Object3D

      Returns this

    • Point the sun. dirTowardSun points from the scene toward the sun (day/night hook).

      Parameters

      • dirTowardSun: Vector3

      Returns void

    • Toggle shadow casting. Materials recompile automatically on change.

      Parameters

      • enabled: boolean

      Returns void

    • Re-fit the shadow frustum to the camera's view of the ground plane. Call once per frame after camera controls update, before rendering.

      Parameters

      • camera: Camera

      Returns void