Ridge: near-cover check measures a notch against 8 columns each side; scrim kept over the settled still

The body-end check compared each column only with its neighbour, so an early
dissolve that eased over a few columns passed it. It now refuses a column whose
body ends more than 40 px short of the deepest end within 8 columns either side.
The old Vienna bake (12e733dc9f09) fails it at column 1251 (42 px); the committed
rebake (f25b2314a20c) passes in all six frames. Mutants added for the window.

The night scrim was dropped when the scene settled to a still frame; it is now
rebuilt over the canvas after the planes are painted (gradient with planes, flat
without), with a test for both.

Recovered from Nibu's uncommitted work at the 2026-11-17 brake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-17 15:49:14 +01:00
commit 24e1a1c3e2
6 changed files with 66 additions and 30 deletions

View file

@ -27,7 +27,8 @@ LUMA_SKY = 0.5 # the flat mid-grey sky the planes are co
LUMA_COVER = 0.5 # composite coverage (1 - prod(1 - alpha)) at or above which a pixel is measured
NEAR_CREST_ALPHA = 64 # alpha (0..255) at which a near-plane pixel counts as the ridge's body: the crest of a column is its first such row
NEAR_BODY_ALPHA = 40 # alpha at which a near-plane pixel still counts as body when finding where a column's body ends
NEAR_END_STEP_PX = 24 # the most the row where the body ends may differ between neighbouring columns: a step is where the near plane dissolves early over a few columns (Vienna had 55 px at x 1252)
NEAR_END_DROP_PX = 40 # how far the row where the body ends may fall short of the deepest end within NEAR_END_WINDOW columns: a notch where the near plane dissolves early over a few columns (Vienna had 60 at x 1252-1280; natural terrain 22)
NEAR_END_WINDOW = 8
NEAR_HOLE_ALPHA = 24 # alpha below which a pixel under the crest is a hole (the sky would show through the ground in front of the eye)
SHEET_SKY = (0.80, 0.86, 0.94) # the flat sky of the contact sheet
ATTRIBUTION = dict(
@ -104,14 +105,15 @@ def luma_range(decoded):
return float(y.min()), float(y.max())
def check_near_cover(near, horizon_row):
"""Refuse a near plane (RGBA uint8) that does not cover the ground in front of the eye: every column must have a crest (an alpha >= NEAR_CREST_ALPHA row), and from the crest down to the horizon row no pixel may be a hole (alpha < NEAR_HOLE_ALPHA), and the row where the body ends may not step more than NEAR_END_STEP_PX between neighbouring columns.
"""Refuse a near plane (RGBA uint8) that does not cover the ground in front of the eye: every column must have a crest (an alpha >= NEAR_CREST_ALPHA row), and from the crest down to the horizon row no pixel may be a hole (alpha < NEAR_HOLE_ALPHA), and the row where the body ends may not fall more than NEAR_END_DROP_PX short of the deepest end within NEAR_END_WINDOW columns.
A transparent column, or a wedge of holes under a crest, shows the sky through the foreground; the farther planes may leave columns empty (a place with no ridge at that distance), the nearest may not."""
a = near[..., 3]; h, w = a.shape; crest = np.argmax(a >= NEAR_CREST_ALPHA, axis=0); none = ~(a >= NEAR_CREST_ALPHA).any(0)
if none.any(): raise ValueError(f'near plane: {int(none.sum())} fully transparent columns, first at x={int(np.argmax(none))}')
rows = np.arange(h)[:, None]; hole = (a < NEAR_HOLE_ALPHA) & (rows >= crest[None, :]) & (rows < int(horizon_row))
if hole.any(): x = int(np.argmax(hole.any(0))); raise ValueError(f'near plane: {int(hole.any(0).sum())} columns have a hole between the crest and the horizon, first at x={x} row {int(np.argmax(hole[:, x]))}')
body = a >= NEAR_BODY_ALPHA; end = h - 1 - np.argmax(body[::-1], axis=0); step = np.abs(np.diff(end)) # the body's last row, per column: the dissolve below the horizon has no edge of its own
if (step > NEAR_END_STEP_PX).any(): x = int(np.argmax(step > NEAR_END_STEP_PX)); raise ValueError(f'near plane: the body ends at row {int(end[x])} in column {x} and row {int(end[x + 1])} in column {x + 1}, a step over {NEAR_END_STEP_PX} px')
body = a >= NEAR_BODY_ALPHA; end = h - 1 - np.argmax(body[::-1], axis=0) # the body's last row, per column: the dissolve below the horizon has no edge of its own
deepest = np.lib.stride_tricks.sliding_window_view(np.pad(end, NEAR_END_WINDOW, mode='edge'), 2 * NEAR_END_WINDOW + 1).max(-1); notch = deepest - end
if (notch > NEAR_END_DROP_PX).any(): x = int(np.argmax(notch > NEAR_END_DROP_PX)); raise ValueError(f'near plane: the body ends {int(notch[x])} px short of its neighbours in column {x} (row {int(end[x])}), a notch over {NEAR_END_DROP_PX} px')
def check_budget(frame_bytes, plane_w, plane_h):
"""Refuse a bake the runtime could not hold: any two adjacent frames (night with dawn too) above PAIR_BYTES_MAX, or the planes of a frame pair decoding above DECODE_BYTES_MAX."""