# VolumetricFogEffect

Class · extends [`CameraFrameEffect`](https://api.playcanvas.com/engine/classes/CameraFrameEffect.md) · category: Graphics

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/extras/effects/volumetric-fog/volumetric-fog-effect.js#L32

The volumetric fog effect, a raymarched height fog lit by a directional light. The fog samples
the light's cascaded shadow map along each view ray, forming visible shafts of light. The
raymarch runs at a reduced resolution and is blended into the scene before TAA, so when TAA is
enabled, its noise is temporally resolved to a smooth result. Optionally the clustered omni and
spot lights scatter light in the fog as well, see [VolumetricFogEffect#localOmniLights](https://api.playcanvas.com/engine/classes/VolumetricFogEffect.md#localomnilights)
and [VolumetricFogEffect#localSpotLights](https://api.playcanvas.com/engine/classes/VolumetricFogEffect.md#localspotlights).

The fog is rendered by passes the effect owns, from the scene depth, into the scene. It is only
supported on perspective cameras.

Every [CameraFrame](https://api.playcanvas.com/engine/classes/CameraFrame.md) constructs and registers one, available as
[CameraFrame#volumetricFog](https://api.playcanvas.com/engine/classes/CameraFrame.md#volumetricfog).

## Constructors

### constructor

```ts
new VolumetricFogEffect(device: GraphicsDevice)
```

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.

## Properties

### ambientColor

```ts
ambientColor: Color
```

The color of the ambient in-scattered light, which keeps the fog in shadowed areas visible.
Defaults to white.

### ambientIntensity

```ts
ambientIntensity: number = 0.02
```

The intensity of the ambient in-scattered light. Defaults to 0.02.

### anisotropy

```ts
anisotropy: number = 0.6
```

The anisotropy of the scattering, 0-0.95 range. Larger values scatter more light forward,
making the fog brighter when looking towards the light. Defaults to 0.6.

### density

```ts
density: number = 0.01
```

The fog density at the base height. Defaults to 0.01.

### enabled

```ts
enabled: boolean = false
```

Whether the volumetric fog is enabled. Defaults to false.

### extinction

```ts
extinction: number = 1
```

A scale of how quickly the fog absorbs the light passing through it, without affecting how
much light it scatters. A value of 1 is physically consistent, where the fog absorbs as much
as it scatters, and distant fog and light shafts fade out exponentially with the density.
Lower values keep them visible over a longer distance while the fog itself stays as bright,
which is not physically correct but is often preferable. Defaults to 1.

### heightBase

```ts
heightBase: number = 0
```

The world space height at which the fog density starts to fall off. Below it the density is
constant. Defaults to 0.

### heightFalloff

```ts
heightFalloff: number = 0.05
```

The exponential falloff of the fog density with height above the base height. Value of 0
makes the fog uniform. Defaults to 0.05.

### intensity

```ts
intensity: number = 1
```

The intensity of the light scattering. Defaults to 1.

### light

```ts
light: LightComponent | null = null
```

The directional light providing the scattered light, or null when the fog is lit by the local
lights and the ambient term only. When a light of a type other than directional is assigned,
the effect is disabled. Defaults to null.

### localIntensity

```ts
localIntensity: number = 1
```

The intensity of the light scattering of the local lights. Defaults to 1.

### localOmniLights

```ts
localOmniLights: boolean = false
```

Whether the clustered omni lights scatter light in the fog. Each light adds a raymarch over
the part of the view rays inside its volume, sampling the shadow and the cookie atlas of the
clustered lighting, and so the cost scales with the screen space size of the light volumes.
As an omni light fills its whole bounding sphere, its volume is typically much larger on the
screen than the volume of a spot light. Requires clustered lighting, which is enabled by
default. Individual lights can scatter more or less light using
[LightComponent#volumetricScattering](https://api.playcanvas.com/engine/classes/LightComponent.md#volumetricscattering). Defaults to false.

### localSpotLights

```ts
localSpotLights: boolean = false
```

Whether the clustered spot lights scatter light in the fog, forming visible beams. See
[VolumetricFogEffect#localOmniLights](https://api.playcanvas.com/engine/classes/VolumetricFogEffect.md#localomnilights) for details, both types are rendered the same way
and share the [VolumetricFogEffect#localIntensity](https://api.playcanvas.com/engine/classes/VolumetricFogEffect.md#localintensity) and
[VolumetricFogEffect#localSteps](https://api.playcanvas.com/engine/classes/VolumetricFogEffect.md#localsteps) settings. Defaults to false.

### localSteps

```ts
localSteps: number = 12
```

The number of raymarching steps taken inside the volume of each local light, 2-64 range.
Defaults to 12.

### maxDistance

```ts
maxDistance: number = 300
```

The maximum world space distance the fog is raymarched to. Defaults to 300.

### scale

```ts
scale: number = 0.5
```

The resolution scale of the fog texture relative to the scene render target, 0.25-1 range.
Defaults to 0.5.

### steps

```ts
steps: number = 24
```

The number of raymarching steps, 4-128 range. Higher values improve the quality at a higher
performance cost. Defaults to 24.

### tint

```ts
tint: Color
```

The albedo of the fog. Defaults to white.

## Accessors

### active

```ts
get active(): boolean
```

Gets whether the effect contributes to the frame: it is enabled, it has a light source -
the directional light or the local lights - and the camera is a perspective camera.

## Methods

### frameUpdate

```ts
frameUpdate(frame: CameraFrameEffectContext): void
```

**Parameters**

- `frame` ([`CameraFrameEffectContext`](https://api.playcanvas.com/engine/interfaces/CameraFrameEffectContext.md)): The values of this frame.

### update

```ts
update(): void
```

Applies the effect's parameters. Called by [CameraFrame#update](https://api.playcanvas.com/engine/classes/CameraFrame.md#update) while the effect is
active: set the uniform values with [CameraFrameEffect#setUniform](https://api.playcanvas.com/engine/classes/CameraFrameEffect.md#setuniform) here, and the
defines which depend on the parameters.
Everything it sets is what the frames rendered until the next update use.

## Inherited from [CameraFrameEffect](https://api.playcanvas.com/engine/classes/CameraFrameEffect.md)

- `cameraFrame: CameraFrame | null = null`
- `device: GraphicsDevice`
- `get cameraExposureScale(): number`
- `get chunkName(): string`
- `get debugViews(): string[]`
- `get defineName(): string`
- `get entryPoint(): string`
- `get glsl(): string | null`
- `get id(): string`
- `get requires(): string[]`
- `get slot(): string | null`
- `get wgsl(): string | null`
- `buildKey(): string`
- `destroy(): void`
- `getChunk(shaderLanguage: string): string | null`
- `resolveScene(scene: CameraFrameEffectScene): void`
- `setDefine(name: string, value: any): void`
- `setUniform(name: string, value: number | number[] | ArrayBufferView<ArrayBufferLike> | Texture): void`
