CineCode
Reference

Shaders

The WGSL shader contract — entry point, uniforms, bindings, and compositing order.

Shaders run on the GPU backend only (--gpu). Declare them in the manifest, then apply them in a scene.

codescene.toml
[shaders]
aurora = "shaders/aurora.wgsl"

The entry point

Every CineCode shader implements a single function:

fn shade(uv: vec2<f32>, local: vec2<f32>, frag: vec2<f32>) -> vec4<f32> {
    // return the RGBA color for this pixel
}
ArgumentMeaning
uvNormalized coordinate in the target region, 01.
localLocal coordinate within the applied rect.
fragPixel coordinate in the frame.

Uniforms

A uniform block u is bound and available inside shade:

FieldDescription
resolutionFrame resolution in pixels.
timeSeconds since the scene start.
progressNormalized progress 01.
rectThe applied region rectangle.
paramsFour floats from .params(a, b, c, d).
opacityCurrent opacity.
thresholdBloom/threshold control.
intensityEffect intensity.

Bindings

BindingTypeDescription
srctexture_2d<f32>The content currently under the shader.
sampsamplerSampler for src.
uUniformsThe uniform block above.

Sample the underlying content like this:

let base = textureSample(src, samp, uv);

Applying shaders

CallWhere it draws
s.background_shader(name)Full-frame, behind all content.
s.shader(name, x, y, w, h)A rectangular region; samples the content beneath.
s.shader_fill(name, x, y, w, h)Fills a region, ignoring content beneath.
s.overlay_shader(name)Full-frame, on top of all content.
.params(a, b, c, d)Pass up to four floats into the shader's u.params.

Compositing order

For each frame the GPU backend composites in this order:

background shaders → CPU/content draw → region & overlay shaders → bloom

Enable bloom at render time:

cinecode render my-video -o out.mp4 --gpu --bloom 0.8

Example

shaders/scanlines.wgsl
fn shade(uv: vec2<f32>, local: vec2<f32>, frag: vec2<f32>) -> vec4<f32> {
    let base = textureSample(src, samp, uv);
    let line = 0.85 + 0.15 * sin(frag.y * 3.14159 + u.time * 4.0);
    return vec4<f32>(base.rgb * line, base.a);
}
Background, region, and overlay shaders plus bloom.
Files that made this video

The GPU effects scene: a scene script, one Rust source file, and three WGSL shaders registered in the manifest.

codescene.toml
Project manifest: output size, theme, scene order, transitions, and shader names.
Open full file
scenes = ["scenes/intro.ccs", "scenes/terrain.ccs", "scenes/pathfind.ccs", "scenes/particles.ccs", "scenes/graph.ccs", "scenes/life.ccs", "scenes/boids.ccs", "scenes/tweens.ccs", "scenes/inserts.ccs", "scenes/edit.ccs", "scenes/edit_source.ccs", "scenes/editor_theme.ccs", "scenes/font_set.ccs", "scenes/remove_styles.ccs", "scenes/morph.ccs", "scenes/shapes.ccs", "scenes/effects.ccs"]
theme = "dark_documentary"

[episode]
title = "How Rivers Form"

[output]
fps = 30
width = 1280
height = 720

[shaders]
aurora = "shaders/aurora.wgsl"
glitch = "shaders/glitch.wgsl"
scanlines = "shaders/scanlines.wgsl"

[transition]
kind = "crossfade"
frames = 18

See also: Apply GPU shaders.

On this page