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:
parent
c10f02a4a1
commit
24e1a1c3e2
6 changed files with 66 additions and 30 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -91,7 +91,8 @@ M = {
|
|||
'near foot step not eased (the widest foot in the margin dropped)': ('ridge.py', 'return np.maximum(blurw(slide_max(foot, NEAR_FOOT_MARGIN_PX), NEAR_FOOT_MARGIN_PX / 2.0), foot)', 'return foot'),
|
||||
'near foot widest-in-margin without the easing': ('ridge.py', 'blurw(slide_max(foot, NEAR_FOOT_MARGIN_PX), NEAR_FOOT_MARGIN_PX / 2.0)', 'slide_max(foot, NEAR_FOOT_MARGIN_PX)'),
|
||||
'near foot margin of one column': ('ridge.py', 'NEAR_FOOT_MARGIN_PX = 48', 'NEAR_FOOT_MARGIN_PX = 1'),
|
||||
'near cover allows any step in where the body ends': ('export.py', 'NEAR_END_STEP_PX = 24 ', 'NEAR_END_STEP_PX = 600 '),
|
||||
'near cover allows any notch in where the body ends': ('export.py', 'NEAR_END_DROP_PX = 40 ', 'NEAR_END_DROP_PX = 600 '),
|
||||
'near cover looks at no neighbour (window of zero)': ('export.py', 'NEAR_END_WINDOW = 8', 'NEAR_END_WINDOW = 0'),
|
||||
'near cover measures the body end at alpha above any pixel': ('export.py', 'NEAR_BODY_ALPHA = 40 ', 'NEAR_BODY_ALPHA = 256 '),
|
||||
'near cover looks below the horizon too': ('export.py', '& (rows < int(horizon_row))', '& (rows < h)'),
|
||||
'near cover crest threshold above any alpha': ('export.py', 'NEAR_CREST_ALPHA = 64 ', 'NEAR_CREST_ALPHA = 256 '),
|
||||
|
|
|
|||
|
|
@ -461,9 +461,9 @@ def test_near_foot_reaches_the_horizon_and_a_step_in_it_is_eased_not_cut():
|
|||
assert np.abs(np.diff(f)).max() < 8.0, np.abs(np.diff(f)).max()
|
||||
assert ridge.near_foot(np.full(400, 1.0), np.full(400, 5.0)).min() >= 5.0 * ridge.PXDEG_V / ridge.FADE_AT - 1e-6
|
||||
ok = np.zeros((60, 40, 4), np.uint8); ok[10:, :, 3] = 200; export.check_near_cover(ok, 30.0)
|
||||
early = ok.copy(); early[25:, 30:, 3] = 0
|
||||
try: export.check_near_cover(early, 20.0)
|
||||
except ValueError as e: assert 'step' in str(e), str(e)
|
||||
early = ok.copy(); early[15:, 30:, 3] = 0
|
||||
try: export.check_near_cover(early, 12.0)
|
||||
except ValueError as e: assert 'notch' in str(e), str(e)
|
||||
else: assert False, 'a near plane whose body ends early in a few columns was accepted'
|
||||
def test_write_bake_refuses_a_near_plane_with_a_wedge_and_lets_the_other_planes_have_empty_columns():
|
||||
"""The refusal is at the writer, on the decoded near plane of every frame; the far and mid planes may have transparent columns (a place with no ridge at that distance in part of the window)."""
|
||||
|
|
|
|||
|
|
@ -413,7 +413,9 @@ describe('the starfield in the scene', () => {
|
|||
const { parent, canvas } = host();
|
||||
createRidgeScene({ canvas, tier: 'still', sky: night });
|
||||
expect(count('star')).toBe(N);
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(
|
||||
parent.children.filter((c: any) => c !== canvas).map((c: any) => c.style.pointerEvents)
|
||||
).toEqual(['none']); // only the scrim
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
});
|
||||
|
||||
|
|
@ -467,7 +469,7 @@ describe('the starfield in the scene', () => {
|
|||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'full', sky: night })!;
|
||||
runFrames(100, 100);
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
expect(parent.children.filter((c: any) => c !== canvas)).toHaveLength(1); // the scrim stays
|
||||
expect(count('star')).toBe(N);
|
||||
expect(rafQueue).toHaveLength(0);
|
||||
s.dispose();
|
||||
|
|
@ -569,7 +571,7 @@ describe('the ridge planes in the scene', () => {
|
|||
expect(parent.children).toEqual([canvas]);
|
||||
});
|
||||
|
||||
it('the scrim never takes a tap or a row\'s size, and is flat and heavier when the planes are missing', () => {
|
||||
it("the scrim never takes a tap or a row's size, and is flat and heavier when the planes are missing", () => {
|
||||
const withPlanes = host();
|
||||
createRidgeScene({ canvas: withPlanes.canvas, tier: 'full', sky: night, backdrop: NOON });
|
||||
const flat = host();
|
||||
|
|
@ -586,6 +588,22 @@ describe('the ridge planes in the scene', () => {
|
|||
expect(SCRIM_ALPHA.flat).toBeGreaterThan(SCRIM_ALPHA.planes);
|
||||
});
|
||||
|
||||
it('the settled still keeps the scrim over the canvas: gradient with planes, flat without', () => {
|
||||
for (const [backdrop, flat] of [
|
||||
[NOON, false],
|
||||
[undefined, true],
|
||||
] as const) {
|
||||
const { parent, canvas } = host();
|
||||
const s = createRidgeScene({ canvas, tier: 'still', sky: night, backdrop })!;
|
||||
const scrims = parent.children.filter((c: any) => c.style.background);
|
||||
expect(scrims).toHaveLength(1);
|
||||
expect(scrims[0].style.background).toBe(scrimBackground(night, !flat));
|
||||
expect(scrims[0].style.pointerEvents).toBe('none');
|
||||
s.dispose();
|
||||
expect(parent.children).toEqual([canvas]);
|
||||
}
|
||||
});
|
||||
|
||||
it('a day sky has no scrim', () => {
|
||||
const { parent, canvas } = host();
|
||||
createRidgeScene({ canvas, tier: 'full', sky: DAY, backdrop: NOON });
|
||||
|
|
|
|||
|
|
@ -5,7 +5,14 @@ import { skyColours, SkyColours, Srgb } from './skyColour';
|
|||
import { paintSky as paintPhysicalSky } from './physicalSky';
|
||||
import { windowFor } from './view';
|
||||
import { crossfade } from './frameChoice';
|
||||
import { activeAt, drawStars, drawTwinkle as paintTwinkle, isNight, makeStars, Star } from './stars';
|
||||
import {
|
||||
activeAt,
|
||||
drawStars,
|
||||
drawTwinkle as paintTwinkle,
|
||||
isNight,
|
||||
makeStars,
|
||||
Star,
|
||||
} from './stars';
|
||||
import { drawRainTile, RAIN_TILES } from './rain';
|
||||
import type { Backdrop, Planes } from './Backdrop';
|
||||
import { PLANE_NAMES } from './manifest';
|
||||
|
|
@ -29,7 +36,9 @@ export const scrimBackground = (sky: SkyColours, hasPlanes: boolean): string =>
|
|||
const [r, g, b] = sky.top;
|
||||
const a = hasPlanes ? SCRIM_ALPHA.planes : SCRIM_ALPHA.flat;
|
||||
const c = (k: number) => `rgba(${r},${g},${b},${a * k})`;
|
||||
return hasPlanes ? `linear-gradient(to bottom, ${c(1)} 0%, ${c(1)} 55%, ${c(0)} 85%)` : `linear-gradient(${c(1)}, ${c(1)})`;
|
||||
return hasPlanes
|
||||
? `linear-gradient(to bottom, ${c(1)} 0%, ${c(1)} 55%, ${c(0)} 85%)`
|
||||
: `linear-gradient(${c(1)}, ${c(1)})`;
|
||||
};
|
||||
|
||||
const css = (c: Srgb): string => `rgb(${c[0]},${c[1]},${c[2]})`;
|
||||
|
|
@ -323,6 +332,24 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
});
|
||||
};
|
||||
|
||||
/** The legibility fill, appended over whatever the parent holds so far. Over a dark sky only: a light one is not the stars' problem, and a dark fill would hurt dark text. */
|
||||
const makeScrim = (): HTMLElement | undefined => {
|
||||
if (!isNight(sky)) return undefined;
|
||||
const scrim = document.createElement('div');
|
||||
scrim.setAttribute('aria-hidden', 'true');
|
||||
Object.assign(scrim.style, {
|
||||
position: 'absolute',
|
||||
left: '0',
|
||||
top: '0',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
pointerEvents: 'none',
|
||||
background: scrimBackground(sky, !!opts.backdrop),
|
||||
});
|
||||
parent.appendChild(scrim);
|
||||
return scrim;
|
||||
};
|
||||
|
||||
/** Paint the sky, the stars and the rain. Returns false when a 2D context is missing or there is no area yet. */
|
||||
const build = (): boolean => {
|
||||
teardown();
|
||||
|
|
@ -353,22 +380,7 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
});
|
||||
parent.appendChild(twinkle);
|
||||
}
|
||||
// Over a dark sky only: a light one is not the stars' problem, and a dark fill would hurt dark text.
|
||||
let scrim: HTMLElement | undefined;
|
||||
if (isNight(sky)) {
|
||||
scrim = document.createElement('div');
|
||||
scrim.setAttribute('aria-hidden', 'true');
|
||||
Object.assign(scrim.style, {
|
||||
position: 'absolute',
|
||||
left: '0',
|
||||
top: '0',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
pointerEvents: 'none',
|
||||
background: scrimBackground(sky, !!opts.backdrop),
|
||||
});
|
||||
parent.appendChild(scrim);
|
||||
}
|
||||
const scrim = makeScrim();
|
||||
field = stars;
|
||||
built = { twinkle, scrim };
|
||||
if (opts.backdrop && !still) built.rig = startRig(opts.backdrop, w, h);
|
||||
|
|
@ -426,6 +438,9 @@ export function createRidgeScene(opts: RidgeOptions): Scene | null {
|
|||
cancelAnimationFrame(raf);
|
||||
raf = 0;
|
||||
if (opts.backdrop) paintPlanes(opts.backdrop);
|
||||
// The planes are in the canvas now: the scrim, which fades out toward them, goes over the canvas.
|
||||
const scrim = makeScrim();
|
||||
built = scrim ? { scrim } : undefined;
|
||||
report(true);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ describe('star placement', () => {
|
|||
it('fades with the sky: every star sits where the sky is dark, alpha within bounds', () => {
|
||||
for (const s of makeStars(NIGHT, 390, 844)) {
|
||||
expect(skyLuma(NIGHT, s.y)).toBeLessThan(NIGHT_LUMA);
|
||||
expect(s.alpha).toBeLessThanOrEqual(STAR_MAX_ALPHA)
|
||||
expect(s.alpha).toBeLessThanOrEqual(STAR_MAX_ALPHA);
|
||||
expect(s.y).toBeLessThanOrEqual(STAR_BAND);
|
||||
expect(s.alpha).toBeGreaterThanOrEqual(0.05);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue