Bloom

Watch the dark pixels just outside a bright shape. Toggle bloom and see how far its glow reaches.
Interactive demo#LightAndGlowScreen-space effects and shadersPS2 era
Bright areas bleed a soft glow into their surroundings.
The game copies only the brightest parts of the picture, blurs the copy, and adds it back on top. It imitates how a camera lens or your eye smears very bright light.
Code
namespace bloom_lesson;
import stage;
import std;
import math;
// Only the hot glass enters the low-resolution brightness buffer.
fn emitters() {
for x, i in [26, 80, 134] {
ell(x, 44, 2.0, 2.4, if i == 1 { "#ff9f62" } else { "#ffdb80" });
}
}
export "bloom" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("hall", 0, 0, W, 125);
ground();
rect(0, 0, W, H, "rgba(13,22,45,.73)");
for x in [26, 80, 134] {
line(x, 0, x, 34, "#504a45");
draw_prop("lantern", x - 4.5, 33, 9, 18);
}
actor(54, GY, STAND);
emitters();
if toggle("on") {
buffer_start(40, 25, 0.25);
emitters();
buffer_end();
save();
smooth(true);
additive(true);
// Spread light equally around each source with concentric filter taps.
for r in 3 {
let radius = 2.0 + r * 3.0;
opacity((0.18 - 0.055 * r) * (1 + 0.08 * sin(time * 5)));
for i in 8 {
let angle = i * PI / 4;
buffer_draw(radius * cos(angle), radius * sin(angle), W, H);
}
}
restore();
}
}

Comments
No comments yet.