Hazel

Post-Processing Effects

A fullscreen camera effect is one shader file. The file declares its own sliders in comments, so there is no Rust to write, nothing to compile and no plugin to install: put the .wesl in the project and drop it on a camera. Shader effects published on the Marketplace are files of exactly this shape.

The pass that runs them is renzora_postprocess, registered in RenderPhase::LdrPost.

Using an effect

  1. Select the camera, or the World Environment if the effect should apply to every camera.
  2. Add Component > Post Process.
  3. Drag the effect's .wesl from the Assets panel onto the drop zone at the top of the component.

Two shortcuts do the same: drop the .wesl on the viewport and it joins the scene's Post Process list (an existing one first, else the World Environment's, else the default camera's), or drop it on a Hierarchy row to add it to that entity's list. An effect file never goes on a mesh as a material: it is a different kind of shader, and the drop targets refuse it as one.

Each effect becomes a section with its sliders, an on switch, reordering and removal. Effects run in list order, each reading what the one above wrote, so a blur above a pixelation is a different picture from the same two the other way round.

A file that is not a usable effect still appears in the list, with a red message saying why, and the same message goes to the Console, so a mistake in a shader you are writing shows up where you are looking.

Writing one

The whole of a working effect:

// @effect(name = "Invert", icon = "circle-half")

@group(0) @binding(0) var screen_texture: texture_2d<f32>;
@group(0) @binding(1) var screen_sampler: sampler;

struct Settings {
    amount: f32,    // @slider(0, 1, default = 1)
};
@group(0) @binding(2) var<uniform> settings: Settings;

@fragment
fn fragment(@location(0) uv: vec2<f32>) -> @location(0) vec4<f32> {
    let c = textureSample(screen_texture, screen_sampler, uv);
    return vec4(mix(c.rgb, 1.0 - c.rgb, settings.amount), c.a);
}

Save it as shaders/invert.wesl and it can be dropped on a Post Process component at once. Edit it while it is in use and the effect, and its sliders, update when you save.

The header

The // @effect(...) comment is what makes a shader an effect; the drop zone refuses a shader without one.

SettingMeaning
namewhat the inspector calls the effect; defaults to the file name
icona Phosphor icon name; defaults to sparkle
freeze_whilefor effects that read a frozen frame, see below

// @effect alone, with no parentheses, is a valid header too.

Settings and sliders

The settings are an ordinary struct at @group(0) @binding(2). A comment after each field says how the inspector shows it:

CommentThe field is
// @slider(min, max)a slider over that range
// @slider(min, max, default = 0.5, step = 0.01, label = "Amount")the same, with a starting value, drag step and row label
// @hidden(default = 1)fixed at that value and not shown
nonea slider with no range, starting at 0

Two field names are filled in by the engine and take no comment:

  • time: seconds since startup, wrapped at 1024. A float second count loses precision after hours of uptime, and noise hashed from it starts to visibly step.
  • enabled: always 1, for older effects that read it. A switched-off effect is simply not drawn.

A field whose name starts with _ is hidden at 0.

Fields are f32, i32 or u32; an integer field's slider snaps to whole numbers. Never write padding: the engine takes each field's offset from the shader compiler (naga) and packs the buffer to match, so fields can be added, removed or reordered freely. Values are stored by field name, so a value you set survives the shader being edited around it.

The shader contract

  • Write the @fragment entry point only. The vertex stage is the engine's fullscreen triangle; its output arrives as @builtin(position) plus a @location(0) UV.
  • All bindings are in @group(0): 0 the frame so far, 1 its sampler, 2 the settings, and 3 and 4 a frozen frame (below). Anything else is refused with a message naming the binding, because the pass does not provide it.
  • One file, no imports. An effect is compiled on its own. Plain WGSL is valid WESL, which is why .wesl works for both.
  • Effects run after tonemapping, on the picture as it will be shown, with values from 0 to 1. Work that needs light above 1 belongs earlier in the frame, as a render pass (below).

For animation, read settings.time. Scale it in the shader when a slider sets the speed, and feed time in as its own hash input rather than adding it to the sample position: offsetting the position slides one fixed noise pattern across the picture, which reads as dirt on the lens instead of grain regenerating in place.

Effects that need the previous frame

A transition fades from what was on screen. Declare bindings 3 and 4 and the pass gives the effect a copy of the frame as it arrived, beside the live one:

// @effect(name = "Screen Transition", icon = "arrows-left-right", freeze_while = "progress < 1")

@group(0) @binding(3) var frozen_texture: texture_2d<f32>;
@group(0) @binding(4) var frozen_sampler: sampler;

freeze_while names a settings field and a comparison (<, <=, >, >=, ==, !=). While it holds, the copy stops updating, so the effect blends from a fixed picture. Here, setting progress to 0 freezes the outgoing frame, and animating it back to 1 wipes to the live one.

Checking effects in bulk

cargo run --profile dist -p renzora_postprocess --example check_effects -- <folder>

parses every .wesl and .wgsl under a folder exactly as the engine does and lists each effect's sliders, or why it would not load. Run it before publishing a set of effects.

Cost

  • An effect's pipeline is built the first time the effect is used; nothing else is compiled per effect.
  • A camera with no effects costs nothing: the pass returns at once.
  • Each effect is one fullscreen pass. Fewer, fuller shaders beat many thin ones.

When an effect is not one shader

An effect file is one fullscreen fragment pass over the current picture. Anything else is a render pass in a plugin: implement RenderPass and register it on the render sub-app with add_render_pass(id, phase, order, pass) (from RenderCompositionAppExt), which places it in one of four phases:

RenderPhaseImageTypical use
GiHDR, after the main 3D pass, before temporal AAglobal illumination, screen-space reflections (running before TAA puts them in the temporal history)
HdrPostHDR, after temporal AAbloom, depth of field, motion blur
LdrPostLDR, after tonemappingcolour grading and stylisation; effect files run here
Overlayfinal, after AAdebug visualisations, overlays

order sorts passes within a phase. See Render Pipeline for the frame as a whole and Shaders for writing WESL.