# LensFlare

Class · category: Graphics

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

A lens flare: a [LensFlareLook](https://api.playcanvas.com/engine/interfaces/LensFlareLook.md) placed in the world, following a light or a node. Create
one for each light that flares, and add it to the [LensFlareEffect](https://api.playcanvas.com/engine/classes/LensFlareEffect.md) of a camera frame.
The properties of the flare are live - changes apply to the next frame rendered - except the
look, whose elements are built into the effect when [CameraFrame#update](https://api.playcanvas.com/engine/classes/CameraFrame.md#update) is called.

**Example**

```ts
const sun = new LensFlare(sunLook, { light: sunEntity.light });
sun.occlusionRadius = 0.03;
cameraFrame.getEffect('lensFlare').add(sun);
cameraFrame.update();
```

## Constructors

### constructor

```ts
new LensFlare(look?: LensFlareLook | null, options?: LensFlareOptions)
```

Creates a new lens flare.

**Parameters**

- `look` ([`LensFlareLook`](https://api.playcanvas.com/engine/interfaces/LensFlareLook.md) `| null`, optional, default `null`): The look of the flare.
- `options` ([`LensFlareOptions`](https://api.playcanvas.com/engine/interfaces/LensFlareOptions.md), optional, default `{}`): The source the flare follows.

## Properties

### allowOffScreen

```ts
allowOffScreen: boolean = true
```

Whether the flare keeps drawing while its source is outside the screen, within the edge fade
band - the ghosts of a sun just outside the frame. Defaults to true.

### color

```ts
color: Color
```

The color of the flare, tinting its elements. Defaults to white.

### direction

```ts
direction: Vec3 | null = null
```

The world direction towards the source, or null. See [LensFlareOptions](https://api.playcanvas.com/engine/interfaces/LensFlareOptions.md).

### edgeFade

```ts
edgeFade: number = 0.2
```

The width of the band at the edge of the screen the flare fades out over as its source
leaves the screen, as a fraction of half the screen size. Defaults to 0.2.

### enabled

```ts
enabled: boolean = true
```

Whether the flare is drawn. Defaults to true.

### fadeEnd

```ts
fadeEnd: number = 0
```

The distance from the camera the flare of a positional source is fully faded out at, in
world units. Defaults to 0, which disables the fade.

### fadeStart

```ts
fadeStart: number = 0
```

The distance from the camera the flare of a positional source starts to fade out at, in
world units. The fade is disabled while [LensFlare#fadeEnd](https://api.playcanvas.com/engine/classes/LensFlare.md#fadeend) is not greater than this.
Defaults to 0.

### intensity

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

The brightness of the flare, multiplying the intensity of its elements. Defaults to 1.

### light

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

The light the flare belongs to, or null. See [LensFlareOptions](https://api.playcanvas.com/engine/interfaces/LensFlareOptions.md).

### node

```ts
node: GraphNode | null = null
```

The node whose position is the source, or null. See [LensFlareOptions](https://api.playcanvas.com/engine/interfaces/LensFlareOptions.md).

### occlusionFade

```ts
occlusionFade: number = 0.15
```

The time the measured visibility takes to follow a change, in seconds, smoothing the flare
as the source is covered and uncovered. Zero follows immediately. Defaults to 0.15.

### occlusionOffset

```ts
occlusionOffset: number = 0
```

The distance the depth test is moved from the source towards the camera, in world units, so
that the geometry of the light itself, such as a bulb, does not occlude its own flare.
Defaults to 0.

### occlusionRadius

```ts
occlusionRadius: number = 0.02
```

The radius around the source the scene depth is tested in to measure how much of the source
is visible, as a fraction of the screen height. The flare fades with the fraction. Defaults
to 0.02.

### position

```ts
position: Vec3 | null = null
```

The world position of the source, or null. See [LensFlareOptions](https://api.playcanvas.com/engine/interfaces/LensFlareOptions.md).

### scale

```ts
scale: number = 1
```

The scale of the flare, multiplying the size of its elements. Defaults to 1.

### useLightColor

```ts
useLightColor: boolean = true
```

Whether the color of the light the flare belongs to tints the flare. Defaults to true.

### useLightIntensity

```ts
useLightIntensity: boolean = true
```

Whether the intensity of the light the flare belongs to scales the flare, so that the flare
dims and brightens with its light, and disappears at an intensity of 0. With
[Scene#physicalUnits](https://api.playcanvas.com/engine/classes/Scene.md#physicalunits), the luminance of the light scales the flare instead, as it
scales the lighting. Defaults to true.

## Accessors

### look

```ts
get look(): LensFlareLook | null
set look(value: LensFlareLook | null)
```

Gets the look of the flare.
