Engine API Reference - v2.24.0-beta.13
    Preparing search index...

    Class DynamicSkyEffect

    The dynamic sky effect: renders the sky of the camera - a day sky of an analytic atmosphere, lit by the sun, a night sky of stars and the moon, and optionally clouds drifting with the wind - in place of the sky of the scene. The time of day is set by the position of the sun, see DynamicSkyEffect#azimuth and DynamicSkyEffect#elevation, and the effect can keep a directional light in sync with it, see DynamicSkyEffect#light.

    The sky has no clouds by default, see DynamicSkyEffect#cloudType. They are a single flat layer of noise (CLOUDTYPE_FLAT), or volumetric clouds ray marched through a layer of 3D noise (CLOUDTYPE_VOLUMETRIC). The volumetric clouds are the expensive part of the sky, and render to a texture of their own, at a reduced resolution by default, see DynamicSkyEffect#cloudResolution. Their noise is generated on the CPU when the clouds are first used.

    The effect also generates the lighting of the scene from its sky: the environment atlas lighting the materials, assigned to Scene#envAtlas, see DynamicSkyEffect#lighting. The cameras without the effect, such as the cameras rendering planar reflections, render the sky of the scene from that environment atlas - a still image of this sky. The effect is not supported in XR.

    The sky does not work together with the volumetric fog of the camera frame, CameraFrame#volumetricFog: the clouds cast no shadows into the fog, and the fog is not lit by the light of the sky.

    The effect is not part of a camera frame by default - construct it and add it to the camera frame of a camera:

    const sky = new DynamicSkyEffect(app.graphicsDevice);
    sky.light = sunEntity.light;
    sky.cloudType = CLOUDTYPE_VOLUMETRIC;
    cameraFrame.addEffect(sky);
    cameraFrame.update();

    Like all effects, its settings apply on the next CameraFrame#update, which a day and night cycle moving the sun calls every frame. The clouds drift with the time of the application.

    Hierarchy (View Summary)

    Index
    atlasSize: number = 512

    The size of the environment atlas the lighting is generated to. Higher values give sharper reflections on glossy surfaces, and a sharper sky of the scene for the cameras without the effect, such as the cameras rendering planar reflections. Defaults to 512.

    azimuth: number = 0

    The azimuth of the sun, in degrees - its compass direction. Defaults to 0.

    cameraFrame: CameraFrame | null = null

    The camera frame the effect is registered with, or null.

    cloudBrightness: number = 0.6

    The brightness of the sunlight falling on the clouds. Defaults to 0.6.

    cloudCoverage: number = 0.45

    The fraction of the sky covered by clouds, 0-1 range, from a clear sky to overcast. Defaults to 0.45.

    cloudHeight: number = 2000

    The altitude of the cloud layer, in meters. Defaults to 2000.

    cloudNightBrightness: number = 0.05

    The brightness of the moonlight on the clouds at night. The moonlight of the DynamicSkyEffect#light is usually much brighter than the moon, to keep the night scene readable - lit by it, the clouds would glow against the dark night sky. Defaults to 0.05.

    cloudOpacity: number = 1

    The opacity of the clouds, 0-1 range. Defaults to 1.

    cloudQuality: number = 0.5

    The quality of the volumetric clouds, 0-1 range - the number of their steps through the cloud layer, from 24 to 64, and toward the light, from 1 to 4, and the fineness of the steps through a cloud. The cost grows about linearly, doubling from 0.5 to 1. Lower values give less defined edges of the clouds and a flatter shading. Defaults to 0.5.

    cloudResolution: number = 0.5

    The resolution the volumetric clouds render at, relative to the resolution of the scene, 0.25-1 range. The clouds are soft, so a reduced resolution saves most of their cost with little loss of detail. The sky blurs them over 3x3 of their texels as it reads them, smoothing the grain of their steps, so lower values also soften the clouds. Defaults to 0.5.

    cloudSize: number = 8000

    The distance in meters over which the cloud pattern repeats. Larger values give larger clouds. Defaults to 8000.

    cloudSoftness: number = 0.7

    The softness of the clouds, 0.01-1 range. Lower values give dense clouds with crisp edges and deep shadows, higher values thin them into translucent, wispy clouds with softer shading. Defaults to 0.7.

    cloudSunDimming: number = 0.6

    The fraction of the sunlight the clouds block at the full coverage, dimming the DynamicSkyEffect#light. Defaults to 0.6.

    cloudThickness: number = 2500

    The thickness of the layer of the volumetric clouds, in meters, above their DynamicSkyEffect#cloudHeight. Defaults to 2500.

    cloudType: string = CLOUDTYPE_NONE

    The type of the clouds of the sky, CLOUDTYPE_NONE, CLOUDTYPE_FLAT or CLOUDTYPE_VOLUMETRIC. Defaults to CLOUDTYPE_NONE.

    The graphics device.

    elevation: number = 25

    The elevation of the sun above the horizon, in degrees. Negative values place the sun below the horizon, which gives the night sky. Defaults to 25.

    enabled: boolean = true

    Whether the effect is enabled. An effect can additionally disable itself from its own parameters, see CameraFrameEffect#active.

    light: LightComponent | null = null

    The directional light kept in sync with the sun - its direction, color and intensity. By day it shines from the sun, at DynamicSkyEffect#sunIntensity, dimmed by the clouds, and at night it fades to the moonlight, see DynamicSkyEffect#moonIntensity. Defaults to null.

    lighting: boolean = true

    Whether the effect generates the lighting of the scene from its sky - the environment atlas lighting the materials, assigned to Scene#envAtlas. Only one effect should do so, the one of the main camera. The lighting is generated when the effect is first used, and again when the sun moves by DynamicSkyEffect#lightingThreshold, when a setting of the sky changes by more than a percent, when the clouds drift by DynamicSkyEffect#lightingCloudThreshold, and when DynamicSkyEffect#bakeLighting is called. The clouds are a still image in the lighting, and the sun disc is left out of it, as the DynamicSkyEffect#light carries the light of the sun. Defaults to true.

    lightingCloudThreshold: number = 0

    The distance the clouds drift by, as a fraction of the DynamicSkyEffect#cloudSize, before the lighting is generated again, so the clouds in it follow the clouds of the sky. A value of 0 disables it, and the drift of the clouds does not generate the lighting again. Defaults to 0.

    lightingInterpolation: boolean = false

    Whether the lighting blends from its previous update to its latest one, instead of changing at once. While the sky changes gradually, such as with an animated time of day, each update blends in over the time since the previous one, up to a second, so the lighting follows the sky smoothly, about one update behind it. Without it, the lighting steps at each update, which shows as flicker in the reflections of a quickly changing sky on glossy surfaces, such as water. Sudden changes, such as a jump of the time of day, and DynamicSkyEffect#bakeLighting, still apply at once. It costs two more environment atlases of memory, and a small pass each frame while the lighting blends, so enable it only when the sky changes continuously. Defaults to false.

    lightingResolution: number = 256

    The resolution of the sky the lighting is generated from, the size of the faces of a cubemap, in texels. The sky is filtered down from it to the environment atlas, so it should be well above the resolution of the atlas: at lower values, the detail of the clouds aliases, and their reflections flicker on each update of the lighting as the clouds drift. Defaults to 256.

    lightingThreshold: number = 0.5

    The angle the sun moves by, in degrees, before the lighting is generated again - keeping the cost of a day and night cycle down. Defaults to 0.5.

    luminance: number = 1

    The brightness of the sky, relative to the light of the sun. At 1, the sky lights the scene with about a tenth of the light of the sun, as a clear sky does, at any elevation of the sun: the blue sky and the ground lit by the sun are then of a similar brightness, so a single exposure suits both. Lower values give a deeper sky, higher values a brighter one, and a brighter ambient light of the scene. Defaults to 1.

    mieCoefficient: number = 0.005

    The amount of the Mie (aerosol) scattering, 0-0.1 range, setting the brightness of the glow around the sun. Defaults to 0.005.

    mieDirectionalG: number = 0.8

    The directional anisotropy of the Mie scattering, 0-1 range, setting how tightly the glow hugs the sun. Defaults to 0.8.

    moonColor: Color = ...

    The color of the moonlight, and of the moon disc. Defaults to a pale blue.

    moonDirection: Vec3 = ...

    The direction toward the moon, in the world space, turned by the DynamicSkyEffect#rotation of the sky. It does not need to be normalized. Defaults to a direction high in the sky.

    moonGlow: number = 3

    The brightness of the moon disc in the night sky. Defaults to 3.

    moonIntensity: number = 1

    The intensity of the DynamicSkyEffect#light at night - the moonlight, a dim cool light from the direction of the moon. Defaults to 1.

    moonSize: number = 0.6

    The angular radius of the moon disc, in degrees. Defaults to 0.6.

    nightBrightness: number = 0.052

    The brightness of the night sky. Defaults to 0.052.

    nightColor: Color = ...

    The color of the night sky. Defaults to a deep blue.

    rayleigh: number = 1.5

    The amount of the Rayleigh scattering, 0-4 range, setting the blueness of the sky. Defaults to 1.5.

    rotation: number = 0

    The rotation of the whole sky around the vertical axis, in degrees. It is added to the azimuth of the sun, so the sky, the sun and the moon turn together, along with the light and the shadows it casts. Defaults to 0.

    starBrightness: number = 0.05

    The brightness of the stars. A value of 0 disables them. Defaults to 0.05.

    starDensity: number = 0.8

    The density of the stars, 0-1 range - the fraction of the cells of the sky holding a star. Defaults to 0.8.

    starSize: number = 0.5

    The scale of the size of the stars. Defaults to 0.5.

    sunIntensity: number = 2

    The intensity of the light of the sun: of the DynamicSkyEffect#light with the sun above the horizon, and of the sunlit clouds. The sky scales with it too, see DynamicSkyEffect#luminance, so it sets the brightness of the whole day, to match the exposure of the camera. Defaults to 2, a sunny day at an exposure of 1.

    turbidity: number = 2

    The haziness of the atmosphere, 1-20 range. Higher values give a milkier sky and a larger glow around the sun. Defaults to 2.

    twilightGlow: number = 0.52

    The strength of the warm glow at the horizon while the sun is just below it. Defaults to 0.52.

    windDirection: number = 45

    The direction the clouds drift toward, in degrees around the vertical axis. Defaults to 45.

    windSpeed: number = 10

    The speed the clouds drift with, in meters per second. Defaults to 10.

    • get cameraExposureScale(): number

      Gets the scale the effect applies to the exposure of the camera this frame, multiplying the exposure of the scene, or of the physical camera with physical units - for effects adapting the exposure to what the camera sees. Read every frame while the effect takes part, after CameraFrameEffect#frameUpdate; the camera frame applies the product of the scales of the effects taking part, and the camera renders with its own exposure again once none does. Defaults to 1.

      // an effect brightening the image by one stop
      get cameraExposureScale() {
      return 2;
      }

      Returns number

    • get chunkName(): string

      Gets the name the compose chunk can be overridden under in ShaderChunks, the same way as the built-in chunks. Derived from the id as compose<Id>PS unless given.

      Returns string

    • get defineName(): string

      Gets the define set on the compose shader while the effect is active: the id in upper snake case, colorEnhance giving COLOR_ENHANCE.

      Returns string

    • get entryPoint(): string

      Gets the name of the function the composition calls at the effect's slot. Derived from the id as apply<Id> unless given. The signature depends on the slot: colour slots take (vec3 color, vec2 uv) and return the colour, COMPOSESLOT_SCENE takes and returns a vec4.

      Returns string

    • get requires(): string[]

      Gets the frame resources the effect needs, the FRAMERESOURCE_* constants - for its passes, or for its compose chunk, such as the scene depth. The camera frame provides them while the effect is active. Requirements which depend on the device are computed when constructing the effect; override this as a getter when they depend on a parameter, and the camera frame provides what it returns from the next CameraFrame#update.

      Returns string[]

    • get slot(): string | null

      Gets the compose slot the entry function is called at, or null for an effect that does not take part in the composition.

      Returns string | null

    • Destroys the effect, removing it from its camera frame if it is still registered and releasing everything it owns, the passes it created included. Subclasses which create resources in their constructor release them in an override, calling super.destroy(). The removal takes effect for the frames rendered after the next CameraFrame#update, which is due before the next frame renders.

      Returns void

    • Sets a define on the compose shader. The define persists until changed, so fixed defines can be set once in the constructor and those depending on the parameters from CameraFrameEffect#update. A value of false, null or undefined removes it. Changing a define rebuilds the compose shader.

      Parameters

      • name: string

        The define name.

      • value: any

        The value.

      Returns void