p5.tree/pipe

Post-processing the frame with shaders.

Run a drawn layer through one or more filter shaders — blur, pixelate, vignette, colour grading — and show the result on the canvas, or keep it in a framebuffer for further use. pipe() chains the passes for you; releasePipe() frees the framebuffers it kept for a chain.

Reach for it when a baseFilterShader() effect should apply to a whole rendered frame rather than to a single shape.

p5

pipe(source, passes, [opt])

Run a source texture through one or more filter shaders in sequence and draw the result on the canvas, or keep it off-screen and use the returned framebuffer with display set to false (see the off-screen example). The two working framebuffers are managed for you; key separates independent chains, and ping/pong let you supply your own. Needs a WEBGL canvas, a source, and filter shaders.

ParameterTypeDefaultDescription
source p5.Framebuffer|p5.Texture|p5.Image|p5.Graphics Input texture; a Framebuffer contributes its .color.
passes p5.Shader|p5.Shader[] A pass or array of passes (e.g. baseFilterShader().modify(...)); falsy entries ignored.
opt optional Object Options.
opt.display optional boolean true If true, draw the final output to the main canvas.
opt.allocate optional boolean true If true, create the two working framebuffers when missing (kept per key).
opt.key optional string 'default' Name of the working framebuffer pair; give each independent chain its own key.
opt.ping optional p5.Framebuffer Your own first working framebuffer (advanced; not kept by pipe()).
opt.pong optional p5.Framebuffer Your own second working framebuffer (advanced; not kept by pipe()).
opt.clear optional boolean true If true, clear each working framebuffer before a pass draws into it.
opt.clearDisplay optional boolean true If true and display is true, clear the main canvas before drawing the final output.
opt.clearFn optional function How to clear a working framebuffer before a pass. Defaults to background(0).
opt.clearDisplayFn optional function How to clear the main canvas before the final output. Defaults to clearFn.
opt.draw optional function How to draw the current texture onto the current target. Defaults to a full-canvas copy.

Returns p5.Framebuffer|null The framebuffer holding the final result, or null when no working framebuffers were available.

One pass: a pixelate filter, its level driven by the mouse
A chain kept off-screen: the returned framebuffer textures a pane

releasePipe([key])

Free the framebuffers pipe() cached for a pipeline: the default one, a named key, or every pipeline with true (see the example). Framebuffers you supplied yourself are left alone.

ParameterTypeDefaultDescription
key optional string|boolean If omitted, releases the default key ('default'). If a string, releases only that key. If true, releases all keys.
Free a keyed pipeline's buffers when its effect is switched off