Module post

Source
Expand description

Opt-in full-screen post-processing: bloom, tonemapping, grading, vignette and optional film grain, chromatic aberration and scanlines.

Games choose a PostFx with set_post_fx. The setting is sticky: it stays active across frames (and clear_background) until replaced, so a game usually sets it once per scene. PostFx::off() (the default) restores the original direct-to-screen path with zero extra GPU work.

While post-processing is active, the world is drawn into an offscreen target. At the world/HUD boundary the hosts resolve that target, run the bloom chain and composite the graded image to the screen; every later draw (HUD, menus, the Controls editor) is drawn directly on top, crisp, un-bloomed and un-vignetted. The boundary is the first of:

  • an explicit post_fx_hud_begin;
  • set_world_colors(false) while world colors are enabled;
  • set_default_camera() while world colors are enabled (that is, after a set_camera in the same frame).

The last two follow the existing world-palette boundary and can be disabled with PostFx::auto_hud. Without a boundary, the whole frame is post-processed. Only the first boundary in a frame counts.

Player preferences and accessibility always win over authored settings:

  • An explicit Low quality choice (Details, ?quality=low or FERRAVEX_QUALITY=low) disables post-processing. Medium uses a four-level bloom chain; High uses five levels. Without a player choice, an authored set_quality(High) selects High and anything else selects Medium.
  • Sustained adaptive-performance pressure (level 2 and above) caps the tier at Medium.
  • Reduced flash caps bloom intensity at REDUCED_FLASH_BLOOM and disables grain and chromatic aberration.

Developers can force a preset for a session with FERRAVEX_POST=off|subtle| neon|warm-film|crt (native) or ?post=… (browser) without editing a game.

use ferravex_render::{input, post::{self, PostFx, PostTier}};
post::set_post_fx(PostFx::neon().vignette(0.25, 0.6));
let status = input::host_frame(1. / 60., 320, 200, || {
    ferravex_render::clear_background(ferravex_render::BLACK);
    // World: bright additive accents feed the bloom.
    post::glow_circle(160., 100., 24., ferravex_render::ORANGE, 1.5);
    // HUD: drawn after the boundary, it stays crisp.
    post::post_fx_hud_begin();
    ferravex_render::draw_rectangle(8., 8., 40., 6., ferravex_render::WHITE);
    post::post_fx_status()
});
assert_ne!(status.tier, PostTier::Off);
post::set_post_fx(PostFx::off());

Structs§

PostFx
Authored post-processing settings. Start from a preset and adjust with the builder methods. Values are sanitized when applied: non-finite numbers use the neutral value and every field is clamped to its documented range.
PostStatus
Effective post-processing state for the current settings and preferences.

Enums§

PostTier
Effective post-processing tier after preferences, accessibility and adaptive performance are applied.
Tonemap
How bloom and over-bright scene values are mapped to the display.

Constants§

MAX_BLOOM_LEVELS
Maximum bloom chain length used by the High tier.
POST_COMPOSITE_FRAGMENT_BODY
Final composite: bloom upsample, exposure, tonemap, lift/gamma/gain, power-law contrast, saturation, vignette, scanlines, grain and a static sub-LSB dither (interleaved gradient noise) against 8-bit banding. u_texel.xy is the bloom texel size and u_texel.zw the scene texel size.
POST_DOWN_FRAGMENT_BODY
Dual-filter downsample. u_texel.xy is the source texel size; u_texel.z selects the bright-pass prefilter (threshold u_bloom.x, knee u_bloom.y).
POST_FRAME_FLOATS
Number of f32 values in the resolved per-frame host block.
POST_UP_FRAGMENT_BODY
Dual-filter tent upsample. u_texel.xy is the source texel size and u_texel.z the radius; hosts additively blend into the larger level.
POST_VERTEX_BODY
Full-screen triangle; no vertex attributes. Hosts prepend their GLSL version/precision header.
REDUCED_FLASH_BLOOM
Bloom intensity cap applied while the player requests reduced flash.

Functions§

glow_circle
Soft additive radial glow in the current camera’s 2D coordinates (z = 0). intensity multiplies RGB and may exceed one: over-bright values bloom more strongly on half-float targets. Uses 112 unlit triangles; the world palette still applies inside a world camera.
post_fx
Current authored settings (before session overrides and preferences).
post_fx_hud_begin
Mark the world/HUD boundary explicitly. Draws after this call go straight to the screen on top of the post-processed world. Returns true when this call recorded the frame’s boundary; false if post-processing is off or a boundary already exists in this frame.
post_fx_status
Effective tier, bloom levels and capped settings for the current state.
set_post_fx
Replace the sticky post-processing settings. Takes effect for the current frame’s composite; use PostFx::off() to return to direct rendering.
with_glow
Draw immediate primitives (rectangles, circles, lines, text, meshes) with additive blending inside draw, so bright shapes accumulate light and feed the bloom. Equivalent to EffectBlend::Additive for immediate geometry; works with post-processing off as plain additive blending.