Skip to content

GodRays

Controls volumetric light shafts (crepuscular rays). The active light is the sun during the day and the moon at night. Shaft color follows the active light, and shafts require clouds.

sky.applyTo(sceneColor, scenePass) composites the effect. Use sky.godRays.enabled to turn it on or off.

Properties

enabled

Type: boolean
Default: true
Units: -

Enables or disables the shaft raymarch. Quality tiers set the initial value.

Not a uniform; assign it directly.


extinction.value

Type: uniform<float>
Default: 0.0002
Units: 1/m

Sets the haze density through which shafts travel. Higher values make shafts denser but shorten their visible range. Typical range: 0–0.001.


maxDistance.value

Type: uniform<float>
Default: 12500
Units: meters

Sets how far the march runs for pixels showing open sky. Pixels showing geometry stop at the surface instead.

Shafts fade at the edge of the cloud-shadow area. Values much larger than that area add uniform haze without extending visible shafts. Typical range: 1,000–20,000.


moonGodRayScale

Type: number
Default: 0.4
Units: -

Scales shaft brightness while the moon is active. Sunlight shafts use strength directly. Typical range: 0–1.

Not a uniform; assign it directly.


sharpness.value

Type: uniform<float>
Default: 2.0
Units: -

Sets shaft contrast. Higher values create sharper streaks; 1 preserves the sampled visibility. Typical range: 1–16.


steps.value

Type: uniform<float>
Default: 24
Units: -

Sets how many samples the march takes along each view ray. This is the dominant cost of the effect. The quality tier sets it, and the demo UI can override it.


strength.value

Type: uniform<float>
Default: 2.0
Units: -

Sets shaft brightness before soft clipping. Higher values make shafts approach the active light's color more quickly.

Shafts are added before exposure and can contribute to bloom. Typical range: 0–8.

Methods

applyParams(params)

Writes any subset of GodRaysParams in one call. Omitted fields are left unchanged.

Returns: void

typescript
sky.godRays.applyParams({
  enabled: true,
  strength: 2.0,
  sharpness: 2.0,
  extinction: 0.0002,
  maxDistance: 12500,
  moonGodRayScale: 0.4,
});

toParams()

Returns a new GodRaysParams containing the current values. Pass it to applyParams to restore the state, or store it in a preset's godRays block.

Returns: GodRaysParams

typescript
const saved = sky.godRays.toParams();
sky.godRays.applyParams({ strength: 5 });
sky.godRays.applyParams(saved); // back to where it was

Types

GodRaysParams

One field per property above, named the same, with the uniform-valued ones dropping the .value. Every field is required — toParams() returns all of them, and applyParams takes Partial<GodRaysParams>. This is also the shape of a preset's godRays block.

There is no steps field: the march budget comes from the quality tier. Raise steps.value directly to override it.

typescript
interface GodRaysParams {
  enabled: boolean;
  strength: number;
  sharpness: number;
  // 1/meters
  extinction: number;
  // meters
  maxDistance: number;
  moonGodRayScale: number;
}
typescript
import type { GodRaysParams } from 'threejs-sky-pro';

Post-Processing Setup

applyTo adds god rays and fog to the post-processing chain:

typescript
import { pass } from "three/tsl";

const scenePass = pass(scene, camera);
const output = sky.applyTo(scenePass.getTextureNode("output"), scenePass);
const pipeline = new THREE.RenderPipeline(renderer, output);

The raymarch reads scene depth and stops at the nearest surface. Clouds also occlude shafts behind them while leaving foreground haze visible. See Post-Processing for the correct placement of applyTo.

Limitations

  • Shadow-map extent. Shafts appear only within the cloud-shadow area, which is an 8 km square around the camera by default. They fade at its boundary. Increase the extent for longer shafts near the horizon; see Shadows.
  • Below-base approximation. The shadow map is a flat top-down lookup, so it over-darkens clear sky above the cloud tops. Shafts are a below-cloud effect, so this rarely shows.
  • Low sun. The shadow bake under-samples at dawn and dusk, which smears shafts slightly at very low sun elevations.

Toggling

typescript
sky.godRays.enabled = false;

See Also

Commercial License - All Rights Reserved.