Expand description
CPU fragment-shader effects packed into half-block cells. CPU fragment-shader toolkit: a GPU-style program trait and a rasterizer that packs per-pixel shading into half-block cells.
The mental model is a fullscreen GPU pipeline at terminal resolution:
implement [Program] — a per-frame advance, a
per-pixel fragment, and an optional point-sprite
particles pass — or use a plain
Fn(f32, f32) -> (Vec3, f32) closure for a still field. Then either
mount it in a retained tree with crate::components::Shader or paint
it into any cell grid with [Surface::render].
One terminal cell is a 1×2 pixel column (▀ foreground over
background), so a cols × rows viewport is a cols × rows·2 pixel
target with square pixels on a typical 1:2 cell. Everything is a pure
function of the caller’s clock, so animated effects stay deterministic
and testable.
§Example
use omp_tui::{
scene::{Vec3, vec3},
shader::Surface,
};
// A vertical dusk gradient: any `Fn(x, y) -> (color, coverage)` closure.
let mut dusk = |_: f32, y: f32| (vec3(0.9, 0.4, 0.2).lerp(vec3(0.05, 0.05, 0.2), y / 16.0), 1.0);
let mut lit = 0;
Surface::new().render(&mut dusk, std::time::Duration::ZERO, 20, 8, |_, _, _, _, _| lit += 1);
assert_eq!(lit, 20 * 8);Structs§
Traits§
- Program
- A fullscreen effect: per-frame state plus a shader for every pixel.