# RenderPassForward

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

Source: https://github.com/playcanvas/engine/blob/64089771243fe28a9b9d2b4de538b99b07c75097/src/scene/renderer/render-pass-forward.js#L60

A render pass rendering layers of the scene with a single camera. The engine renders the scene
with these passes, and you can use them in the [CameraComponent#framePasses](https://api.playcanvas.com/engine/classes/CameraComponent.md#framepasses) of a camera to
render the scene into a render target of your own, for example to process it with your own
passes before it is displayed.

Call [RenderPass#init](https://api.playcanvas.com/engine/classes/RenderPass.md#init) with the render target before adding the layers to render with
[RenderPassForward#addLayer](https://api.playcanvas.com/engine/classes/RenderPassForward.md#addlayer). Each frame, the pass:

- clears the render target as the clear flags of the camera and of the layers request, see
[RenderPassForward#addLayer](https://api.playcanvas.com/engine/classes/RenderPassForward.md#addlayer);
- culls the mesh instances of its layers for the camera, and renders the directional shadows
they need;
- renders the [CameraComponent#beforePasses](https://api.playcanvas.com/engine/classes/CameraComponent.md#beforepasses) of the camera, when it is the first pass
rendering the camera in the frame;
- fires [Scene.EVENT_PRERENDER](https://api.playcanvas.com/engine/classes/Scene.md#event_prerender) from the first pass rendering the camera in the frame,
[Scene.EVENT_POSTRENDER](https://api.playcanvas.com/engine/classes/Scene.md#event_postrender) from the last one, and [Scene.EVENT_PRERENDER_LAYER](https://api.playcanvas.com/engine/classes/Scene.md#event_prerender_layer) and
[Scene.EVENT_POSTRENDER_LAYER](https://api.playcanvas.com/engine/classes/Scene.md#event_postrender_layer) around each layer it renders.

A RenderPassForward cannot be nested under another one, which is among its before-passes or
after-passes, or among the before-passes of its camera, which it executes before itself. To
render the layers with another camera first, render the passes one after the other, for example
as the before-passes of a [FramePass](https://api.playcanvas.com/engine/classes/FramePass.md), or render them with a camera of a lower priority.

**Example**

```ts
// render the world and the UI layers into a texture
const scenePass = new RenderPassForward(app.graphicsDevice, app.scene, cameraEntity.camera);
scenePass.init(renderTarget, { resizeSource: null });
scenePass.addLayer(app.scene.layers.getLayerByName('World'), false);
scenePass.addLayer(app.scene.layers.getLayerById(LAYERID_UI), true);

// a pass of your own, drawing the texture to the screen
const tintPass = new RenderPassTint(app.graphicsDevice, renderTarget.colorBuffer);
tintPass.init(null);

// the camera renders with these passes instead of its default rendering
cameraEntity.camera.framePasses = [scenePass, tintPass];
```

## Constructors

### constructor

```ts
new RenderPassForward(device: GraphicsDevice, scene: Scene, cameraComponent: CameraComponent)
```

Create a new RenderPassForward instance.

**Parameters**

- `device` ([`GraphicsDevice`](https://api.playcanvas.com/engine/classes/GraphicsDevice.md)): The graphics device.
- `scene` ([`Scene`](https://api.playcanvas.com/engine/classes/Scene.md)): The scene whose layers the pass renders.
- `cameraComponent` ([`CameraComponent`](https://api.playcanvas.com/engine/classes/CameraComponent.md)): The camera component used to render the layers.

## Properties

### cameraComponent

```ts
readonly cameraComponent: CameraComponent
```

The camera component used to render the layers.

### gammaCorrection

```ts
gammaCorrection: number | undefined
```

The gamma correction setting for the render pass. If not set, the setting from the camera
is used. This allows render passes to override the camera's gamma correction during the
render pass.

For HDR pipelines, scene render passes typically set this to [GAMMA_NONE](https://api.playcanvas.com/engine/variables/GAMMA_NONE.md) to output
linear values to an HDR render target, while subsequent passes (like UI) leave it undefined
to use the camera's default [GAMMA_SRGB](https://api.playcanvas.com/engine/variables/GAMMA_SRGB.md) for correct display output.

Can be:
- [GAMMA_NONE](https://api.playcanvas.com/engine/variables/GAMMA_NONE.md)
- [GAMMA_SRGB](https://api.playcanvas.com/engine/variables/GAMMA_SRGB.md)
- `undefined` (uses camera setting)

### toneMapping

```ts
toneMapping: number | undefined
```

The tone mapping setting for the render pass, one of the TONEMAP_* constants, for example
[TONEMAP_ACES](https://api.playcanvas.com/engine/variables/TONEMAP_ACES.md). If not set, the setting from the camera is used.

## Methods

### addLayer

```ts
addLayer(layer: Layer, transparent: boolean, autoClears?: boolean): void
```

Adds a layer to be rendered by this pass, after the layers added before it. Call
[RenderPass#init](https://api.playcanvas.com/engine/classes/RenderPass.md#init) before adding layers. The camera of the pass needs to render the
layer, see [CameraComponent#layers](https://api.playcanvas.com/engine/classes/CameraComponent.md#layers).

**Parameters**

- `layer` ([`Layer`](https://api.playcanvas.com/engine/classes/Layer.md)): The layer to be added.
- `transparent` (`boolean`): True to render the transparent sub-layer of the layer, false to
  render its opaque sub-layer. To render both, add the layer twice.
- `autoClears` (`boolean`, optional, default `true`): True to clear the render target before the layer renders, as
  the clear flags of the layer request, together with those of the camera for the first layer
  added. Defaults to true.

### after

```ts
after(): void
```

Called while the pass renders, after [FramePass#execute](https://api.playcanvas.com/engine/classes/FramePass.md#execute). It is called even when
[FramePass#executeEnabled](https://api.playcanvas.com/engine/classes/FramePass.md#executeenabled) is false and the pass did not execute, so an override
using the results of the execution can skip that work while executeEnabled is false.

### before

```ts
before(): void
```

Called while the pass renders, before [FramePass#execute](https://api.playcanvas.com/engine/classes/FramePass.md#execute). It is called even when
[FramePass#executeEnabled](https://api.playcanvas.com/engine/classes/FramePass.md#executeenabled) is false and the pass does not execute, so an override
preparing only for the execution can skip that work while executeEnabled is false.

### execute

```ts
execute(): void
```

Records the work of the pass. Called while the frame renders, between
[FramePass#before](https://api.playcanvas.com/engine/classes/FramePass.md#before) and [FramePass#after](https://api.playcanvas.com/engine/classes/FramePass.md#after), and only while
[FramePass#executeEnabled](https://api.playcanvas.com/engine/classes/FramePass.md#executeenabled) is true. For a [RenderPass](https://api.playcanvas.com/engine/classes/RenderPass.md), it runs inside the GPU
render pass, which starts right before it.

### frameUpdate

```ts
frameUpdate(): void
```

Resizes the render target to the size of its resize source, scaled by
[RenderPass#scaleX](https://api.playcanvas.com/engine/classes/RenderPass.md#scalex) and [RenderPass#scaleY](https://api.playcanvas.com/engine/classes/RenderPass.md#scaley), while the pass resizes its render
target, see [RenderPass#resizeSource](https://api.playcanvas.com/engine/classes/RenderPass.md#resizesource). See [FramePass#frameUpdate](https://api.playcanvas.com/engine/classes/FramePass.md#frameupdate). Subclasses
overriding it call `super.frameUpdate()` to keep the resize.

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

- `afterPasses: FramePass[] = []`
- `beforePasses: FramePass[] = []`
- `device: GraphicsDevice`
- `executeEnabled: boolean = true`
- `onAfter: ((pass: FramePass) => void) | null = null`
- `onBefore: ((pass: FramePass) => void) | null = null`
- `renderTarget: RenderTarget | null | undefined`
- `get enabled(): boolean` · `set enabled(value: boolean)`
- `get name(): string` · `set name(value: string)`
- `get resizeSource(): Texture | RenderTarget | null | undefined` · `set resizeSource(value: Texture | RenderTarget | null | undefined)`
- `get scaleX(): number` · `set scaleX(value: number)`
- `get scaleY(): number` · `set scaleY(value: number)`
- `destroy(): void`
- `init(renderTarget?: RenderTarget | null, options?: object): void`
- `onDisable(): void`
- `onEnable(): void`
- `postInit(): void`
- `render(): void`
- `setClearColor(color: Color | undefined, index?: number): void`
- `setClearDepth(depthValue: number | undefined): void`
- `setClearStencil(stencilValue: number | undefined): void`
- `setGenerateMipmaps(generate: boolean, index?: number): void`
- `setStoreColor(store: boolean, index?: number): void`
- `setStoreDepth(store: boolean): void`
- `setStoreStencil(store: boolean): void`
