Rendering effects
The engine effects system provides reusable GPU passes that transform a rendered image. It covers simple image changes, multi-stage blur and bloom, screen-space lighting, atmospheric effects, and temporal cleanup. The application owns the scene and supplies the color and supporting buffers; the effects system applies the selected visual changes as part of the render workflow.
Effect capabilities
The public effects entry point is modules/…/index.ts. It groups reusable passes by the kind of image information they use. Each pass exposes tunable properties while composite effects combine several passes and their intermediate images.
| Capability | Purpose | Typical inputs |
|---|---|---|
| Image adjustment | Change color, contrast, tone, grain, or edge emphasis. | Scene color. |
| Blur and lens | Soften, spread, magnify, or reshape image features. | Scene color and effect settings. |
| Stylized image filters | Add halftone, pixel, ink, or warp looks. | Scene color and screen-space settings. |
| Visibility and indirect light | Estimate contact shadow, diffuse bounce, reflection, or outlines from visible surfaces. | Color, depth, normals, and camera data. |
| Atmospheric effects | Add fog, volumetric light, or god rays. | Depth, camera data, and light data. |
| Temporal effects | Reuse earlier frames to improve stability or create persistence. | Current color plus history, depth, velocity, or camera transforms. |
The engine now owns these capabilities under modules/engine/src/effects/. Code that previously treated them as a separate effects package should use the engine effects surface instead. The sibling GPGPU compute page describes related GPU data work, while GPU compute and effects gives the wider system view.
References: modules/…/index.ts• L5-210 modules/…/brightnesscontrast.ts• L47-80 modules/…/bloom.ts• L92-129 modules/…/ssao.ts• L10-14
Rendering pipeline
The effects pipeline takes an application-owned scene image and passes it through an ordered list. A simple pass reads the current image and writes a new image. A composite pass is a small render graph that can keep scratch images or frame history before it returns a result to the chain.
This diagram shows how the scene image and supporting buffers move through reusable effects.
flowchart LR
Scene[Rendered scene] --> Color[Scene color]
Scene --> Buffers[Depth normals velocity]
Color --> Chain[Ordered effect chain]
Buffers --> Chain
Lights[Light and cluster data] --> Chain
History[Previous-frame data] --> Chain
Chain --> Result[Texture or screen]
The application chooses the effect order and supplies per-frame values. Effects that only change color can run with the scene image alone. Screen-space effects read matching attachments from the same view. Composite effects use named intermediate targets so one stage can feed another without changing the application’s scene render.
References: modules/…/copy-pass.ts• L7-14 modules/…/depth-aware-blur.ts• L85-102 modules/…/ssao.ts• L100-141 modules/…/volumetric-fog.ts• L81-101
Image filters
Image filters operate on the completed scene image. They cover color adjustment, tone mapping, noise and denoise, vignette, blur, bloom, halftone, pixelation, ink, magnification, and local warps. Most filters expose tunable settings as uniforms, while fixed shader choices such as the FXAA quality preset are selected by the pass definition. An application can change the visual result without rebuilding the scene.
The filters form several useful groups:
- Color and presentation: brightness and contrast, hue and saturation, sepia, vibrance, vignette, noise, denoise, tone mapping, and FXAA.
- Blur and glow: Gaussian, triangle, tilt-shift, zoom blur, depth-of-field, and bloom.
- Stylized image changes: color halftone, dot screen, edge work, hexagonal pixelation, ink, and magnify.
- Image warps: bulge and pinch, swirl, and the shared warp behavior used by those passes.
Tone mapping belongs near the end of an HDR chain. Bloom and other bright-light effects need the HDR range before tone mapping compresses it for display.
References: modules/…/index.ts• L5-128 modules/…/fxaa.ts• L970-982 modules/…/denoise.ts• L73-111 modules/…/vignette.ts• L41-79 modules/…/tone-mapping.ts• L55-89 modules/…/gaussianblur.ts• L7-20 modules/…/colorhalftone.ts• L86-120 modules/…/warp.ts• L7-45
Bloom pipeline
Bloom extracts bright scene values, builds a set of lower-resolution glow images, reconstructs the glow, and adds it to the scene. The pipeline can also add lens artifacts, temporal stability, exposure-aware thresholds, and an optional WebGPU compute path.
The main quality choices affect the number and scale of glow levels, blur method, reconstruction method, resolution, color format, and whether the pipeline uses compute downsampling. Floating-point intermediates preserve bright values that a clamped format would lose.
References: modules/…/bloom-composite-shader-pass.ts• L47-92 modules/…/bloom-composite-shader-pass.ts• L948-1159 modules/…/bloom-compute-pyramid.ts• L20-54 modules/…/bloom-lens-effects.ts• L12-39
Screen-space effects
Screen-space effects use data from the visible view to add information that the base scene pass does not include. Depth gives surface distance, normals give surface direction, and velocity or camera transforms describe movement across frames. Some effects can reconstruct normals from depth; others need an application-provided normal texture.
| Effect family | Result | Main scene contract |
|---|---|---|
| SSAO and GTAO | Ambient visibility and contact darkening. | Depth, with normals and camera data for the richer path. |
| SSGI | Diffuse light from nearby visible surfaces. | Scene color, depth, normals, and temporal data. |
| SSR | Reflections from visible scene color and surfaces. | Depth, normals, camera data, and temporal data. |
| Depth of field | Blur based on distance from a focal plane. | Scene color, matching depth, and lens settings. |
| Outlines | Edge emphasis from depth or normals. | Depth and optionally a normal texture. |
| Motion blur | Streaking along screen movement. | Velocity and depth. |
| Fog and volumetric lighting | Extinction and in-scattered light. | Depth, camera data, and optional clustered light buffers. |
| HDR auto exposure | GPU-resident luminance metering and exposure adaptation. | HDR scene color and persistent exposure history. |
These families are not interchangeable. For example, ambient occlusion darkens blocked ambient light, SSGI adds diffuse bounce, and SSR adds visible reflections. The application must provide each selected pass with the buffers it declares.
References: modules/…/index.ts• L130-210 modules/…/ssao.ts• L10-25 modules/…/gtao.ts• L10-54 modules/…/screen-space-global-illumination.ts• L9-62 modules/…/screen-space-reflections.ts• L15-32 modules/…/motion-blur.ts• L8-10
Depth-driven effects
Depth-driven effects turn the view depth attachment into a useful scene measure. Depth of field maps distance from the focal plane to blur, depth-aware blur avoids mixing across surfaces, and fog reconstructs a position or ray so it can apply spatial extinction. The depth texture must match the scene color view and its clip-depth rules.
Depth of field has two reusable forms. dofCompositeShaderPass uses horizontal and vertical stages for separable blur. bokehDof uses a circular aperture gather for round blur. Both are local gathers, so they do not provide full foreground-scattering behavior.
References: modules/…/dof.ts• L26-46 modules/…/dof.ts• L214-285 modules/…/depth-aware-blur.ts• L8-16 modules/…/height-fog.ts• L14-30
Temporal effects
Temporal effects retain selected images across frames and validate old samples before blending them with the current frame. This reduces noise in effects such as TAA, SSGI, SSR, fog, volumetric lighting, and adaptive exposure. History can follow object velocity or reproject static geometry from camera matrices.
The temporal contract includes more than a history color. Depending on the effect, the system also needs prior depth, prior normals, velocity, jitter, or camera transforms. A camera cut or resize invalidates old view data, so the application must reset or recreate the affected history.
References: modules/…/temporal-antialiasing.ts• L8-13 modules/…/temporal-antialiasing.ts• L81-120 modules/…/camera-reprojection-temporal-antialiasing.ts• L11-43 modules/…/ssr-camera-temporal.ts• L10-32 modules/…/screen-space-shader-helpers.ts• L25-85
Lighting and atmospheric effects
Atmospheric effects combine scene depth with light and camera data to model media between the camera and visible surfaces. Height fog applies a shared height-based extinction model. Clustered volumetric lighting also reads point-light and cluster buffers, then integrates directional light, local light, and optional god rays before compositing the result.
GPU compute can prepare the cluster data that a volumetric effect consumes. The effect does not replace that data-producing step; it uses the buffers as part of its scene contract.
References: modules/…/height-fog.ts• L29-45 modules/…/clustered-volumetric-lighting.ts• L10-14 modules/…/clustered-volumetric-lighting.ts• L66-83 modules/…/clustered-volumetric-lighting.ts• L712-783
Effect configuration
Effect factories turn visual choices into a pass or composite pipeline. Per-frame uniforms tune the current camera, time, lens, and strength values, while construction options choose the shape and cost of the pipeline.
| Configuration area | Effect on the workflow |
|---|---|
| Effect order | Controls which result the next pass reads and whether HDR work happens before presentation. |
| Scene bindings | Supplies depth, normals, velocity, light clusters, selection masks, lens dirt, or history images. |
| Quality and resolution | Trades detail and temporal stability against pixel work and intermediate memory. |
| Target format | Preserves the numeric range needed for HDR or temporal data. |
| History policy | Selects persistent targets, their initial values, and when old data is valid. |
| Backend choice | Selects a fragment path or an available WebGPU compute optimization. |
Resolution is part of the visual contract. Lower-resolution tracing and denoising can reduce cost, but it can also reduce edge detail or make history less stable. A compute option does not change the visual purpose of a composite effect; it replaces selected work while the render path remains available as a fallback.
References: modules/…/screen-space-reflections.ts• L15-32 modules/…/screen-space-global-illumination.ts• L9-13 modules/…/gtao.ts• L10-16 modules/…/bloom-composite-shader-pass.ts• L47-92 modules/…/bloom-composite-shader-pass.ts• L1000-1158
Rendering workflow
The application renders the scene first, then runs the selected effects with matching inputs. The effects stage returns a texture or presents to the screen; it does not own scene geometry or the broader frame schedule.
When a frame uses reusable effects, the workflow is:
- Render scene color and the attachments required by the selected effects.
- Select or build the effect chain in the intended visual order.
- Bind the current scene buffers, external resources, and frame uniforms.
- Run each pass or composite graph and keep valid intermediate targets.
- Present the final image or return it for a later render stage.
- Preserve valid temporal targets for the next frame and reset them when the view contract changes.
For example, a scene can render HDR color, depth, normals, velocity, and clustered light data. Bloom can use the HDR color, a screen-space effect can use the G-buffer, and tone mapping can finish the chain after those effects have used the wider value range.
References: modules/…/dof.ts• L214-285 modules/…/screen-space-global-illumination.ts• L525-590 modules/…/clustered-volumetric-lighting.ts• L712-783 modules/…/tone-mapping.ts• L67-89
Change checklist
When these files or sections are changed, remember to consider these:
- When an effect moves into or out of
modules/engine/src/effects/, update the public engine export and all links or consumers that use the effect surface. - When a pass adds or renames a binding, update the scene-rendering contract and every workflow that supplies the binding.
- When a composite target changes scale, format, lifetime, or initialization, check HDR range, history validity, resize behavior, and target aliasing together.
- When effect order changes, check which result the next pass reads and whether tone mapping still follows HDR effects.
- When temporal inputs or camera transforms change, check history reset and disocclusion rules for cuts, movement, and resize.
- When a compute optimization changes its outputs or device requirements, keep the render fallback and storage format contract aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A screen-space effect receives no required depth, normal, velocity, or light data. | The effect cannot produce a valid result and may fail during setup. | Match the application attachments to the selected effect contract. |
| History remains after a camera cut, resize, or incompatible scene change. | Old pixels can ghost into the new view. | Reset or recreate the affected history before the next blend. |
| Bloom or tone mapping receives a clamped color target too early. | HDR highlight range is lost before bright-light effects use it. | Keep the HDR section in a suitable floating-point format and map to display range last. |
| A circular depth-of-field pass is used as a full foreground-scattering solver. | Nearby samples spread locally but foreground and background occlusion remain incomplete. | Use the circular pass for local bokeh and choose a method that models scattering when needed. |
| A composite step samples the target that it writes. | The render route is invalid. | Route through previous or a separate intermediate target. |
| Cluster buffers do not match the volumetric lighting layout. | Local light contribution is missing or the pass reads invalid data. | Keep light records, cluster counts, indices, and cluster dimensions synchronized. |
Key files
| File | Why to read it |
|---|---|
| modules/…/index.ts | Public engine effects surface and the main capability groups. |
| modules/…/fxaa.ts | Compact image-pass example for edge cleanup with a fixed quality choice. |
| modules/…/denoise.ts | Image-pass example for configurable noise reduction. |
| modules/…/vignette.ts | Image-pass example for configurable lens edge darkening. |
| modules/…/bloom-composite-shader-pass.ts | Complete example of quality choices, HDR targets, lens options, temporal history, and compute fallback. |
| modules/…/tone-mapping.ts | Example of a final image pass that maps HDR values for display. |
| modules/…/ssao.ts | Example of a depth and normal effect with lower-resolution intermediates and depth-aware denoising. |
| modules/…/screen-space-global-illumination.ts | Example of tracing, temporal history, spatial denoising, and final composition. |
| modules/…/screen-space-reflections.ts | Example of configurable reflection quality and velocity or camera reprojection. |
| modules/…/temporal-antialiasing.ts | Compact example of color and depth history across frames. |
| modules/…/clustered-volumetric-lighting.ts | Example of depth, clustered light buffers, atmospheric integration, history, and composition. |
| modules/…/dof.ts | Depth-driven blur with separable and circular-aperture forms. |
| modules/…/screen-space-shader-helpers.ts | Shared depth reconstruction and temporal validation concepts. |