Add 2D canvas mode compacted to the steps, ocean-chaos and reef-2d shaders

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
April John 2026-10-16 15:28:41 +02:00
commit d917860201

View file

@ -68,3 +68,40 @@ def test_brightness_scales_and_clamps():
assert t.to_rgbw(px, "extract", 0).max() == 0
np.testing.assert_allclose(t.to_rgbw(px, "extract", 500),
t.to_rgbw(px, "extract", 100))
CANVAS_SHADER = """
void mainImage(out vec4 c, in vec2 p) {
// red in the two lowest rows, and in the two leftmost columns (step 0)
c = vec4(p.y < 2.0 ? 1.0 : 0.0, p.x < 2.0 ? 1.0 : 0.0, 0.0, 1.0);
}"""
def test_canvas_compaction_modes():
ctx, _ = t.create_context(window=False)
r = t.Renderer(ctx)
r.load(CANVAS_SHADER)
r.configure((32, 4), "mean") # 2 columns per step, 4 rows
px = r.render_strip(0.0)
assert px.shape == (16, 4)
np.testing.assert_allclose(px[:, 0], 0.5) # 2 of 4 rows
np.testing.assert_allclose(px[0, 1], 1.0) # step 0 green
np.testing.assert_allclose(px[1:, 1], 0.0)
r.configure((32, 4), "max")
np.testing.assert_allclose(r.render_strip(0.0)[:, 0], 1.0)
r.configure((32, 4), "row") # row 2 is dark
np.testing.assert_allclose(r.render_strip(0.0)[:, 0], 0.0)
r.configure(None) # back to 1D
assert r.render_strip(0.0).shape == (16, 4)
def test_canvas_parsing():
assert t.parse_canvas("256x32") == (256, 32)
for bad in ("100x10", "abc", "8x8", "256x0"):
with pytest.raises(ValueError):
t.parse_canvas(bad)
assert t.directive("// x\n// canvas: 128x16 compact: max\nvoid f(){}") == (
(128, 16), "max")
assert t.directive("void mainImage() {}") == (None, None)
with pytest.raises(ValueError):
t.directive("// canvas: 128x16 compact: nope")