# SmaaEffect

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

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/extras/effects/smaa/smaa-effect.js#L46

The SMAA effect - Subpixel Morphological Anti-Aliasing (SMAA 1x), a technique smoothing the
jagged edges of the rendered geometry. It finds the edges in the image, recognizes the shape of
each aliased edge, and blends the pixels along it with their neighbors by the area the edge
before aliasing would cover. Unlike temporal anti-aliasing it works within a single frame: it
does not jitter the camera, needs no history and does not ghost, at the cost of not resolving
detail finer than a pixel.

The effect resolves the scene before the other effects read it, so that the depth of field, the
bloom and the composition all work with the anti-aliased scene. It is not registered by default
- add it to a [CameraFrame](https://api.playcanvas.com/engine/classes/CameraFrame.md):

```javascript
const smaa = new SmaaEffect(app.graphicsDevice);
cameraFrame.addEffect(smaa);
cameraFrame.update();
```

The parameters default to the HIGH quality preset of the reference implementation. The
presets, as threshold / maxSearchSteps / maxSearchStepsDiag / cornerRounding, are LOW: 0.15 /
4 / 0 / 100, MEDIUM: 0.1 / 8 / 0 / 100, HIGH: 0.1 / 16 / 8 / 25 and ULTRA: 0.05 / 32 / 16 / 25.

It can be combined with multisampling, see `rendering.samples` of the camera frame, which smooths
the edges further at a higher cost. Combined with [TaaEffect](https://api.playcanvas.com/engine/classes/TaaEffect.md), it resolves the scene in the
order the effects are registered - after the built-in temporal anti-aliasing unless inserted
before it with [CameraFrame#insertEffectBefore](https://api.playcanvas.com/engine/classes/CameraFrame.md#inserteffectbefore).

Based on the reference implementation of SMAA by Jorge Jimenez, Jose I. Echevarria, Belen
Masia, Fernando Navarro and Diego Gutierrez, distributed under the MIT license.

## Constructors

### constructor

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

**Parameters**

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

## Properties

### cornerRounding

```ts
cornerRounding: number = 25
```

How much the sharp corners of the geometry are rounded, 0-100 range. Zero keeps them the
sharpest, 100 smooths them like the rest of the edges. Defaults to 25.

### maxSearchSteps

```ts
maxSearchSteps: number = 16
```

The maximum number of steps searching for the end of a horizontal or vertical edge, each
step covering two pixels, 1-112 range. The ends of longer edges are not found, which smooths
them less accurately. Defaults to 16.

### maxSearchStepsDiag

```ts
maxSearchStepsDiag: number = 8
```

The maximum number of steps searching for the end of a diagonal edge, 0-20 range. Zero
disables the detection of diagonal edges, which are then smoothed as horizontal and
vertical ones. Defaults to 8.

### threshold

```ts
threshold: number = 0.1
```

The brightness difference between neighboring pixels above which they are separated by an
edge, 0-0.5 range. Lower values smooth more edges, at a higher cost, and can smooth texture
detail along with the geometry. Defaults to 0.1.

## Methods

### 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.

### 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 active(): boolean`
- `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`
- `frameUpdate(frame: CameraFrameEffectContext): void`
- `getChunk(shaderLanguage: string): string | null`
- `setDefine(name: string, value: any): void`
- `setUniform(name: string, value: number | number[] | ArrayBufferView<ArrayBufferLike> | Texture): void`
