/** * @import { CameraComponent } from '../../framework/components/camera/component.js' * @import { FramePass } from '../../platform/graphics/frame-pass.js' * @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js' * @import { Camera } from '../camera.js' * @import { LayerComposition } from '../composition/layer-composition.js' * @import { Renderer } from './renderer.js' * @import { Scene } from '../scene.js' */ /** * 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 {@link CameraComponent#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 {@link RenderPass#init} with the render target before adding the layers to render with * {@link RenderPassForward#addLayer}. Each frame, the pass: * * - clears the render target as the clear flags of the camera and of the layers request, see * {@link RenderPassForward#addLayer}; * - culls the mesh instances of its layers for the camera, and renders the directional shadows * they need; * - renders the {@link CameraComponent#beforePasses} of the camera, when it is the first pass * rendering the camera in the frame; * - fires {@link Scene.EVENT_PRERENDER} from the first pass rendering the camera in the frame, * {@link Scene.EVENT_POSTRENDER} from the last one, and {@link Scene.EVENT_PRERENDER_LAYER} and * {@link Scene.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 {@link FramePass}, or render them with a camera of a lower priority. * * @example * // 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]; */ export class RenderPassForward extends RenderPass { /** * Create a new RenderPassForward instance. * * @param {GraphicsDevice} device - The graphics device. * @param {Scene} scene - The scene whose layers the pass renders. * @param {CameraComponent} cameraComponent - The camera component used to render the layers. */ constructor(device: GraphicsDevice, scene: Scene, cameraComponent: CameraComponent); /** * The layer composition the forward renderer renders the layers from, when it is not the * layers of the scene. * * @type {LayerComposition|null} * @private */ private _layerComposition; /** * The camera component used to render the layers. * * @type {CameraComponent} * @readonly */ readonly cameraComponent: CameraComponent; /** * True if this is the first pass rendering its camera in the frame, set when the pass is * scheduled. The first pass collects the before-passes of the camera, and fires * {@link Scene.EVENT_PRERENDER}. * * @type {boolean} * @ignore */ firstCameraUse: boolean; /** * True if this is the last pass rendering its camera in the frame, set when the passes are * scheduled. The last pass fires {@link Scene.EVENT_POSTRENDER}. * * @type {boolean} * @ignore */ lastCameraUse: boolean; /** * @type {Scene} * @ignore */ scene: Scene; /** * @type {Renderer} * @ignore */ renderer: Renderer; /** * @type {LayerRenderStep[]} * @ignore */ layerRenderSteps: LayerRenderStep[]; /** * 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 {@link GAMMA_NONE} to output * linear values to an HDR render target, while subsequent passes (like UI) leave it undefined * to use the camera's default {@link GAMMA_SRGB} for correct display output. * * Can be: * - {@link GAMMA_NONE} * - {@link GAMMA_SRGB} * - `undefined` (uses camera setting) * * @type {number|undefined} */ gammaCorrection: number | undefined; /** * The tone mapping setting for the render pass, one of the TONEMAP_* constants, for example * {@link TONEMAP_ACES}. If not set, the setting from the camera is used. * * @type {number|undefined} */ toneMapping: number | undefined; /** * The names of the scene textures this pass renders alongside the scene color, in the order of * the color attachments they are rendered to. If not set, setting from the camera is used. Only * the passes rendering to a render target the scene textures are attached to set this, so that * the camera's other passes, for example the one rendering the UI to the output render target, * do not write them. * * @type {string[]|undefined} * @ignore */ sceneTextures: string[] | undefined; /** * The camera whose scene textures this pass publishes when it finishes, making them available to * the passes which consume them, or null if it publishes none. The last pass rendering to the * render target they are attached to sets this. An earlier pass can set it too, for passes * consuming them before the remaining passes render, but only when the next of those clears them * first, see {@link RenderPassForward#clearSceneTextures} - otherwise the materials the remaining * passes render could sample an attachment of the render target they render into, which is not * allowed. * * @type {Camera|null} * @ignore */ sceneTexturesCamera: Camera | null; /** * True if this pass clears the uniforms the scene textures are published to before it renders. The * first pass rendering to the render target they are attached to sets this, when no depth prepass * has published to those uniforms already - it is what stops a material from sampling a scene * texture which nothing has produced yet. A later pass sets it when an earlier one published them, * see {@link RenderPassForward#sceneTexturesCamera}, so that its materials do not sample the * attachments of the render target it renders into. * * @type {boolean} * @ignore */ clearSceneTextures: boolean; /** * If true, do not clear the depth buffer before rendering, as it was already primed by a depth * pre-pass. * * @ignore */ noDepthClear: boolean; /** * Sets the layer composition the layers are rendered from, when it is not the layers of the * scene, as when the forward renderer renders another composition. * * @type {LayerComposition} * @ignore */ set layerComposition(value: LayerComposition); /** * Gets the layer composition the layers are rendered from. * * @type {LayerComposition} * @ignore */ get layerComposition(): LayerComposition; /** * @type {boolean} * @ignore */ get rendersAnything(): boolean; /** * @param {LayerRenderStep} layerRenderStep - The layer render step to add. * @ignore */ addLayerRenderStep(layerRenderStep: LayerRenderStep): void; /** * Adds a layer to be rendered by this pass, after the layers added before it. Call * {@link RenderPass#init} before adding layers. The camera of the pass needs to render the * layer, see {@link CameraComponent#layers}. * * @param {Layer} layer - The layer to be added. * @param {boolean} transparent - True to render the transparent sub-layer of the layer, false to * render its opaque sub-layer. To render both, add the layer twice. * @param {boolean} [autoClears] - 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. */ addLayer(layer: Layer, transparent: boolean, autoClears?: boolean): void; /** * Adds the directional shadow passes the camera of this pass needs to its internal * before-passes. * * @ignore */ updateDirectionalShadows(): void; /** * Marks this pass as the first and the last one rendering its camera in the frame, keeping the * last pass of each camera in the renderer. As no RenderPassForward is nested under another one, * the passes execute in the order they are scheduled in, so the flags are final when before() * and after() read them. A pass scheduled again, before the next frame, keeps its flags. * * @ignore */ updateCameraUse(): void; /** * Collects the before-passes of the camera in the first pass rendering it, so they are * scheduled once, even when multiple RenderPassForward instances render the same camera (e.g. * CameraFrame's scenePass vs afterPass). Called after updateDirectionalShadows, so camera * before-passes execute after the directional shadow passes and can render into the freshly * updated shadow maps. * * @ignore */ updateCameraBeforePasses(): void; /** * Sets up the clears of the pass from its first layer render step. * * @ignore */ updateClears(): void; /** * @param {LayerRenderStep} step - The layer render step. * @param {boolean} firstStep - True if this is the first render step in the render pass. * @ignore */ renderLayerRenderStep(step: LayerRenderStep, firstStep: boolean): void; log(device: any, index: any): void; } import { RenderPass } from '../../platform/graphics/render-pass.js'; import type { CameraComponent } from '../../framework/components/camera/component.js'; import type { Scene } from '../scene.js'; import type { Renderer } from './renderer.js'; import { LayerRenderStep } from './layer-render-step.js'; import type { Camera } from '../camera.js'; import type { LayerComposition } from '../composition/layer-composition.js'; import { Layer } from '../layer.js'; import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';