Skip to content

Built-in effects ​

Parameters of every post-processing effect, and a typical chain order.

All effects are functions that return an EffectPass or CompositeEffectPass. Use them in postEffects, and update their uniforms afterwards like any other pass.

ts
import { bloom, fxaa, glCanvas, hableToneMapping, trails } from "@radiancejs/gl";

glCanvas({
  canvas: "#glCanvas",
  fragment,
  postEffects: [
    trails({ fadeout: 0.25 }),
    bloom({ radius: 0.5, mix: 0.8 }),
    hableToneMapping({ exposure: 1.2 }),
    fxaa(),
  ],
});

bloom(params?) ​

Downsampling / upsampling pyramid that adds glow around bright areas. A CompositeEffectPass. Based on the Unreal Engine bloom.

ParamTypeDefaultUniformMeaning
levelsnumber8—depth of the mip pyramid
radiusnumber0.65uRadiusblur radius of the upsampling stages
mixnumber0.5uMixglow intensity blended over the input

Example: Bloom.

trails(params?) ​

Double-buffered frame accumulation behind moving objects. A CompositeEffectPass.

ParamTypeDefaultUniformMeaning
fadeoutnumber0.25uFadeouthow fast trails decay (higher = shorter)
erosionnumber0uErosionshrinks the trail (squared internally)
tailColor[number × 4][1,1,1,1]uTailColorcolor the trail fades to
tailColorFalloffnumber0uTailColorFalloffhow quickly the color becomes the tail color

Example: Trails.

noise(params?) ​

Procedural noise over the image.

ParamTypeDefaultUniformMeaning
intensitynumber0.5uIntensitystrength of the noise (0–1)
sizenumber2uSizenoise cell size in pixels (1–5)
colorMixnumber0.5uColorMix0 = monochrome, 1 = colored noise
timenumberframe timeuTimeseed; assign () => 0 to freeze the noise

Example: Noise.

pixelate(params?) ​

Snaps the image to a grid of square blocks. Each block samples the input once, at its center. One full-screen pass with a single texture fetch and no extra render target.

ParamTypeDefaultUniformMeaning
sizenumber8uSizeblock size in CSS pixels (1 = no pixelation)

size is independent of the device pixel ratio, so a given value looks the same on any display. Assign pixelateEffect.uniforms.uSize to change it at runtime.

Smoother and cheaper

For a smoother pixelated look, render the scene into a small texture and upscale it with magFilter: "nearest". Downsampling averages the source, so the blocks keep more detail, and far fewer fragments are shaded. On a canvas rendered at a low dpr, image-rendering: pixelated on the canvas gives the same blocky look with no shader pass at all.

Example: Pixelate.

Dither ​

Dithering effects quantize the image to a small palette and use patterns to make the missing shades read from a distance. All use a single full-screen pass and need no extra render target. Tone map first with outputColorSpace: "linear", then apply them as the last effect.

FunctionLookExtra param
ditherBayer(params?)classic cross-hatch ordered matrixmatrix (2, 4 or 8, default 8)
ditherBlueNoise(params?)smooth, no visible pattern (recommended)—
ditherIgn(params?)soft film-like grain—
ditherWhiteNoise(params?)uncorrelated static—
ditherHalftone(params?)angled round dots, print screenangle (degrees, default 15)

Shared params:

ParamTypeDefaultUniformMeaning
sizenumber1uSizecell size in CSS pixels, rounded to whole device pixels (ditherHalftone defaults to 4)
colorbooleantrueuColortrue = each channel dithered on its own, false = grayscale
levelsnumber3uLevelsvalues per channel in the palette, at least 2

levels sets the palette: in grayscale it is the number of grays (2 is pure black and white), in color it is the number of values per channel (levels³ colors: 3 gives 27 and 2 gives the 8 corners of the RGB cube). Values are evenly spaced in sRGB, so 4 gives 0, 85, 170 and 255. The default is 3 (0, 128, 255).

The effects expect linear input and write sRGB output. Between the two nearest palette values the pattern is mixed in linear light, so the average light matches the source and the image keeps its brightness. If you need tone mapping, use outputColorSpace: "linear", and dither after it: the tone map compresses HDR without clipping. Dithering before the tone map clips anything above 1; feeding sRGB values (the tone mapping default) applies the sRGB curve twice and brightens the image.

ditherBlueNoise samples a 32×32 void-and-cluster mask one texel per dither cell.

For ditherHalftone, size is the distance between dot centres, not their diameter. Dots occupy only part of each cell, so halftone looks finer than the solid-cell patterns at the same value; increase size for a coarser screen.

Example: Dither.

fxaa() ​

Fast approximate anti-aliasing. Detects luminance edges and blends along them. No parameters — place it last so it sees final pixels.

Example: FXAA.

Tone mapping ​

Seven operators mapping HDR values to the display. All return an EffectPass and share ToneMappingParams:

ParamTypeDefaultUniformMeaning
exposurenumber1uExposuremultiplier applied before the curve
outputColorSpace"sRGB" | "linear""sRGB"uConvertToSRGBfinal transfer function
FactoryCurveExtra param
linearToneMappingexposure then clamp—
reinhardToneMappingx / (1 + x)whitePoint (default 1)
hableToneMappingUncharted 2 filmic—
acesToneMappingACES filmic—
neutralToneMappingKhronos neutral (hue preserving)—
cineonToneMappingfilm-scan look—
agxToneMappingAgX filmic—

reinhardToneMapping also takes whitePoint: number (uniform uWhitePoint) — luminance mapped to 1; values above 1 enable the extended curve.

Choosing between them: Tone map the output.

Typical chain ​

scene → [stylize] → [trails] → [bloom] → [tone mapping] → [fxaa] → canvas

Reasoning: accumulate before glowing, glow before compressing, anti-alias the final pixels. See Chain and order post effects.

Writing your own ​

Anything with the effect contract slots into the same list — effectPass for one step, compositeEffectPass for several.

See also ​

Released under the MIT License.