# LensFlareEffect

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

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/extras/effects/lens-flare/lens-flare-effect.js#L75

The lens flare effect: draws the flares of the lights, or of any positions, in the scene. A
flare is a [LensFlare](https://api.playcanvas.com/engine/classes/LensFlare.md), following its light, whose look places shapes along the axis from
the light through the center of the screen. The shapes are textures, given to the effect as a
[LensFlareShapeLibrary](https://api.playcanvas.com/engine/interfaces/LensFlareShapeLibrary.md) it copies into one texture array shared by all its flares. The
flares fade as their source is covered by the scene, measured against the scene depth, as it
leaves the screen, and for a spot light as the camera leaves its cone.

The flares are drawn by passes the effect owns, at the resolution
[LensFlareEffect#scale](https://api.playcanvas.com/engine/classes/LensFlareEffect.md#scale) gives, half of the scene's by default, and added to the scene in linear HDR space, before
tone mapping.

Add one to a camera frame with [CameraFrame#addEffect](https://api.playcanvas.com/engine/classes/CameraFrame.md#addeffect); it is not a built-in effect.

**Example**

```ts
const lensFlare = new LensFlareEffect(app.graphicsDevice);
lensFlare.shapes = {
    shapes: {
        glow: glowAsset.resource,
        star: starAsset.resource,
        disc: discAsset.resource
    }
};
cameraFrame.addEffect(lensFlare);

const sun = new LensFlare({
    elements: [
        { shape: 'glow', size: 0.5, color: [1, 0.9, 0.7], intensity: 0.5 },
        { shape: 'star', size: 1.2, intensity: 0.4 },
        { shape: 'disc', offset: 0.5, size: 0.08, color: [0.4, 0.8, 1], count: 4, spread: 0.4 }
    ]
}, { light: sunEntity.light });
lensFlare.add(sun);

cameraFrame.update();
```

## Constructors

### constructor

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

**Parameters**

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

## Properties

### flares

```ts
flares: LensFlare[] = []
```

The flares registered with the effect, in the order they are drawn. Treat the array as
read-only; use [LensFlareEffect#add](https://api.playcanvas.com/engine/classes/LensFlareEffect.md#add) and [LensFlareEffect#remove](https://api.playcanvas.com/engine/classes/LensFlareEffect.md#remove) to change it.

### intensity

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

The brightness of all flares. Zero disables the effect. Defaults to 1.

### scale

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

The resolution the flares are drawn at, relative to the resolution of the scene, 0.25-1
range. Lower values are cheaper and soften the elements slightly, which suits soft shapes,
while 1 keeps small sharp elements crisp. Defaults to 0.5.

## Accessors

### active

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

Gets whether the effect contributes to the frame: when it is enabled, its intensity is
positive and it has flares.

### shapes

```ts
get shapes(): LensFlareShapeLibrary | null
set shapes(value: LensFlareShapeLibrary | null)
```

Gets the shape library.

## Methods

### add

```ts
add(flare: LensFlare): void
```

Registers a flare with the effect, drawn from the next [CameraFrame#update](https://api.playcanvas.com/engine/classes/CameraFrame.md#update). A flare
can be registered with the effects of several camera frames.

**Parameters**

- `flare` ([`LensFlare`](https://api.playcanvas.com/engine/classes/LensFlare.md)): The flare.

### destroy

```ts
destroy(): void
```

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](https://api.playcanvas.com/engine/classes/CameraFrame.md#update), which
is due before the next frame renders.

### frameUpdate

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

**Parameters**

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

### remove

```ts
remove(flare: LensFlare): void
```

Removes a flare from the effect, from the next [CameraFrame#update](https://api.playcanvas.com/engine/classes/CameraFrame.md#update).

**Parameters**

- `flare` ([`LensFlare`](https://api.playcanvas.com/engine/classes/LensFlare.md)): The flare.

### 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`
- `enabled: boolean = true`
- `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`
- `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`
