NatureGL Skyv1.1.0

Reference

API reference

Everything exported from src/index.js and build/index.js. The types are in build/*.d.ts.

js
import {
  SkySystem, SkyPostPass, QUALITY_LEVELS, PRESETS, getPresetParams, DEFAULT_PARAMS,
  CLOUD_FORMS, CLOUD_SHADOW_GLSL, patchMaterialWithCloudShadow,
  phaseName, dayPhase, formatClock, lunarAgeNow, SYNODIC,
} from 'naturegl-sky';

#SkySystem

#SkySystem.create(options): Promise<SkySystem>static async

Builds the system, adds the backdrop mesh to options.scene, runs the first LUT, shadow, env and PMREM bakes, and pre-compiles the backdrop. new SkySystem(options) also works; in that case call update(0) before the first render.

OptionTypeDefault
rendererTHREE.WebGLRenderer—Required
sceneTHREE.Scene—Required; the backdrop mesh is added here
cameraTHREE.PerspectiveCamera—Required; the main camera clouds are reconstructed for
quality'low', 'medium', 'high', 'ultra''high'See Quality levels
qualityOverridesPartial<QualitySettings>{}Merged over the tier
cloudRenderingMode'static', 'dynamic''dynamic'static freezes evolution and re-bakes only on change
presetstring or Partial<SkyParams>'marine'Initial sky
metersPerUnitnumber1World units → metres
lightScalenumber0.5Sky radiance → three.js light units (noon sun ≈ 4)
autoExposurebooleantrueWrites renderer.toneMappingExposure every update
maxExposurenumberInfinity1.1 Ceiling for the auto exposure
nightExposurenumber—1.1 Ceiling at full night, blended through dusk
setSceneEnvironmentbooleanfalseKeep scene.environment on environment
shadowExtentnumber8000Cloud shadow map half-width in metres

The renderer should use a tone mapping, since the sky writes linear HDR.

#Frame

#sky.update(dt, opts?): voidmethod

Call once per frame after moving the camera and before rendering. It advances the clock and the eased weather, and updates the sun, moon, ambient, fog and exposure. Then it does the offscreen work: sky-view LUT, cloud shadow map, env slices and PMREM when due, and the cloud march with its temporal resolve. dt is in seconds, clamped to 0.1. opts.forceBakes re-bakes everything now.

#sky.resize(width?, height?): voidmethod

Re-reads the renderer's drawing-buffer size and reallocates the cloud buffers and the post pass. Call it after renderer.setSize. The renderer size is authoritative, and update() also detects size changes on its own.

#sky.setCamera(camera): voidmethod

Switches the main camera. The temporal history is reset.

#sky.dispose(): voidmethod

Removes the backdrop, frees every render target and material, clears scene.environment if the sky set it, and disposes a post pass created by createPostPass.

#Parameters and presets

#sky.loadPreset(preset): voidmethod

Snaps to a preset name or params object. Missing fields take the defaults. There's no easing, the temporal history is reset, and everything re-bakes.

#sky.applyPreset(preset): voidmethod

Transitions to a preset: the targets change and numeric params ease over about 1–2 s.

#sky.setParams(partial, { immediate? }): voidmethod

Merges into the targets. Numeric params ease unless immediate is set.

#sky.getParams(): SkyParamsmethod

Returns a complete, JSON-safe copy of the targets, with numbers rounded to 3 decimals and no view. You can use it as a preset.

#sky.setTime(hours, { immediate? }): voidmethod

Sets the clock (0–24). It eases the short way round unless immediate is set.

#sky.setSunAngles(elevationDeg, azimuthDeg, { immediate? }): voidmethod

Picks the afternoon time at which the sun has this elevation, and sets northOffset so the sun sits at this world azimuth. sky.sun.setFromAngles(...) does the same.

Property
params: SkyParamsThe targets
current: SkyParamsThe eased values actually rendered
presetName: string | nullLast loaded preset (null once edited)
clock: { running, speed }When running, timeOfDay advances speed hours per second (default 24/144)

#Quality and modes

#sky.setQualityLevel(level, overrides?): voidmethod

Switches tier at runtime. Targets are reallocated, history is reset and env/PMREM re-bake. If the PMREM or env texture object changes, scene.environment, scene.background and material envMaps that pointed at the old one are updated, and environmentchange fires. Read back quality (the level name) and qualitySettings (the effective settings).

#sky.setCloudRenderingMode(mode): voidmethod

'static' or 'dynamic'. See Static and dynamic rendering.

Property
taa: booleanTemporal reconstruction on/off (default on). Off gives a plain bilinear upscale of the noisy march; use it for debugging only

#Outputs

PropertyType
sun.directionVector3Unit vector toward the sun (world)
sun.color, sun.intensityColor, numberDirect sunlight at the camera (0 below the horizon)
sun.elevation, sun.azimuthnumberDegrees; azimuth 0 = −Z, 90 = +X
sun.visibilitynumber0–1 cloud shadow at the camera (async GPU probe, ~4 Hz)
moon.direction / color / intensityThe same for the moon
moon.phase, moon.illumination, moon.phaseNamenumber, number, stringSynodic fraction, lit fraction, e.g. 'WAX GIB'
keyLight.direction / color / intensitySun by day, moon once the sun is 6° down
ambient.skyColor / groundColor / intensityFor a HemisphereLight
ambient.colorColorUp-facing irradiance, magnitude included
envMapTextureEquirect HDR sky + clouds (no sun disc)
environmentTexture | nullPMREM of envMap (listen to environmentchange)
cloudShadow.textureTextureTop-down transmittance toward the key light (r)
cloudShadow.matrixMatrix4World position → shadow uv (includes the light shear)
cloudShadow.strengthnumber0–1 scale for patched materials
cloudShadow.uniformsobjectskyCloudShadowMap / Matrix / Strength uniforms to share
fogColor, fogSigmaColor, numberLinear horizon colour; sea-level extinction (1/m)
exposurenumberDisplay exposure after the ceilings
meteredExposurenumber1.1 Raw metered exposure
displayExposurenumber1.1 Exposure in toneMappingExposure units
nightnumber1.1 0 by day … 1 at full night
maxExposure, nightExposurenumber, number | null1.1 The ceilings, mutable
lightningnumberCurrent flash, 0 – 1.5
timeOfDay, dayPhasenumber, stringCurrent eased hour and its name
cloudLayer{ base, top }Deck altitude in metres
uniformsRecord<string, IUniform>Shared sky uniform block (advanced)
backdrop.meshMeshThe sky mesh in your scene
clouds.texture / depthTextureTextureResolved screen-space cloud buffer

#Composition helpers

#sky.bindLights(directional, hemisphere?, opts?): voidmethod

Drives the lights from the sky on every update. opts: distance (default 100), cloudDimming (multiply by sun.visibility), intensityScale (default 1). See Lighting.

#sky.patchMaterial(material): Materialmethod

Adds cloud shadowing to a built-in lit material (Standard, Physical, Lambert, Phong, Toon). It supports instancing and batching, chains onBeforeCompile, and is idempotent.

#sky.createPostPass(options?): SkyPostPassmethod

#Events

SkySystem is a THREE.EventDispatcher.

EventPayloadWhen
change—A preset was loaded or params were set
quality{ level }The tier changed
environmentchange—environment or envMap is a new texture object

#Debug switches

Property
debugRotationOnlyTAAReproject history as if the camera only rotated (the cloudpro method), for comparisons
debugLegacyRender the cloud and sky details the way cloudpro.html did, for before/after comparisons

#SkyPostPass

js
const post = sky.createPostPass({ fog: true, godRays: true, bloom: true, cloudsOverGeometry: true, grade: 1 });
#post.render(scene, camera, target?): voidmethod

Renders the scene into the HDR target with depth, runs bloom and shafts, composites fog, god rays, clouds over geometry and the grade, and tone-maps into target (the screen by default).

#post.composite(colorTexture, depthTexture, camera, target?): voidmethodsince 1.1

Runs the same chain on an HDR render you already have. The colour must be linear and not tone-mapped; the depth is the matching DepthTexture. See Composite.

#post.setSize(w, h): voidmethod

Drawing-buffer size. render calls it automatically.

Member
options{ fog, godRays, bloom, cloudsOverGeometry, grade, msaa }, mutable at runtime
dispose()Frees the targets

#Other exports

Export
PRESETSRecord<string, Partial<SkyParams> & { label }>
getPresetParams(name)Complete, deep-cloned params
DEFAULT_PARAMSThe defaults every preset fills from
CLOUD_FORMSThe six forms, in shader order
QUALITY_LEVELSSee Quality levels
patchMaterialWithCloudShadow(material, uniforms)The function behind sky.patchMaterial
CLOUD_SHADOW_GLSLskyCloudShadow(worldPos) for your own shaders
phaseName(age), dayPhase(hour, elevRad), formatClock(hours), lunarAgeNow(), SYNODICAstronomy helpers

#Units and conventions

  • Space: world units × metersPerUnit = metres. Y is up and sea level is y = 0. Azimuth 0 = −Z, 90° = +X.
  • Light: internal sky radiance uses a sun illuminance of 10. lightScale converts to three.js units for the backdrop, env map, lights, ambient and fog. A white Lambertian surface under the noon sun reads about 4 / π before exposure.
  • Exposure: with autoExposure, the sky sets renderer.toneMappingExposure = exposure / lightScale. Without it, set your own; the sky reads it back.
  • Clock: a real sun track for latitude and declination. The moon rides the same track lunarAge days behind and is lit by the real sun direction. The stars turn about the celestial pole.