import { type AbstractEngine } from "@babylonjs/core/Engines/abstractEngine.pure.js"; import { AtmospherePerCameraVariables } from "./atmospherePerCameraVariables.js"; import { AtmospherePhysicalProperties } from "./atmospherePhysicalProperties.js"; import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.pure.js"; import { type Camera } from "@babylonjs/core/Cameras/camera.pure.js"; import { type DeepImmutable, type Nullable } from "@babylonjs/core/types.js"; import { DiffuseSkyIrradianceLut } from "./diffuseSkyIrradianceLut.js"; import { type DirectionalLight } from "@babylonjs/core/Lights/directionalLight.pure.js"; import { type Effect } from "@babylonjs/core/Materials/effect.pure.js"; import { type IAtmosphereOptions } from "./atmosphereOptions.js"; import { type IColor3Like, type IVector3Like } from "@babylonjs/core/Maths/math.like.js"; import { type IDisposable, type Scene } from "@babylonjs/core/scene.pure.js"; import { Observable } from "@babylonjs/core/Misc/observable.pure.js"; import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTargetTexture.pure.js"; import { TransmittanceLut } from "./transmittanceLut.js"; import { UniformBuffer } from "@babylonjs/core/Materials/uniformBuffer.js"; /** * Renders a physically based atmosphere. * Use {@link IsSupported} to check if the atmosphere is supported before creating an instance. * @experimental */ export declare class Atmosphere implements IDisposable { readonly name: string; readonly scene: Scene; private readonly _directionToLight; private readonly _tempSceneAmbient; private readonly _engine; private readonly _isDiffuseSkyIrradianceLutEnabled; private _physicalProperties; private _transmittanceLut; private _diffuseSkyIrradianceLut; private _isSkyViewLutEnabled; private _isAerialPerspectiveLutEnabled; private _aerialPerspectiveTransmittanceScale; private _aerialPerspectiveSaturation; private _aerialPerspectiveIntensity; private _aerialPerspectiveRadianceBias; private _diffuseSkyIrradianceDesaturationFactor; private _additionalDiffuseSkyIrradianceIntensity; private _additionalDiffuseSkyIrradianceColor; private _additionalDiffuseSkyIrradiance; private _diffuseSkyIrradianceIntensity; private _multiScatteringIntensity; private _groundAlbedo; private _minimumMultiScatteringColor; private _minimumMultiScatteringIntensity; private _lights; private _atmosphereUbo; private _minimumMultiScattering; private _cameraAtmosphereVariables; private _isLinearSpaceComposition; private _isLinearSpaceLight; private _lightRadianceAtCamera; private _linearLightColor; private _originHeight; private _applyApproximateTransmittance; private _exposure; private _atmosphereUniformBufferAsArray; private _effectRenderer; private _skyRenderingGroup; private _aerialPerspectiveRenderingGroup; private _globeAtmosphereRenderingGroup; private _isEnabled; private _aerialPerspectiveLutHasBeenRendered; private _hasRenderedMultiScatteringLut; private _hasEverRenderedMultiScatteringLut; private _multiScatteringEffectWrapper; private _multiScatteringLutRenderTarget; private _aerialPerspectiveLutEffectWrapper; private _aerialPerspectiveLutEffectRenderer; private _aerialPerspectiveLutRenderTarget; private _skyViewLutEffectWrapper; private _skyViewLutEffectRenderer; private _skyViewLutRenderTarget; private _aerialPerspectiveCompositorEffectWrapper; private _skyCompositorEffectWrapper; private _globeAtmosphereCompositorEffectWrapper; private _onBeforeCameraRenderObserver; private _onBeforeRenderObserver; private _onBeforeDrawPhaseObserver; private _onAfterRenderingGroupObserver; /** * Checks if the {@link Atmosphere} is supported. * @param engine - The engine to check. * @returns True if the atmosphere is supported, false otherwise. */ static IsSupported(engine: AbstractEngine): boolean; /** * The unique ID of this atmosphere instance. */ readonly uniqueId: number; private readonly _materialPluginName; /** * Called after the atmosphere variables have been updated for the specified camera. */ readonly onAfterUpdateVariablesForCameraObservable: Observable; /** * Called immediately before the light variables are finalized. */ readonly onBeforeLightVariablesUpdateObservable: Observable; /** * Called before the LUTs are rendered for this camera. This happens after the per-camera UBO update. */ readonly onBeforeRenderLutsForCameraObservable: Observable; /** * Called after the LUTs were rendered. */ readonly onAfterRenderLutsForCameraObservable: Observable; /** * If provided, this is the depth texture used for composition passes. * Expects an infinite far plane on the camera (camera.maxZ = 0) and the non-linear depth accessible in red channel. * @internal */ readonly depthTexture: Nullable; /** * Controls the overall brightness of the atmosphere rendering. */ get exposure(): number; set exposure(value: number); /** * Affects the overall intensity of the multiple scattering. */ get multiScatteringIntensity(): number; set multiScatteringIntensity(value: number); /** * Affects the multiply scattered light contribution in the atmosphere by describing the average light color reflected off the ground. */ get groundAlbedo(): DeepImmutable; set groundAlbedo(value: DeepImmutable); /** * Can be used to clamp the multiple scattering to a minimum value. */ get minimumMultiScatteringColor(): DeepImmutable; set minimumMultiScatteringColor(value: DeepImmutable); /** * This is an additional scaling factor applied to the {@link minimumMultiScatteringColor}. */ get minimumMultiScatteringIntensity(): number; set minimumMultiScatteringIntensity(value: number); /** * Can be used to force the diffuse irradiance towards a gray color. */ get diffuseSkyIrradianceDesaturationFactor(): number; set diffuseSkyIrradianceDesaturationFactor(value: number); /** * This is an additional amount of irradiance added to the diffuse irradiance. */ get additionalDiffuseSkyIrradianceIntensity(): number; set additionalDiffuseSkyIrradianceIntensity(value: number); /** * This is the color for the additional amount of irradiance added to the diffuse irradiance. */ get additionalDiffuseSkyIrradianceColor(): DeepImmutable; set additionalDiffuseSkyIrradianceColor(value: DeepImmutable); /** * The final additional diffuse irradiance, taking into account the intensity and color. */ get additionalDiffuseSkyIrradiance(): DeepImmutable; /** * The intensity of the diffuse irradiance. */ get diffuseSkyIrradianceIntensity(): number; set diffuseSkyIrradianceIntensity(value: number); /** * True if the sky view LUT should be used for compositing the sky instead of a per-pixel ray march. */ get isSkyViewLutEnabled(): boolean; set isSkyViewLutEnabled(value: boolean); /** * Gets the sky view LUT render target or null if not enabled. * @returns The render target. */ get skyViewLutRenderTarget(): Nullable; /** * True if the aerial perspective LUT should be used. * If false, full ray marching would be used instead. */ get isAerialPerspectiveLutEnabled(): boolean; set isAerialPerspectiveLutEnabled(value: boolean); /** * Gets the aerial perspective LUT render target or null if not enabled. * @returns The render target. */ get aerialPerspectiveLutRenderTarget(): Nullable; /** * The intensity of the aerial perspective. */ get aerialPerspectiveIntensity(): number; set aerialPerspectiveIntensity(value: number); /** * The amount of light transmitted into aerial perspective. * A scale of 1 is physically correct. */ get aerialPerspectiveTransmittanceScale(): number; set aerialPerspectiveTransmittanceScale(value: number); /** * The amount of saturation applied to the aerial perspective. * Reducing to zero desaturates the aerial perspective completely. * A value of 1 has no effect. */ get aerialPerspectiveSaturation(): number; set aerialPerspectiveSaturation(value: number); /** * A radiance bias applied to aerial perspective. */ get aerialPerspectiveRadianceBias(): number; set aerialPerspectiveRadianceBias(value: number); /** * True if the composition should be in linear space (e.g. for HDR rendering). * Typically linear space is expected when ImageProcessing is enabled via PostProcesses. * False for non-linear output. */ get isLinearSpaceComposition(): boolean; set isLinearSpaceComposition(value: boolean); /** * True if the {@link light} value should be specified in linear space. * If using PBRMaterials, light value is expected to be linear. */ get isLinearSpaceLight(): boolean; set isLinearSpaceLight(value: boolean); /** * The lookup table for transmittance. */ get transmittanceLut(): Nullable; /** * Gets the multiple scattering LUT render target. * @returns The render target. */ get multiScatteringLutRenderTarget(): Nullable; /** * The lookup table for diffuse sky irradiance, or null if not enabled. */ get diffuseSkyIrradianceLut(): Nullable; /** * The properties used to describe the size and optical parameters of the atmosphere. */ get physicalProperties(): AtmospherePhysicalProperties; /** * The height in kilometers of the scene's origin. */ get originHeight(): number; set originHeight(value: number); /** * When atmospheric scattering is applied to surfaces, if this value is set to true, * a grayscale approximation of the transmittance is used to dim surfaces. * * When set to false, the atmospheric composition does not dim the surfaces behind it. * It is up to the client application to apply transmittance manually. */ get applyApproximateTransmittance(): boolean; set applyApproximateTransmittance(value: boolean); /** * The directional lights in the scene which represent the suns illuminating the atmosphere. * Each frame, the color and intensity of the lights are updated based on the camera position and the light's direction. */ get lights(): ReadonlyArray; /** * The rendering group ID for the sky compositor. * The sky will only be rendered for this group. */ get skyRenderingGroup(): number; set skyRenderingGroup(value: number); /** * The rendering group ID for the aerial perspective compositor. * Aerial perspective will only be rendered for this group. */ get aerialPerspectiveRenderingGroup(): number; set aerialPerspectiveRenderingGroup(value: number); /** * The rendering group ID for the globe atmosphere compositor. * The globe atmosphere will only be rendered for this group. */ get globeAtmosphereRenderingGroup(): number; set globeAtmosphereRenderingGroup(value: number); /** * Gets the uniform buffer used to store the atmosphere's physical properties. */ get uniformBuffer(): UniformBuffer; /** * Gets the camera-related variables for this atmosphere. Updated each frame. */ get cameraAtmosphereVariables(): AtmospherePerCameraVariables; /** * Constructs the {@link Atmosphere}. * @param name - The name of this instance. * @param scene - The scene to which the atmosphere will be added. * @param lights - The light sources that illuminate the atmosphere. Currently only supports one light, and that light should be the first light in the scene. * @param options - The options used to create the atmosphere. */ constructor(name: string, scene: Scene, lights: DirectionalLight[], options?: IAtmosphereOptions); /** * Fire-and-forget wrapper around {@link preloadMaterialPluginShaderIncludesAsync} used during construction. * Swallows failures so a rejected preload does not surface as an unhandled promise rejection; the plugin's * `isReadyForSubMesh` already retries and logs on failure. * @returns A promise that always resolves. */ private _eagerlyPreloadMaterialPluginShaderIncludesAsync; /** * Preloads the shader includes used by the atmosphere PBR material plugin so that atmosphere-enabled * materials can render in their creation frame with no delay. The plugin registers these includes lazily * (to keep the module tree-shakeable), so without a preload the very first atmosphere material may skip a * frame while they load. Await this before creating meshes that must render immediately. Safe to call * multiple times. * @returns A promise that resolves once the includes are registered. */ preloadMaterialPluginShaderIncludesAsync(): Promise; /** * @override */ dispose(): void; /** * True if the atmosphere is enabled. * @returns - True if the atmosphere is enabled. */ isEnabled(): boolean; /** * Sets the enabled state of the atmosphere. * @param enabled - True to enable the atmosphere, false to disable it. */ setEnabled(enabled: boolean): void; /** * Returns true if the atmosphere is ready for rendering. * Note, this will cause a render of the global LUTs if they are not up to date. * @returns true if the atmosphere is ready */ isReady(): boolean; /** * The class name of the {@link Atmosphere}. * @returns - The class name of the atmosphere. */ getClassName(): string; /** * Gets the color of a light after being transmitted through the atmosphere to a point specified by its distance to the planet center and its geocentric normal. * NOTE, the result is always a linear space color. * @param directionToLight - The direction of the light. * @param pointRadius - The distance from the planet center to the point in kilometers. * @param pointGeocentricNormal - The geocentric normal at the point i.e., normalize(point - planet center). * @param result - The color to store the result in. * @returns The result color. */ getTransmittedColorToRef: (directionToLight: IVector3Like, pointRadius: number, pointGeocentricNormal: IVector3Like, result: T) => T; /** * Gets the diffuse sky irradiance. Result is always in linear space. * @param directionToLight - The direction of the point to the light. * @param pointRadius - The distance from the planet center to the point in kilometers. * @param pointGeocentricNormal - The geocentric normal at the point: normalize(point - planet center). * @param lightIrradiance - The irradiance of the light. * @param result - The color to store the result in. * @returns The result color. */ getDiffuseSkyIrradianceToRef: (directionToLight: IVector3Like, pointRadius: number, pointGeocentricNormal: IVector3Like, lightIrradiance: number, result: T) => T; /** * Draws the multiple scattering LUT using {@link EffectWrapper} and {@link EffectRenderer}. */ private _drawMultiScatteringLut; /** * Draws the aerial perspective compositor using {@link EffectWrapper} and {@link EffectRenderer}. */ drawAerialPerspectiveCompositor(): void; /** * Draws the sky compositor using {@link EffectWrapper} and {@link EffectRenderer}. */ drawSkyCompositor(): void; /** * Draws the globe atmosphere compositor using {@link EffectWrapper} and {@link EffectRenderer}. */ drawGlobeAtmosphereCompositor(): void; private _disposeSkyCompositor; private _disposeAerialPerspectiveCompositor; private _disposeGlobeAtmosphereCompositor; private get _isGlobalLutsReady(); /** * Updates the camera variables that are specific to the atmosphere. * @param camera - The camera to update the variables for. */ private _updatePerCameraVariables; /** * Renders the lookup tables, some of which can vary per-camera. * It is expected that updatePerCameraVariables was previously called. * @param camera - The camera to render the LUTs for. */ private _renderLutsForCamera; /** * Renders the lookup tables that do not depend on a camera position. */ renderGlobalLuts(): void; /** * Binds the atmosphere's uniform buffer to an {@link Effect}. * @param effect - The {@link Effect} to bind the uniform buffer to. */ bindUniformBufferToEffect(effect: Effect): void; /** * Updates the values in the atmosphere's uniform buffer. */ updateUniformBuffer(): void; /** * Draws the aerial perspective LUT using {@link EffectWrapper} and {@link EffectRenderer}. */ private _drawAerialPerspectiveLut; private _clearAerialPerspectiveLut; /** * Draws the sky view LUT using {@link EffectWrapper} and {@link EffectRenderer}. */ private _drawSkyViewLut; }