Ridge bake: place ground colour is an authored material; Grand Canyon strata
places.json owns a `materials` table (alpine = the old albedo numbers, canyon = Grand Canyon strata, first draft tuned by eye); a place names its material, absent means alpine, an unknown name is a Refusal. ridge.albedo(h, n_up, material) evaluates one; the GRASS/FOREST/ROCK/SNOW constants are gone. An oracle test pins alpine to the old formula bit for bit. grandcanyon names canyon and is rebaked (grandcanyon-dcfa7cc15fdd, geometry files unchanged); the other four bakes are untouched. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
69f64feba9
commit
194a094c24
391 changed files with 355 additions and 158 deletions
|
|
@ -49,6 +49,10 @@ Files per card `i` and tile `t`: `card-<i>-t<tt>-colour.webp` (lossy RGB albedo,
|
|||
|
||||
Budgets (`check_budget`; a cap is never raised to fit a bake, the lever is `TILES` = 64): every file of one tile at most 235 kB (1.5 MB per 72 degrees), every file of the place at most 7.5 MB, at most 6 cards, and the lit canvases (4 bytes x 202 columns x band rows, per card) of the worst run of N consecutive tiles, cyclic, at most 20 MB, where N = ceil(arc_max / 11.25) + 5 and arc_max = `HFOV_MAX_DEG` / s_min + 2 (r_max / Rmin) 57.3 degrees with Rmin the nearest card's smallest tile distance and s_min = Rmin / (Rmin + r_max). The loader decodes one tile at a time, so the decode transient is not gated.
|
||||
|
||||
## Materials
|
||||
|
||||
`places.json` `materials` is the one owner of ground colour (ruling `ridge-place-colour-authored`: the topology is real, the colour is authored). A material is `{ base: rgb, ramps: [{ from_m, to_m, colour }], steep: { colour } | null, snow: { from_m, to_m, colour } | null }`: `ridge.albedo(h, n_up, material)` lerps `base` through each ramp in order by height, then to the steep colour on steep faces (null: strata hold on cliffs), then to the snow colour on flat ground above its band. A place names its `material` (absent: `alpine`, the numbers the baker had before materials, pinned by an oracle test); an unknown name is refused (`ridge.load_material`). The material is part of the bake id. `canyon` (Grand Canyon strata by height at the Unkar reach) is a first draft, tuned by eye on the contact sheet.
|
||||
|
||||
## Licence
|
||||
|
||||
Elevation: Copernicus DEM GLO-30. The credit line is written into every manifest (`attribution`) and must be shown with any rendering:
|
||||
|
|
|
|||
|
|
@ -233,19 +233,19 @@ def write_bake(out, place, view, meta, packed, opaque, default=None):
|
|||
return dest
|
||||
|
||||
# ------------------------------------------------------------------------------------ the bake
|
||||
def cut_ring(d, a, h, splits_km, near):
|
||||
def cut_ring(d, a, h, splits_km, near, material):
|
||||
"""The ring cut of a prefiltered march (set_view done) and its near march (ridge.near_march): coverage, the periodic seams and the opaque view on the far march (d, a), the join of the near ground and the normals on all RING_W columns (ridge.join_near), then ridge.cards per tile on its TILE_W + 2 APRON columns of the joined march. Returns dict(cards [TILES][cards] (ridge.cards arrays),
|
||||
splits_km, seams (K, ring) in m, cov (bins, ring), opaque [TILES] (rows, TILE_W + 2 APRON) coverage, edges)."""
|
||||
import ridge
|
||||
cov = ridge.coverage(d, a); sm = ridge.seams(cov, [k * 1000.0 for k in splits_km], d); op = ridge.opaque(a); D, A, Hc, nrm = ridge.join_near(d, a, h, near); cols = lambda x, t: ridge.ring_cols(x, t * TILE_W - APRON, TILE_W + 2 * APRON); tiles = []
|
||||
for t in range(TILES): tiles.append(ridge.cards(D, cols(A, t), cols(Hc, t), cols(sm, t), tuple(cols(x, t) for x in nrm))); print(f'tile {t + 1}/{TILES}', file=sys.stderr, flush=True)
|
||||
for t in range(TILES): tiles.append(ridge.cards(D, cols(A, t), cols(Hc, t), cols(sm, t), tuple(cols(x, t) for x in nrm), material=material)); print(f'tile {t + 1}/{TILES}', file=sys.stderr, flush=True)
|
||||
return dict(cards=tiles, splits_km=list(splits_km), seams=sm, cov=cov, opaque=[cols(op, t) for t in range(TILES)], edges=ridge.log_edges(d))
|
||||
|
||||
def bake_place(pid):
|
||||
"""stage 0, prefilter, set_view on the whole ring, cut_ring: dict(place, view, meta, v, and cut_ring's cards, splits_km, seams, cov, opaque, edges). Needs RIDGE_TILES / RIDGE_WORK."""
|
||||
import ridge
|
||||
assert ridge.W == RING_W and ridge.H > 0
|
||||
p = ridge.configure(ridge.load_preset(pid)); ridge.mosaic(p); d, _, Hh, _ = ridge.stage0(False); a, h = ridge.prefilter(d, Hh, p.get('prefilter_m', 0)); v = ridge.set_view(a.max(0)); ring = cut_ring(d, a, h, p['card_split_km'], ridge.near_march(p.get('prefilter_m', 0) or 0))
|
||||
p = ridge.load_preset(pid); material = ridge.load_material(p.get('material', 'alpine')); p = ridge.configure(p); ridge.mosaic(p); d, _, Hh, _ = ridge.stage0(False); a, h = ridge.prefilter(d, Hh, p.get('prefilter_m', 0)); v = ridge.set_view(a.max(0)); ring = cut_ring(d, a, h, p['card_split_km'], ridge.near_march(p.get('prefilter_m', 0) or 0), material)
|
||||
place = dict(id=p['id'], name=p['name'], lat=p['lat'], lon=p['lon'], altitude_km=p['ground_m'] / 1000.0, eye_m=p['eye_m'], tz=p['tz'])
|
||||
view = dict(look_az_deg=p['az_center'], plane_h=ridge.H, px_per_deg_h=ridge.HPX_DEG, px_per_deg_v=v['px_per_deg'], exaggeration=v['exaggeration'], horizon_row=v['horizon_row'], sky_row=v['sky_row'] * ridge.H, near_row=v['near_row'] * ridge.H)
|
||||
meta = dict(curvature=dict(r_earth_m=ridge.R_EARTH, k_ref=ridge.KREF), encoding=dict(log_d_min=math.log(d[0]), log_d_max=math.log(d[-1])))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,143 @@
|
|||
{
|
||||
"_doc": "Place presets for the A+D baker (ridge.py). eye = observer lat/lon; eye_h_m = eye above the local DEM surface (ground_override_m replaces the DEM ground elevation, used for Vienna to keep round 1's 183.3 m); look_at = target lat/lon whose bearing is the rest azimuth, where the view looks at rest (or az_deg); the ring itself is the whole 360 degrees, absolute compass, column 0 = north; tz = the place's IANA time zone (required, never defaulted: the runtime draws named sky moments in the place's local day); rmax_km = ring radius (decides the tile list: every 1x1 deg GLO-30 tile whose rectangle intersects the circle); card_split_km = the ordered list of 1 to MAX_CARDS - 1 authored seam depths in km (the seam search refines each per column; K splits make K+1 cards; required, never defaulted); prefilter_m = Gaussian sigma in metres of the height low-pass before the cards are cut (default 0).",
|
||||
"_materials": "materials = the authored ground colour of a place (the topology is real, the colour is GameCult's own depiction; ruling ridge-place-colour-authored). A material: base = rgb under every ramp; ramps = [{from_m, to_m, colour}] lerped over height in order (each takes the running colour to its own over from_m..to_m, then holds it); steep = {colour} | null: the colour of steep faces (n_up under 0.93, full at 0.68), null keeps the height colour on cliffs; snow = {from_m, to_m, colour} | null: lerped in over its band on flat ground. A place names its `material`; absent means alpine; an unknown name is refused by the baker.",
|
||||
"materials": {
|
||||
"alpine": {
|
||||
"base": [
|
||||
0.36,
|
||||
0.44,
|
||||
0.26
|
||||
],
|
||||
"ramps": [
|
||||
{
|
||||
"from_m": 150,
|
||||
"to_m": 900,
|
||||
"colour": [
|
||||
0.22,
|
||||
0.31,
|
||||
0.2
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1300,
|
||||
"to_m": 2000,
|
||||
"colour": [
|
||||
0.47,
|
||||
0.44,
|
||||
0.41
|
||||
]
|
||||
}
|
||||
],
|
||||
"steep": {
|
||||
"colour": [
|
||||
0.47,
|
||||
0.44,
|
||||
0.41
|
||||
]
|
||||
},
|
||||
"snow": {
|
||||
"from_m": 1900,
|
||||
"to_m": 2300,
|
||||
"colour": [
|
||||
0.93,
|
||||
0.95,
|
||||
0.97
|
||||
]
|
||||
}
|
||||
},
|
||||
"canyon": {
|
||||
"base": [
|
||||
0.62,
|
||||
0.52,
|
||||
0.4
|
||||
],
|
||||
"ramps": [
|
||||
{
|
||||
"from_m": 1000,
|
||||
"to_m": 1080,
|
||||
"colour": [
|
||||
0.55,
|
||||
0.3,
|
||||
0.2
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1150,
|
||||
"to_m": 1300,
|
||||
"colour": [
|
||||
0.72,
|
||||
0.38,
|
||||
0.22
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1300,
|
||||
"to_m": 1350,
|
||||
"colour": [
|
||||
0.45,
|
||||
0.33,
|
||||
0.25
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1400,
|
||||
"to_m": 1450,
|
||||
"colour": [
|
||||
0.5,
|
||||
0.52,
|
||||
0.42
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1550,
|
||||
"to_m": 1600,
|
||||
"colour": [
|
||||
0.62,
|
||||
0.48,
|
||||
0.42
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 1800,
|
||||
"to_m": 1850,
|
||||
"colour": [
|
||||
0.52,
|
||||
0.24,
|
||||
0.18
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 2050,
|
||||
"to_m": 2070,
|
||||
"colour": [
|
||||
0.85,
|
||||
0.76,
|
||||
0.58
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 2150,
|
||||
"to_m": 2170,
|
||||
"colour": [
|
||||
0.72,
|
||||
0.68,
|
||||
0.58
|
||||
]
|
||||
},
|
||||
{
|
||||
"from_m": 2300,
|
||||
"to_m": 2400,
|
||||
"colour": [
|
||||
0.3,
|
||||
0.38,
|
||||
0.24
|
||||
]
|
||||
}
|
||||
],
|
||||
"steep": null,
|
||||
"snow": null
|
||||
}
|
||||
},
|
||||
"presets": [
|
||||
{
|
||||
"id": "vienna",
|
||||
|
|
@ -658,6 +796,7 @@
|
|||
"tz": "America/Phoenix",
|
||||
"name": "Grand Canyon from Unkar and Cardenas",
|
||||
"kind": "inner canyon from the river: walls rise above the horizon, layered strata",
|
||||
"material": "canyon",
|
||||
"lat": 36.0817,
|
||||
"lon": -111.8551,
|
||||
"eye_h_m": 1.6,
|
||||
|
|
|
|||
|
|
@ -254,18 +254,29 @@ def seams(cov, targets, d):
|
|||
return out[:, n:2 * n]
|
||||
|
||||
# ====================================================================== cards: layered depth, one per band between seams
|
||||
GRASS, FOREST, ROCK, SNOW = (0.36, 0.44, 0.26), (0.22, 0.31, 0.20), (0.47, 0.44, 0.41), (0.93, 0.95, 0.97)
|
||||
def albedo(h, n_up):
|
||||
"""The authored material, a few numbers: valley green to forest to rock by height, rock where the face is steep, snow above the tree line. Straight colour, no light in it."""
|
||||
t = lambda a, b: np.clip((h - a) / (b - a), 0, 1)[..., None]; c = np.asarray(GRASS) + (np.asarray(FOREST) - GRASS) * t(150, 900); c = c + (np.asarray(ROCK) - c) * t(1300, 2000)
|
||||
c = c + (np.asarray(ROCK) - c) * np.clip((0.93 - n_up) / 0.25, 0, 1)[..., None]; return c + (np.asarray(SNOW) - c) * (t(1900, 2300) * np.clip((n_up - 0.55) / 0.3, 0, 1)[..., None])
|
||||
def load_material(name, path=Path(__file__).resolve().parent / 'places.json'):
|
||||
"""The named material of places.json `materials` (its one owner), checked for shape; an unknown name is a Refusal, never a fallback. A material: base rgb, ramps [{from_m, to_m, colour}] lerped over height in order, steep {colour} | None (the steep-face override), snow {from_m, to_m, colour} | None (gated by flatness)."""
|
||||
tab = json.load(open(path)).get('materials') or {}
|
||||
if name not in tab: raise Refusal(f"material {name!r} is not in places.json materials ({', '.join(sorted(tab)) or 'none'})")
|
||||
m = tab[name]; rgb = lambda c: isinstance(c, list) and len(c) == 3 and all(isinstance(v, (int, float)) and 0 <= v <= 1 for v in c)
|
||||
ok = isinstance(m, dict) and set(m) == {'base', 'ramps', 'steep', 'snow'} and rgb(m['base']) and isinstance(m['ramps'], list) and all(isinstance(r, dict) and set(r) == {'from_m', 'to_m', 'colour'} and r['from_m'] < r['to_m'] and rgb(r['colour']) for r in m['ramps'])
|
||||
ok = ok and (m['steep'] is None or (isinstance(m['steep'], dict) and set(m['steep']) == {'colour'} and rgb(m['steep']['colour']))) and (m['snow'] is None or (isinstance(m['snow'], dict) and set(m['snow']) == {'from_m', 'to_m', 'colour'} and m['snow']['from_m'] < m['snow']['to_m'] and rgb(m['snow']['colour'])))
|
||||
if not ok: raise Refusal(f"material {name!r} is malformed (base rgb, ramps [{{from_m < to_m, colour}}], steep {{colour}} | null, snow {{from_m < to_m, colour}} | null; rgb in 0..1)")
|
||||
return m
|
||||
def albedo(h, n_up, material):
|
||||
"""Evaluate a material (load_material) at height h and up-component n_up: the base colour, each ramp lerped by height in order, the steep colour where the face is steep, the snow colour above its band where the face is flat. Straight colour, no light in it."""
|
||||
t = lambda a, b: np.clip((h - a) / (b - a), 0, 1)[..., None]; c = np.asarray(material['base'])
|
||||
for r in material['ramps']: c = c + (np.asarray(r['colour']) - c) * t(r['from_m'], r['to_m'])
|
||||
if material['steep']: c = c + (np.asarray(material['steep']['colour']) - c) * np.clip((0.93 - n_up) / 0.25, 0, 1)[..., None]
|
||||
sn = material['snow']
|
||||
return c + (np.asarray(sn['colour']) - c) * (t(sn['from_m'], sn['to_m']) * np.clip((n_up - 0.55) / 0.3, 0, 1)[..., None]) if sn else c
|
||||
|
||||
def cards(d, a, h, seams, nrm=None):
|
||||
def cards(d, a, h, seams, nrm=None, *, material):
|
||||
"""K+1 cards, nearest first, from the angles a and heights h (samples, n) of n columns and the (K, n) seams (m). Card i holds per pixel the FIRST VISIBLE hit at or beyond seam i-1 (less XF): layered depth, so a farther
|
||||
card keeps the terrain a nearer ridge hides. Its alpha is that pixel's coverage (a crest row holds the share of its angular span under the card's running maximum) times 1 - smoothstep over seam i +- XF in
|
||||
log-distance of the hit; card 0 owns the rows below the first sample, the last card has no far edge. Alphas are then made nested so the alpha-over composite of all cards is exactly the opaque coverage (a row two
|
||||
cards both hold partly is not counted twice). Distance and normal are interpolated between sample k-1 and k by angle. Each card is cropped to the rows where its 8-bit alpha is not zero.
|
||||
nrm is normals(d, h) of the same columns (default: computed from h as given, so pass it for columns cut from the ring: the lateral slope reads the neighbouring columns). Rows of any card below the angle of its first sample (hit and idx == 0) are its wall: they keep that sample's distance, their albedo is the ground material at their height with the face up (n_up = 1),
|
||||
material is the place's (load_material), the one colour rule of wall, near and far rows. nrm is normals(d, h) of the same columns (default: computed from h as given, so pass it for columns cut from the ring: the lateral slope reads the neighbouring columns). Rows of any card below the angle of its first sample (hit and idx == 0) are its wall: they keep that sample's distance, their albedo is the ground material at their height with the face up (n_up = 1),
|
||||
and `wall` flags them (card 0's first sample is the near march's NEAR_START_M, so no row of it is wall under a real frame). Card 0 draws the near march (join_near; the samples nearer than NEAR_CLIP_M) under the silhouette of the terrain at the clip as ordinary terrain: its own normal, the albedo of its own height and n_up; `near` (h, n) bool flags the pixels whose hit lies on the near side of the clip sample (the rows that were card 0's wall), whose distance is then never above the clip. Each card: dict(top, alpha (h,n), albedo (h,n,3), n_r, n_t, logd (ln metres) (h,n), wall (h,n) bool, near (h,n) bool)."""
|
||||
d = np.asarray(d, np.float64); a = np.asarray(a, np.float64); h = np.asarray(h, np.float64); seams = np.asarray(seams, np.float64); nk, n = a.shape; nc = len(seams) + 1
|
||||
if d[0] >= NEAR_CLIP_M: raise Refusal(f"card 0 draws the ground under the near clip from the near march, but the first sample is at {d[0]:g} m (the clip is {NEAR_CLIP_M:g} m): pass join_near")
|
||||
|
|
@ -290,5 +301,5 @@ def cards(d, a, h, seams, nrm=None):
|
|||
rows = np.flatnonzero(al.max(1) > 0)
|
||||
if not len(rows): out.append(dict(top=0, alpha=np.zeros((0, n), np.float32), albedo=np.zeros((0, n, 3), np.float32), n_r=np.zeros((0, n), np.float32), n_t=np.zeros((0, n), np.float32), logd=np.zeros((0, n), np.float32), wall=np.zeros((0, n), bool), near=np.zeros((0, n), bool))); continue
|
||||
sl = slice(int(rows[0]), int(rows[-1]) + 1); g = G[i, :, sl]; nz = np.sqrt(g[2] ** 2 + g[3] ** 2 + g[4] ** 2) + 1e-12
|
||||
out.append(dict(top=int(rows[0]), alpha=al[sl].astype(np.float32), albedo=albedo(g[1], np.where(Wl[i, sl], 1.0, g[4] / nz)).astype(np.float32), n_r=(g[2] / nz).astype(np.float32), n_t=(g[3] / nz).astype(np.float32), logd=g[0].astype(np.float32), wall=Wl[i, sl].copy(), near=Nr[i, sl].copy()))
|
||||
out.append(dict(top=int(rows[0]), alpha=al[sl].astype(np.float32), albedo=albedo(g[1], np.where(Wl[i, sl], 1.0, g[4] / nz), material).astype(np.float32), n_r=(g[2] / nz).astype(np.float32), n_t=(g[3] / nz).astype(np.float32), logd=g[0].astype(np.float32), wall=Wl[i, sl].copy(), near=Nr[i, sl].copy()))
|
||||
return out
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ MUTANTS = { # name -> (text in ridge.py or export.py, replacement)
|
|||
'wall: no row is flagged (the flag is dropped)': ("Wl[i, :, x] = hit & (idx == 0)", "Wl[i, :, x] = False"),
|
||||
'near: the cap to the silhouette of the terrain at the clip is dropped': ("an = np.minimum(an, a[0][None, :])", "an = an"),
|
||||
'near: rows under the clip are flagged wall': ("Wl[i, :, x] = hit & (idx == 0); Nr[i, :, x] = hit & (kp < kn)", "Wl[i, :, x] = hit & ((idx == 0) | (kp < kn)); Nr[i, :, x] = hit & (kp < kn)"),
|
||||
'near: albedo takes the face up (the wall rule on near rows)': ("albedo(g[1], np.where(Wl[i, sl], 1.0, g[4] / nz))", "albedo(g[1], np.where(Wl[i, sl] | Nr[i, sl], 1.0, g[4] / nz))"),
|
||||
'near: albedo takes the face up (the wall rule on near rows)': ("albedo(g[1], np.where(Wl[i, sl], 1.0, g[4] / nz), material)", "albedo(g[1], np.where(Wl[i, sl] | Nr[i, sl], 1.0, g[4] / nz), material)"),
|
||||
'near: albedo reads the height of the far march first sample': ("albedo(g[1], np.where(Wl[i, sl]", "albedo(np.where(Nr[i, sl], h[int(np.searchsorted(d, NEAR_CLIP_M))][None, :], g[1]), np.where(Wl[i, sl]"),
|
||||
'near: the march starts at 20 m': ("NEAR_START_M = 1.0 ", "NEAR_START_M = 20.0 "),
|
||||
'near: the heights are stored float32': (", np.float64) for dk in d])", ", np.float32) for dk in d])"),
|
||||
|
|
@ -87,6 +87,11 @@ MUTANTS = { # name -> (text in ridge.py or export.py, replacement)
|
|||
'pack: the distance reads the apron columns too': ("inner = slice(APRON, APRON + TILE_W)", "inner = slice(0, TILE_W + 2 * APRON)"),
|
||||
'sheet: the tile boundaries are not drawn': ("def bounds(img): img[:, mark] = 0.45 * img[:, mark] + 0.55 * red; return img", "def bounds(img): return img"),
|
||||
'export: an empty card is not refused': ("if all(tile[i]['alpha'].shape[0] == 0 for tile in bake['cards']): raise", "if False: raise"),
|
||||
'material: a null steep override still paints steep faces rock grey (strata do not hold on cliffs)': ("if material['steep']: c = c + (np.asarray(material['steep']['colour'])", "if True: c = c + (np.asarray((material['steep'] or dict(colour=[0.47, 0.44, 0.41]))['colour'])"),
|
||||
'material: the ramps apply in reverse order': ("for r in material['ramps']:", "for r in reversed(material['ramps']):"),
|
||||
'material: a null snow still snows': ("sn = material['snow']", "sn = material['snow'] or dict(from_m=1900, to_m=2300, colour=[0.93, 0.95, 0.97])"),
|
||||
'material: an unknown name falls back to alpine': ("if name not in tab: raise Refusal(", "if name not in tab: name = 'alpine'; ("),
|
||||
'material: the cards take the alpine colours whatever the place names': ("ridge.cards(D, cols(A, t), cols(Hc, t), cols(sm, t), tuple(cols(x, t) for x in nrm), material=material)", "ridge.cards(D, cols(A, t), cols(Hc, t), cols(sm, t), tuple(cols(x, t) for x in nrm), material=ridge.load_material('alpine'))"),
|
||||
'rays cache key ignores the refraction constant': ("R_EARTH, KREF, W, bool(detail)", "R_EARTH, W, bool(detail)"),
|
||||
'rays cache key ignores the eye elevation': ("round(float(P['eye_m']), 3), ", ""),
|
||||
'mosaic cache key ignores the tile list': ("sorted(tiles_for(p)), 3600", "3600"),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import os, sys, math, json, shutil, tempfile, traceback
|
|||
SRC = os.environ.get('RIDGE_SRC') or os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'); sys.path.insert(0, SRC) # RIDGE_WORK and RIDGE_TILES must be set (tests/run.sh sets them)
|
||||
import numpy as np, ridge, export
|
||||
from ridge import W, H
|
||||
ALPINE = ridge.load_material('alpine') # the places.json material of every place that names none
|
||||
NW = 1280 # the synthetic bakes' window: columns 0..NW of the ring (azimuth 0..72); the pieces that need the whole ring (seams across the wrap, the tile cut) run on the ring
|
||||
TW = export.TILE_W + 2 * export.APRON
|
||||
_w = lambda x: ridge.ring_cols(x, 0, NW)
|
||||
|
|
@ -60,7 +61,7 @@ def _bake(hfun, splits_km, sigma=0.0, fixed_m=None):
|
|||
A, Hh = rays(hfun); ridge.P.update(eye_m=EYE); a, h = ridge.prefilter(D, Hh, sigma); v = ridge.set_view(a.max(0)); cov_ring = ridge.coverage(D, a); cov = _w(cov_ring)
|
||||
sm = _w(ridge.seams(cov_ring, [k * 1000.0 for k in splits_km], D)) if fixed_m is None else np.array([np.full(NW, float(v)) for v in fixed_m])
|
||||
Dj, aj, hj, nj = ridge.join_near(D, a, h, near_rays(hfun, sigma)); aw, hw, nrm = _w(aj), _w(hj), tuple(_w(x) for x in nj)
|
||||
return dict(cards=ridge.cards(Dj, aw, hw, sm, nrm), splits_km=list(splits_km), seams=sm, cov=cov, opaque=ridge.opaque(_w(a)), edges=ridge.log_edges(D), D=Dj, a=aw, h=hw, nrm=nrm, v=v)
|
||||
return dict(cards=ridge.cards(Dj, aw, hw, sm, nrm, material=ALPINE), splits_km=list(splits_km), seams=sm, cov=cov, opaque=ridge.opaque(_w(a)), edges=ridge.log_edges(D), D=Dj, a=aw, h=hw, nrm=nrm, v=v)
|
||||
def _canvas(card, key='alpha'):
|
||||
out = np.zeros((H, NW) + card[key].shape[2:], np.float32); out[card['top']:card['top'] + card[key].shape[0]] = card[key]; return out
|
||||
def _row(deg): return int(np.argmin(np.abs(ridge.rowang - deg)))
|
||||
|
|
@ -113,7 +114,7 @@ def test_far_card_keeps_terrain_hidden_behind_a_nearer_ridge():
|
|||
def test_crossfade_is_complementary():
|
||||
"""A ridge across the seam (seam fixed at 6 km, the ridge's front face at 5.9 km inside the cross-fade): the nearer card is partly transparent over the window, the farther card is opaque on the ridge, and the composite stays at coverage 1 below the crest."""
|
||||
hf = terrain(block(0, 359.99, 5900, 6100, 900)); A, Hh = rays(hf); ridge.P.update(eye_m=EYE); ridge.set_view(A.max(0)); aw = _w(A); Dj, aj, hj, nj = _join(hf, A, Hh)
|
||||
cs = ridge.cards(Dj, aj, hj, np.full((1, NW), 6000.0), nj); c0, c1 = _canvas(cs[0]), _canvas(cs[1]); crest = int(np.argmax(ridge.opaque(aw)[:, 500] > 0.5)); r = crest + 6
|
||||
cs = ridge.cards(Dj, aj, hj, np.full((1, NW), 6000.0), nj, material=ALPINE); c0, c1 = _canvas(cs[0]), _canvas(cs[1]); crest = int(np.argmax(ridge.opaque(aw)[:, 500] > 0.5)); r = crest + 6
|
||||
assert 0.2 < c0[r, 500] < 0.8, ('the near card does not fade over the window', c0[r, 500]); assert c1[r, 500] > 0.99, 'the far card is not opaque on the ridge'
|
||||
comp = 1 - (1 - c0) * (1 - c1); assert (comp[crest + 3:, :] > 0.999).all(), 'the composite dips below coverage 1 under the crest'
|
||||
def test_normals_of_a_tilted_plane():
|
||||
|
|
@ -143,7 +144,7 @@ def test_prefilter_flattens_roofs_and_keeps_hills():
|
|||
assert np.allclose(ridge.prefilter(D, Hh, 0.0)[1], Hh), 'sigma 0 changed the heights'
|
||||
def test_crest_rows_have_fractional_coverage():
|
||||
"""The top row of a card's run has alpha equal to the share of its angular span under the running maximum, and the rows below it are 1 (a lower ridge in columns 0..640 so its crest is not at the frame's top edge)."""
|
||||
hf = terrain(block(0, 36, 5000, 5600, 500), block(36, 359.99, 5000, 5600, 560)); A, Hh = rays(hf); ridge.P.update(eye_m=EYE); ridge.set_view(A.max(0)); aw = _w(A); Dj, aj, hj, nj = _join(hf, A, Hh); c = ridge.cards(Dj, aj, hj, np.zeros((0, NW)), nj)[0]
|
||||
hf = terrain(block(0, 36, 5000, 5600, 500), block(36, 359.99, 5000, 5600, 560)); A, Hh = rays(hf); ridge.P.update(eye_m=EYE); ridge.set_view(A.max(0)); aw = _w(A); Dj, aj, hj, nj = _join(hf, A, Hh); c = ridge.cards(Dj, aj, hj, np.zeros((0, NW)), nj, material=ALPINE)[0]
|
||||
cv = _canvas(c)[:, 300]; r = int(np.argmax(cv > 0)); top = float(aw.max(0)[300]); p = 1.0 / ridge.PXDEG_V; want = (top - (ridge.rowang[r] - 0.5 * p)) / p
|
||||
assert 0.0 < want < 1.0 and abs(cv[r] - want) < 0.01, (cv[r], want, r); assert (cv[r + 1:] > 0.999).all()
|
||||
def test_cards_composite_to_the_opaque_view():
|
||||
|
|
@ -160,7 +161,7 @@ _RING = {}
|
|||
def _ring(key, hfun, splits_km):
|
||||
"""export.cut_ring on synthetic rays (prefilter, whole-ring set_view, then the ring cut), cached by key: dict(bake = what export.bake_place returns, minus the place)."""
|
||||
if key not in _RING:
|
||||
A, Hh = rays(hfun); ridge.P.update(eye_m=EYE); a, h = ridge.prefilter(D, Hh, 0.0); v = ridge.set_view(a.max(0)); r = export.cut_ring(D, a, h, splits_km, near_rays(hfun))
|
||||
A, Hh = rays(hfun); ridge.P.update(eye_m=EYE); a, h = ridge.prefilter(D, Hh, 0.0); v = ridge.set_view(a.max(0)); r = export.cut_ring(D, a, h, splits_km, near_rays(hfun), ALPINE)
|
||||
_RING[key] = dict(r, op_ring=ridge.opaque(a), place=dict(id='synthetic', name='Synthetic', lat=48.0, lon=16.0, altitude_km=0.05, eye_m=EYE, tz='Europe/Vienna'), v=v,
|
||||
view=dict(look_az_deg=36.0, plane_h=H, px_per_deg_h=ridge.HPX_DEG, px_per_deg_v=v['px_per_deg'], exaggeration=v['exaggeration'], horizon_row=v['horizon_row'], sky_row=v['sky_row'] * H, near_row=v['near_row'] * H),
|
||||
meta=dict(curvature=dict(r_earth_m=ridge.R_EARTH, k_ref=ridge.KREF), encoding=dict(log_d_min=math.log(D[0]), log_d_max=math.log(D[-1]))))
|
||||
|
|
@ -197,7 +198,7 @@ def test_every_tile_is_cut_at_its_own_seam():
|
|||
def test_tile_is_a_crop_of_the_columns():
|
||||
"""ridge.cards on a tile's columns (the 200 it owns and the apron) equals the same columns of ridge.cards on a wider run of columns, pixel for pixel, for fixed seams: the tile cut changes no pixel and adds no seam."""
|
||||
b = _bake(terrain(_receding, block(0, 359.99, 3000, 3600, 350)), [6]); x0 = 500; n = export.TILE_W + 2 * export.APRON; sl = slice(x0, x0 + n)
|
||||
tile = ridge.cards(b['D'], b['a'][:, sl], b['h'][:, sl], b['seams'][:, sl], tuple(x[:, sl] for x in b['nrm']))
|
||||
tile = ridge.cards(b['D'], b['a'][:, sl], b['h'][:, sl], b['seams'][:, sl], tuple(x[:, sl] for x in b['nrm']), material=ALPINE)
|
||||
for c, w in zip(tile, b['cards']):
|
||||
assert np.array_equal(_canvas(w)[:, sl], _tile_canvas(c)), 'a tile is not a crop of the columns'; seen = _tile_canvas(c) > 0
|
||||
for key in ('albedo', 'n_r', 'n_t', 'logd', 'wall', 'near'): assert np.array_equal(_canvas(w, key)[:, sl][seen], _tile_canvas(c, key)[seen]), ('a tile is not a crop of the columns', key)
|
||||
|
|
@ -437,7 +438,7 @@ def _vienna_ring(splits, tiles):
|
|||
try:
|
||||
p = ridge.configure(dict(ridge.load_preset('vienna'), card_split_km=splits)); d, _, Hh, _ = ridge.stage0(False); a, h = ridge.prefilter(d, Hh, p['prefilter_m']); ridge.set_view(a.max(0)); sm = ridge.seams(ridge.coverage(d, a), [k * 1000.0 for k in splits], d); op = ridge.opaque(a); D_, A_, H_, nrm = ridge.join_near(d, a, h, ridge.near_march(p['prefilter_m']))
|
||||
cols = lambda x, t: ridge.ring_cols(x, t * export.TILE_W - export.APRON, export.TILE_W + 2 * export.APRON)
|
||||
return d, sm, {t: ridge.cards(D_, cols(A_, t), cols(H_, t), cols(sm, t), tuple(cols(x, t) for x in nrm)) for t in tiles}, {t: cols(op, t) for t in tiles}
|
||||
return d, sm, {t: ridge.cards(D_, cols(A_, t), cols(H_, t), cols(sm, t), tuple(cols(x, t) for x in nrm), material=ALPINE) for t in tiles}, {t: cols(op, t) for t in tiles}
|
||||
finally: ridge.P = saved
|
||||
def test_vienna_k1_k2_k3():
|
||||
"""Vienna with card_split_km [6], [6, 40] and [6, 20, 40]: 2, 3 and 4 cards, seams ordered in every column of the ring, each composite of a tile (the rest azimuth's, the north's and the last one) equals the opaque view within 0.02; the cross-fade column count is printed."""
|
||||
|
|
@ -503,7 +504,7 @@ def test_wall_rows_flagged():
|
|||
assert (code == c['wall']).all() and (r[~code] ** 2 + t[~code] ** 2 <= 1.02).all(), 'the wall code is not on exactly the wall pixels, or a real normal reaches it'
|
||||
for x in np.flatnonzero(c['wall'].any(0)):
|
||||
rows = np.flatnonzero(c['wall'][:, x]); ld = c['logd'][rows, x]; assert np.ptp(ld) < 1e-5 and abs(math.exp(ld[0]) - b['D'][k0[x]]) < 1e-3 * b['D'][k0[x]] + 60, ('a wall keeps its sample distance', x)
|
||||
want_alb = ridge.albedo(np.array([b['h'][k0[x], x]]), np.array([1.0]))[0]; assert np.abs(c['albedo'][rows, x] - want_alb).max() < 1e-5, ('wall albedo is not the ground material with the face up', x)
|
||||
want_alb = ridge.albedo(np.array([b['h'][k0[x], x]]), np.array([1.0]), ALPINE)[0]; assert np.abs(c['albedo'][rows, x] - want_alb).max() < 1e-5, ('wall albedo is not the ground material with the face up', x)
|
||||
assert seen > 1000, 'the fixture has no wall'
|
||||
for i in range(1, len(b['cards'])):
|
||||
c = b['cards'][i]; steep += int((np.sqrt(np.clip(1 - c['n_r'] ** 2 - c['n_t'] ** 2, 0, 1))[c['wall']] < 0.93).sum())
|
||||
|
|
@ -587,8 +588,8 @@ def test_near_ground_draws_inside_the_clip_silhouette():
|
|||
try:
|
||||
far = block(36, 359.99, 20000, 21500, 1500); hf = lambda dk, az: np.maximum(np.where((dk >= 150) & (dk < 300), 0.4 * (dk - 150), 0.0), np.asarray(far(dk, az), float))
|
||||
A, Hh = rays(hf, eye=1.6); a, h = ridge.prefilter(D, Hh, 0.0); ridge.set_view(a.max(0)); near = near_rays(hf); Dj, Aj, Hj, Nj = ridge.join_near(D, a, h, near); aw, hw, nj = _w(Aj), _w(Hj), tuple(_w(x) for x in Nj)
|
||||
c = ridge.cards(Dj, aw, hw, np.zeros((0, NW)), nj)[0]; comp = _canvas(c); opq = ridge.opaque(_w(a)); err = np.abs(comp - opq).max(); assert err < export.COVER_TOL, ('card 0 draws outside the silhouette of the terrain at the clip', err)
|
||||
free = ridge.cards(Dj, _w(np.concatenate([near[1], a])), hw, np.zeros((0, NW)), nj)[0]; assert np.abs(_canvas(free) - opq).max() > 5 * export.COVER_TOL, 'the fixture cannot tell a hill above the clip line (the cap is not tested)'
|
||||
c = ridge.cards(Dj, aw, hw, np.zeros((0, NW)), nj, material=ALPINE)[0]; comp = _canvas(c); opq = ridge.opaque(_w(a)); err = np.abs(comp - opq).max(); assert err < export.COVER_TOL, ('card 0 draws outside the silhouette of the terrain at the clip', err)
|
||||
free = ridge.cards(Dj, _w(np.concatenate([near[1], a])), hw, np.zeros((0, NW)), nj, material=ALPINE)[0]; assert np.abs(_canvas(free) - opq).max() > 5 * export.COVER_TOL, 'the fixture cannot tell a hill above the clip line (the cap is not tested)'
|
||||
x = 300; al, nrr, wl, ld = c['alpha'][:, x], c['near'][:, x], c['wall'], c['logd'][:, x]; sel = (al > 0.99) & nrr; assert sel.sum() > 20 and not wl.any(), ('card 0 has wall rows', int(wl.sum()), int(sel.sum())); assert nrr[al > 0.5].mean() > 0.9, 'the rows under the clip are not flagged near'
|
||||
L = np.log(Dj); q = ld[sel].astype(np.float64); want = np.stack([_blend(L, q, nj[0], x), _blend(L, q, nj[1], x), _blend(L, q, nj[2], x)]); m = np.sqrt((want ** 2).sum(0))
|
||||
assert np.abs(c['n_r'][sel, x] - want[0] / m).max() < 2e-3 and np.abs(c['n_t'][sel, x] - want[1] / m).max() < 2e-3, 'a near row has not its own normal'; assert (np.abs(c['n_r'][sel, x]) > 0.5).sum() > 5, 'the fixture has no ramp rows'
|
||||
|
|
@ -598,12 +599,12 @@ def test_near_ground_has_the_material_and_relief_of_its_own_heights():
|
|||
dn = ridge.near_schedule(); K, Kn = len(D), len(dn); a = np.tile(np.linspace(5.0, 12.0, K)[:, None], (1, W)); h = np.full((K, W), 1000.0); blk = (np.arange(W) // 20) % 3; base = np.array([100.0, 1000.0, 2100.0])[blk]
|
||||
hn = np.broadcast_to(base[None, :], (Kn, W)).copy(); hn[:, blk == 1] += dn[:, None]; an = np.tile(np.linspace(-8.0, 5.0, Kn)[:, None], (1, W)); ridge.P.update(eye_m=EYE); ridge.set_view(a.max(0))
|
||||
Dj, Aj, Hj, Nj = ridge.join_near(D, a, h, (dn, an, hn)); assert all(np.array_equal(u[Kn:], w) for u, w in zip(Nj, ridge.normals(D, h))), 'the far normals are not those of the far march alone'
|
||||
c = ridge.cards(Dj, _w(Aj), _w(Hj), np.zeros((0, NW)), tuple(_w(x) for x in Nj))[0]; up = np.sqrt(np.clip(1 - c['n_r'] ** 2 - c['n_t'] ** 2, 0, 1)); got = {}
|
||||
c = ridge.cards(Dj, _w(Aj), _w(Hj), np.zeros((0, NW)), tuple(_w(x) for x in Nj), material=ALPINE)[0]; up = np.sqrt(np.clip(1 - c['n_r'] ** 2 - c['n_t'] ** 2, 0, 1)); got = {}
|
||||
for x in range(NW):
|
||||
if not 3 <= x % 20 <= 16: continue
|
||||
sel = (c['alpha'][:, x] > 0.99) & c['near'][:, x] & (c['logd'][:, x] < math.log(ridge.NEAR_CLIP_M) - 1e-6); assert sel.sum() > 50, ('no near rows', x) # the crest row that meets the clip sample itself is not under the clip
|
||||
if blk[x] == 1: assert up[sel, x].max() < 0.93 and np.abs(c['albedo'][sel, x] - np.asarray(ridge.ROCK)).max() < 1e-4, ('the hill face is not steep rock', x, float(up[sel, x].max()))
|
||||
else: assert np.abs(c['albedo'][sel, x] - ridge.albedo(np.full(int(sel.sum()), base[x]), up[sel, x])).max() < 1e-5, ('a near row has not the material of its own height', x)
|
||||
if blk[x] == 1: assert up[sel, x].max() < 0.93 and np.abs(c['albedo'][sel, x] - np.asarray(ALPINE['steep']['colour'])).max() < 1e-4, ('the hill face is not steep rock', x, float(up[sel, x].max()))
|
||||
else: assert np.abs(c['albedo'][sel, x] - ridge.albedo(np.full(int(sel.sum()), base[x]), up[sel, x], ALPINE)).max() < 1e-5, ('a near row has not the material of its own height', x)
|
||||
got[blk[x]] = c['albedo'][sel, x].mean(0)
|
||||
assert np.abs(got[0] - got[1]).max() > 0.05 and np.abs(got[1] - got[2]).max() > 0.05 and np.abs(got[0] - got[2]).max() > 0.05, ('the blocks do not differ where the ground does', got)
|
||||
def test_near_pixels_bind_at_the_clip_wherever_they_are():
|
||||
|
|
@ -629,7 +630,7 @@ def test_near_pixels_bind_at_the_clip_wherever_they_are():
|
|||
def test_cards_refuses_a_march_without_the_near_ground():
|
||||
"""ridge.cards on a march whose first sample is the near clip (not joined to the near march) raises, naming join_near: card 0 can never extrude the clip sample again."""
|
||||
A, Hh = rays(THREE); ridge.P.update(eye_m=EYE); ridge.set_view(A.max(0))
|
||||
try: ridge.cards(D, _w(A), _w(Hh), np.zeros((0, NW)))
|
||||
try: ridge.cards(D, _w(A), _w(Hh), np.zeros((0, NW)), material=ALPINE)
|
||||
except export.Refusal as e: assert 'join_near' in str(e), str(e)
|
||||
else: assert False, 'cards drew a march that starts at the near clip'
|
||||
def test_near_march_starts_at_your_feet():
|
||||
|
|
@ -639,7 +640,7 @@ def test_near_march_starts_at_your_feet():
|
|||
saved = ridge.P.get('eye_m'); ridge.P.update(eye_m=1.6)
|
||||
try:
|
||||
hf = lambda dk, az: np.zeros_like(az); A, Hh = rays(hf, eye=1.6); a, h = ridge.prefilter(D, Hh, 0.0); sk = np.full(W, -5.0); sk[::2] = 2.0; ridge.set_view(sk); assert ridge.BOTTOM_DEG < -8.0, ridge.BOTTOM_DEG
|
||||
Dj, Aj, Hj, Nj = ridge.join_near(D, a, h, near_rays(hf)); c = ridge.cards(Dj, _w(Aj), _w(Hj), np.zeros((0, NW)), tuple(_w(x) for x in Nj))[0]
|
||||
Dj, Aj, Hj, Nj = ridge.join_near(D, a, h, near_rays(hf)); c = ridge.cards(Dj, _w(Aj), _w(Hj), np.zeros((0, NW)), tuple(_w(x) for x in Nj), material=ALPINE)[0]
|
||||
assert not c['wall'].any() and c['near'].any(), ('card 0 has wall under the frame bottom', int(c['wall'].sum())); assert _canvas(c)[H - 1, 300] > 0.99 and c['near'][H - 1 - c['top'], 300], 'the bottom row is not near ground'
|
||||
finally: ridge.P.update(eye_m=saved)
|
||||
def test_near_march_is_float64_and_prefiltered():
|
||||
|
|
@ -673,11 +674,48 @@ def test_cards_interpolate_between_samples_and_renormalise():
|
|||
that is not renormalised, or a hit that is not interpolated, differs)."""
|
||||
hf = terrain(lambda dk, az: np.where(dk >= 4000, GROUND + 0.5 * (dk - 4000), 0.0) + 0 * az); A, Hh = rays(hf); ridge.P.update(eye_m=EYE); ridge.set_view(A.max(0)); Dj, aw, hw, _ = _join(hf, A, Hh); k = np.arange(len(Dj))[:, None]
|
||||
nr = np.broadcast_to(np.where(k % 2 == 0, -0.8, 0.8), aw.shape).astype(float); nt = np.broadcast_to(np.where(k % 3 == 0, 0.3, -0.3), aw.shape).astype(float); nu = np.sqrt(1 - nr ** 2 - nt ** 2) * 0 + 0.5
|
||||
c = ridge.cards(Dj, aw, hw, np.zeros((0, NW)), nrm=(nr, nt, nu))[0]; x = 300; sel = np.flatnonzero(c['alpha'][:, x] > 0.999); ld = c['logd'][sel, x].astype(np.float64); L = np.log(Dj); kk = np.searchsorted(L, ld, 'left'); kp = kk - 1; ok = kp >= 0
|
||||
c = ridge.cards(Dj, aw, hw, np.zeros((0, NW)), nrm=(nr, nt, nu), material=ALPINE)[0]; x = 300; sel = np.flatnonzero(c['alpha'][:, x] > 0.999); ld = c['logd'][sel, x].astype(np.float64); L = np.log(Dj); kk = np.searchsorted(L, ld, 'left'); kp = kk - 1; ok = kp >= 0
|
||||
t = (ld - L[np.maximum(kp, 0)]) / (L[kk] - L[np.maximum(kp, 0)]); inner = ok & (t > 0.02) & (t < 0.98); assert inner.sum() > 0.3 * len(sel), ('hits sit on samples, not between them', int(inner.sum()), len(sel))
|
||||
mix = lambda arr: arr[np.maximum(kp, 0), x] + t * (arr[kk, x] - arr[np.maximum(kp, 0), x]); m = np.sqrt(mix(nr) ** 2 + mix(nt) ** 2 + mix(nu) ** 2); er = np.abs(c['n_r'][sel, x] - mix(nr) / m)[inner]; et = np.abs(c['n_t'][sel, x] - mix(nt) / m)[inner]
|
||||
assert er.max() < 1e-3 and et.max() < 1e-3, ('the normal is not the normalised blend of the two samples', er.max(), et.max())
|
||||
|
||||
def _old_albedo(h, n_up):
|
||||
"""The oracle: ridge.albedo as it stood before materials, constants and all (copied here, the only place they live now)."""
|
||||
GRASS, FOREST, ROCK, SNOW = (0.36, 0.44, 0.26), (0.22, 0.31, 0.20), (0.47, 0.44, 0.41), (0.93, 0.95, 0.97)
|
||||
t = lambda a, b: np.clip((h - a) / (b - a), 0, 1)[..., None]; c = np.asarray(GRASS) + (np.asarray(FOREST) - GRASS) * t(150, 900); c = c + (np.asarray(ROCK) - c) * t(1300, 2000)
|
||||
c = c + (np.asarray(ROCK) - c) * np.clip((0.93 - n_up) / 0.25, 0, 1)[..., None]; return c + (np.asarray(SNOW) - c) * (t(1900, 2300) * np.clip((n_up - 0.55) / 0.3, 0, 1)[..., None])
|
||||
def test_alpine_material_is_exactly_the_old_albedo():
|
||||
"""places.json's alpine material evaluates to the old hard-coded formula bit for bit on a grid of heights 0-3000 m and n_up 0-1 (the four unrebaked places keep their bake ids because of it), and the canyon material differs from it where it should: the river floor is not grass."""
|
||||
hh, nn = np.meshgrid(np.linspace(0.0, 3000.0, 301), np.linspace(0.0, 1.0, 101), indexing='ij')
|
||||
assert np.array_equal(ridge.albedo(hh, nn, ALPINE), _old_albedo(hh, nn)), 'alpine is not the old formula'
|
||||
assert np.abs(ridge.albedo(np.array([800.0]), np.array([1.0]), ridge.load_material('canyon')) - _old_albedo(np.array([800.0]), np.array([1.0]))).max() > 0.1
|
||||
def test_canyon_material_has_strata_and_holds_on_cliffs():
|
||||
"""The canyon (steep null, snow null): a cliff face has the colour of its height, not a rock grey (a flat and a steep face at one height agree), and the bands are distinct colours over height."""
|
||||
cy = ridge.load_material('canyon'); hs = np.linspace(800.0, 2500.0, 200); flat = ridge.albedo(hs, np.ones_like(hs), cy); steep = ridge.albedo(hs, np.full_like(hs, 0.3), cy)
|
||||
assert np.array_equal(flat, steep), 'a steep face changes the canyon colour'; assert np.abs(np.diff(flat, axis=0)).sum() > 1.0 and len(np.unique(np.rint(flat * 255), axis=0)) > 20, 'the canyon has no strata'
|
||||
def test_an_unknown_material_name_is_refused():
|
||||
"""A place naming a material that places.json does not hold is a Refusal from the baker's own loader, not the alpine fallback; a malformed material is refused too."""
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
p = os.path.join(d, 'm.json'); json.dump(dict(materials=dict(alpine=ALPINE, bad=dict(ALPINE, base=[2, 0, 0]))), open(p, 'w'))
|
||||
assert ridge.load_material('alpine', p) == ALPINE
|
||||
for name in ('canyon', '', 'Alpine'):
|
||||
try: ridge.load_material(name, p)
|
||||
except export.Refusal as ex: assert repr(name) in str(ex), ex
|
||||
else: assert False, ('an unknown material was accepted', name)
|
||||
try: ridge.load_material('bad', p)
|
||||
except export.Refusal: pass
|
||||
else: assert False, 'a malformed material was accepted'
|
||||
json.dump(dict(presets=[]), open(p, 'w'))
|
||||
try: ridge.load_material('alpine', p)
|
||||
except export.Refusal: pass
|
||||
else: assert False, 'a file without materials gave a material'
|
||||
|
||||
def test_the_ring_cut_paints_with_the_material_it_is_given():
|
||||
"""export.cut_ring hands its material to every card: the same terrain cut with the canyon material has a different albedo in tile 0 than with the alpine one, and the same alpha."""
|
||||
b = _ring('wide3', WIDE3, [20, 55]); A, Hh = rays(WIDE3); ridge.P.update(eye_m=EYE); a, h = ridge.prefilter(D, Hh, 0.0); ridge.set_view(a.max(0))
|
||||
c = export.cut_ring(D, a, h, [20, 55], near_rays(WIDE3), ridge.load_material('canyon'))['cards'][0]
|
||||
assert any(not np.array_equal(x['albedo'], y['albedo']) and np.array_equal(x['alpha'], y['alpha']) for x, y in zip(c, b['cards'][0])), 'the ring cut ignores its material'
|
||||
|
||||
TESTS = [v for k, v in sorted(globals().items()) if k.startswith("test_")]
|
||||
if __name__ == '__main__':
|
||||
fails = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue