Move horizontally to pan along the coast.

0:01 / 0:30
Playback speed

Full-screen ordered dithering

Use two levels per channel. Follow the sun’s edge as it crosses the stationary grid.

Interactive demo#PixelLookScreen-space effects and shadersPS1 era

Apply a repeating threshold to the finished frame to trade smooth gradients for a limited colour palette.

Sample the landscape at each screen pixel, scale each colour channel to the output range, then use the Bayer rank at that pixel to round it. The pattern covers the sky, the lighthouse and the water. Pan along the coast and the grid stays fixed to the screen.

Code

src/demos/screen_dither.goose
namespace screen_dither_lesson;
import stage;
import std;
import math;

var pixels: u8[64000] = [0;64000];

export "screen-dither" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    load_texture("coast");
    let levels = number_control("levels", 4) - 1.0;
    let pan = if hover { px } else { 80 + 72 * sin(time * 0.55) };
    for y in 100 {
        for x in 160 {
            var rgb = coast_sample(x, y, pan);
            let threshold = bayer_threshold(x, y);
            for c in 3 { rgb[c] = floor(rgb[c] / 255 * levels + threshold) * 255 / levels; }
            put_rgb(pixels[..], x, y, rgb[0], rgb[1], rgb[2]);
        }
    }
    pixel_buffer(pixels[..], 160, 100);
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.