Add MechPaint surface shader, 4x4 POM decal atlas & shader, vertex weathering baker, and live GL3 probe

This commit is contained in:
Meta Vens 2026-12-04 23:30:58 +01:00
commit 81135e9a83
12 changed files with 2419 additions and 0 deletions

View file

@ -0,0 +1,939 @@
"""Procedural 4x4 hard-surface & combat POM decal trim-sheet atlas generator.
Outputs three 1024x1024 RGBA/RGB PNG textures under assets/decals/:
- decal_atlas_albedo.png (RGBA: sRGB albedo + alpha mask, dilated into alpha=0)
- decal_atlas_normal.png (RGB: tangent-space normal map, OpenGL/Godot +X right, +Y down)
- decal_atlas_ormh.png (RGBA: R=AO, G=Roughness, B=Metallic, A=Height [1=surface, 0=deep recess])
4x4 tile layout (256x256 each, row 0 = top):
Row 0: (0) louvered armor vent, (1) recessed bolted maintenance hatch,
(2) 4-bolt recessed fastener strip, (3) slotted intake grille
Row 1: (4) rivet panel seam, (5) welded armor repair patch,
(6) recessed lift-lug pocket, (7) weathered hazard caution chevron strip
Row 2: (8) tactical stencil "03", (9) tactical stencil "07",
(10) radiation/heat warning stencil, (11) faction chevron emblem
Row 3: (12) deep AP autocannon penetration hole, (13) diagonal shrapnel/flak armor gouge,
(14) molten plasma burn crater, (15) radial blast scorch mark
"""
from __future__ import annotations
from pathlib import Path
import numpy as np
from PIL import Image
REPO_ROOT = Path(__file__).resolve().parents[2]
OUT_DIR = REPO_ROOT / "assets" / "decals"
TILE_SIZE = 256
GRID = 4
ATLAS_SIZE = TILE_SIZE * GRID # 1024
# ---------------------------------------------------------------------------
# Deterministic vectorized noise & SDF primitives (on normalized [-1, 1]^2 tile coords)
# ---------------------------------------------------------------------------
def _hash2(ix: np.ndarray, iy: np.ndarray, seed: int) -> np.ndarray:
n = (ix.astype(np.int64) * 374761393
+ iy.astype(np.int64) * 668265263
+ np.int64(seed) * 1442695041) & 0xFFFFFFFF
n = ((n ^ (n >> 13)) * 1274126177) & 0xFFFFFFFF
n = n ^ (n >> 16)
return (n & 0xFFFFFF).astype(np.float32) / float(0x1000000)
def value_noise(x: np.ndarray, y: np.ndarray, freq: float, seed: int = 1) -> np.ndarray:
px = x * freq
py = y * freq
ix = np.floor(px).astype(np.int64)
iy = np.floor(py).astype(np.int64)
fx = px - ix
fy = py - iy
ux = fx * fx * (3.0 - 2.0 * fx)
uy = fy * fy * (3.0 - 2.0 * fy)
a = _hash2(ix, iy, seed)
b = _hash2(ix + 1, iy, seed)
c = _hash2(ix, iy + 1, seed)
d = _hash2(ix + 1, iy + 1, seed)
return (a * (1.0 - ux) + b * ux) * (1.0 - uy) + (c * (1.0 - ux) + d * ux) * uy
def fbm(x: np.ndarray, y: np.ndarray, base_freq: float, octaves: int = 4, seed: int = 1) -> np.ndarray:
acc = np.zeros_like(x, dtype=np.float32)
amp = 0.5
norm = 0.0
f = base_freq
for o in range(octaves):
acc += amp * value_noise(x, y, f, seed + o * 37)
norm += amp
amp *= 0.5
f *= 2.03
return acc / norm
def smoothstep(e0: float, e1: float, x: np.ndarray) -> np.ndarray:
t = np.clip((x - e0) / (e1 - e0), 0.0, 1.0)
return t * t * (3.0 - 2.0 * t)
def sd_box(x: np.ndarray, y: np.ndarray, cx: float, cy: float, hx: float, hy: float, r: float = 0.0) -> np.ndarray:
qx = np.abs(x - cx) - (hx - r)
qy = np.abs(y - cy) - (hy - r)
out = np.sqrt(np.maximum(qx, 0.0) ** 2 + np.maximum(qy, 0.0) ** 2)
ins = np.minimum(np.maximum(qx, qy), 0.0)
return out + ins - r
def sd_circle(x: np.ndarray, y: np.ndarray, cx: float, cy: float, r: float) -> np.ndarray:
return np.sqrt((x - cx) ** 2 + (y - cy) ** 2) - r
def sd_segment(x: np.ndarray, y: np.ndarray, ax: float, ay: float, bx: float, by: float) -> np.ndarray:
pax = x - ax
pay = y - ay
bax = bx - ax
bay = by - ay
denom = bax * bax + bay * bay + 1e-12
h = np.clip((pax * bax + pay * bay) / denom, 0.0, 1.0)
return np.sqrt((pax - bax * h) ** 2 + (pay - bay * h) ** 2)
def sd_hexagon(x: np.ndarray, y: np.ndarray, cx: float, cy: float, r: float) -> np.ndarray:
px = np.abs(x - cx)
py = np.abs(y - cy)
# Regular hexagon with flat top/bottom
d = np.maximum(px * 0.8660254 + py * 0.5, py) - r
return d
def sd_triangle_eq(x: np.ndarray, y: np.ndarray, cx: float, cy: float, r: float) -> np.ndarray:
# Pointing up (-y in image space)
px = np.abs(x - cx)
py = -(y - cy) + r * 0.25
px_k = np.sqrt(3.0)
# Standard IQ equilateral triangle SDF
px2 = px - r
py2 = py + r / px_k
cond = (px + px_k * py) > 0.0
nx = np.where(cond, (px - px_k * py) * 0.5, px)
ny = np.where(cond, (-px_k * px - py) * 0.5, py)
nx -= np.clip(nx, -2.0 * r, 0.0)
return -np.sqrt(nx * nx + ny * ny) * np.sign(ny)
def tile_coords() -> tuple[np.ndarray, np.ndarray]:
lin = np.linspace(-1.0 + 1.0 / TILE_SIZE, 1.0 - 1.0 / TILE_SIZE, TILE_SIZE, dtype=np.float32)
yy, xx = np.meshgrid(lin, lin, indexing="ij")
return xx, yy
def new_tile() -> dict[str, np.ndarray]:
shape = (TILE_SIZE, TILE_SIZE)
return {
"rgb": np.full((*shape, 3), 0.18, dtype=np.float32),
"alpha": np.zeros(shape, dtype=np.float32),
"height": np.ones(shape, dtype=np.float32),
"rough": np.full(shape, 0.56, dtype=np.float32),
"metal": np.full(shape, 0.35, dtype=np.float32),
}
def add_hex_bolt(
t: dict[str, np.ndarray],
x: np.ndarray,
y: np.ndarray,
cx: float,
cy: float,
pocket_r: float = 0.095,
head_r: float = 0.064,
base_h: float = 0.85,
) -> None:
dp = sd_circle(x, y, cx, cy, pocket_r)
dh = sd_circle(x, y, cx, cy, head_r)
dhex = sd_hexagon(x, y, cx, cy, head_r * 0.48)
in_pocket = smoothstep(0.015, -0.015, dp)
in_head = smoothstep(0.012, -0.012, dh)
in_socket = smoothstep(0.010, -0.010, dhex)
# Countersunk floor
pocket_h = base_h - 0.52 * in_pocket
# Raised chamfered bolt head inside pocket
head_profile = np.clip(1.0 - np.maximum(dh / head_r + 1.0, 0.0) ** 4 * 0.15, 0.0, 1.0)
bolt_h = base_h - 0.06 + 0.04 * head_profile
bolt_h = bolt_h - 0.36 * in_socket
t["height"] = np.where(in_head > 0.5, bolt_h, np.minimum(t["height"], pocket_h))
# Colors & PBR
pocket_col = np.array([0.055, 0.058, 0.056], dtype=np.float32)
bolt_col = np.array([0.24, 0.25, 0.24], dtype=np.float32)
sock_col = np.array([0.035, 0.036, 0.036], dtype=np.float32)
t["rgb"] = t["rgb"] * (1.0 - in_pocket[..., None]) + pocket_col * in_pocket[..., None]
t["rgb"] = t["rgb"] * (1.0 - in_head[..., None]) + bolt_col * in_head[..., None]
t["rgb"] = t["rgb"] * (1.0 - in_socket[..., None]) + sock_col * in_socket[..., None]
t["metal"] = np.where(in_head > 0.5, 0.88, np.where(in_pocket > 0.5, 0.65, t["metal"]))
t["rough"] = np.where(in_head > 0.5, 0.34, np.where(in_pocket > 0.5, 0.62, t["rough"]))
def add_domed_rivet(
t: dict[str, np.ndarray],
x: np.ndarray,
y: np.ndarray,
cx: float,
cy: float,
r: float = 0.052,
base_h: float = 0.88,
) -> None:
d = sd_circle(x, y, cx, cy, r)
mask = smoothstep(0.012, -0.012, d)
ring = smoothstep(0.018, 0.0, np.abs(d - 0.005))
dist_norm = np.clip(np.sqrt((x - cx) ** 2 + (y - cy) ** 2) / r, 0.0, 1.0)
dome = np.sqrt(np.maximum(1.0 - dist_norm ** 2, 0.0))
rivet_h = base_h - 0.08 * ring + 0.11 * dome * mask
t["height"] = t["height"] * (1.0 - mask) + np.clip(rivet_h, 0.0, 1.0) * mask
col = np.array([0.28, 0.29, 0.27], dtype=np.float32)
t["rgb"] = t["rgb"] * (1.0 - mask[..., None]) + col * mask[..., None]
t["metal"] = t["metal"] * (1.0 - mask) + 0.85 * mask
t["rough"] = t["rough"] * (1.0 - mask) + 0.32 * mask
# ---------------------------------------------------------------------------
# Individual tiles (0..15)
# ---------------------------------------------------------------------------
def tile_00_louvered_vent(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(0) Louvered armor vent."""
t = new_tile()
n1 = fbm(x, y, 10.0, 4, seed=101)
n2 = fbm(x, y, 36.0, 3, seed=102)
d_outer = sd_box(x, y, 0.0, 0.0, 0.80, 0.72, r=0.06)
d_inner = sd_box(x, y, 0.0, 0.0, 0.65, 0.56, r=0.03)
d_seam = np.abs(d_outer)
outer_m = smoothstep(0.025, -0.025, d_outer)
inner_m = smoothstep(0.02, -0.02, d_inner)
# Frame plate
frame_h = 0.96 - 0.04 * smoothstep(0.0, 0.14, np.maximum(-d_outer, 0.0))
frame_h -= 0.45 * smoothstep(0.03, 0.0, d_seam)
# Recessed bay behind louvers
h = np.where(inner_m > 0.5, 0.04, frame_h)
# 5 angled louvers inside d_inner
slat_centers = np.linspace(-0.42, 0.42, 5)
slat_mask_all = np.zeros_like(x)
for sc in slat_centers:
# Each louver spans x=[-0.62, 0.62], y=[sc-0.065, sc+0.065]
ds = sd_box(x, y, 0.0, float(sc), 0.62, 0.068, r=0.015)
sm = smoothstep(0.015, -0.015, ds)
# Slope from top (high) down to bottom (low), exposing dark gap underneath
local_t = np.clip((y - (sc - 0.068)) / 0.136, 0.0, 1.0)
slat_h = 0.92 - 0.62 * local_t
h = np.maximum(h, sm * slat_h)
slat_mask_all = np.maximum(slat_mask_all, sm)
# Paint + worn steel + soot inside vent
olive = np.array([0.16, 0.18, 0.14], dtype=np.float32) * (0.85 + 0.30 * n1[..., None])
steel = np.array([0.26, 0.27, 0.26], dtype=np.float32) * (0.85 + 0.30 * n2[..., None])
void = np.array([0.025, 0.025, 0.027], dtype=np.float32)
edge_wear = smoothstep(0.05, 0.0, np.abs(d_inner)) * smoothstep(0.35, 0.65, n2)
slat_top_wear = slat_mask_all * smoothstep(0.70, 0.92, h) * smoothstep(0.35, 0.70, n2)
wear = np.clip(np.maximum(edge_wear, slat_top_wear), 0.0, 1.0)
col = olive * (1.0 - wear[..., None]) + steel * wear[..., None]
# Darken recessed gap
in_void = inner_m * (1.0 - slat_mask_all)
col = col * (1.0 - in_void[..., None]) + void * in_void[..., None]
# Soot darkening on lower slope of slats
col *= (1.0 - 0.45 * slat_mask_all[..., None] * smoothstep(0.85, 0.30, h)[..., None])
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = outer_m
t["height"] = np.where(outer_m > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.35 + 0.55 * wear + 0.25 * slat_mask_all, 0.0, 1.0)
t["rough"] = np.clip(0.58 - 0.26 * wear + 0.25 * in_void, 0.18, 0.95)
for bx, by in [(-0.71, -0.63), (0.71, -0.63), (-0.71, 0.63), (0.71, 0.63)]:
add_hex_bolt(t, x, y, bx, by, pocket_r=0.055, head_r=0.036, base_h=0.95)
return t
def tile_01_bolted_hatch(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(1) Recessed bolted maintenance hatch."""
t = new_tile()
n1 = fbm(x, y, 8.0, 4, seed=201)
n2 = fbm(x, y, 28.0, 3, seed=202)
d_outer = sd_box(x, y, 0.0, 0.0, 0.80, 0.80, r=0.08)
d_groove = np.abs(sd_box(x, y, 0.0, 0.0, 0.66, 0.66, r=0.06))
d_door = sd_box(x, y, 0.0, 0.0, 0.63, 0.63, r=0.05)
d_latch = sd_box(x, y, 0.32, 0.0, 0.13, 0.22, r=0.03)
d_bar = sd_box(x, y, 0.32, 0.0, 0.045, 0.16, r=0.02)
outer_m = smoothstep(0.025, -0.025, d_outer)
groove_m = smoothstep(0.032, 0.0, d_groove)
latch_m = smoothstep(0.02, -0.02, d_latch)
bar_m = smoothstep(0.015, -0.015, d_bar)
h = np.full_like(x, 0.96)
# Bevel down into perimeter seam
h = np.where(d_door < 0.0, 0.88, h)
h -= 0.72 * groove_m
# Recessed latch pocket with grab bar
h = np.where(latch_m > 0.5, 0.22, h)
h = np.where(bar_m > 0.5, 0.86, h)
base_col = np.array([0.19, 0.21, 0.16], dtype=np.float32) * (0.86 + 0.28 * n1[..., None])
door_col = np.array([0.22, 0.24, 0.19], dtype=np.float32) * (0.86 + 0.28 * n1[..., None])
seam_col = np.array([0.04, 0.04, 0.038], dtype=np.float32)
bar_col = np.array([0.34, 0.34, 0.32], dtype=np.float32)
in_door = smoothstep(0.02, -0.02, d_door)
col = base_col * (1.0 - in_door[..., None]) + door_col * in_door[..., None]
# Paint chip around door edge
chip = smoothstep(0.05, 0.0, np.abs(d_door)) * smoothstep(0.45, 0.68, n2)
col = col * (1.0 - chip[..., None]) + np.array([0.32, 0.33, 0.32], dtype=np.float32) * chip[..., None]
col = col * (1.0 - groove_m[..., None]) + seam_col * groove_m[..., None]
col = col * (1.0 - latch_m[..., None]) + np.array([0.05, 0.05, 0.05], dtype=np.float32) * latch_m[..., None]
col = col * (1.0 - bar_m[..., None]) + bar_col * bar_m[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = outer_m
t["height"] = np.where(outer_m > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.30 + 0.55 * chip + 0.60 * bar_m, 0.0, 1.0)
t["rough"] = np.clip(0.56 - 0.24 * chip + 0.25 * groove_m, 0.2, 0.95)
for bx, by in [(-0.50, -0.50), (0.0, -0.52), (0.50, -0.50),
(-0.50, 0.50), (0.0, 0.52), (0.50, 0.50),
(-0.52, 0.0)]:
add_hex_bolt(t, x, y, bx, by, pocket_r=0.068, head_r=0.044, base_h=0.88)
return t
def tile_02_fastener_strip(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(2) 4-bolt recessed fastener strip."""
t = new_tile()
n1 = fbm(x, y, 12.0, 4, seed=301)
n2 = fbm(x, y, 40.0, 3, seed=302)
d_strip = sd_box(x, y, 0.0, 0.0, 0.84, 0.28, r=0.08)
d_bevel = sd_box(x, y, 0.0, 0.0, 0.78, 0.22, r=0.05)
mask = smoothstep(0.025, -0.025, d_strip)
# Raised beveled plate with seam around edge
h = np.where(d_bevel < 0.0, 0.93, 0.82)
h -= 0.45 * smoothstep(0.03, 0.0, np.abs(d_strip))
col = np.array([0.21, 0.22, 0.19], dtype=np.float32) * (0.86 + 0.28 * n1[..., None])
edge_wear = smoothstep(0.05, 0.0, np.abs(d_bevel)) * smoothstep(0.35, 0.70, n2)
col = col * (1.0 - edge_wear[..., None]) + np.array([0.36, 0.37, 0.36], dtype=np.float32) * edge_wear[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = mask
t["height"] = np.where(mask > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.45 + 0.45 * edge_wear, 0.0, 1.0)
t["rough"] = np.clip(0.48 - 0.18 * edge_wear, 0.22, 0.9)
for bx in (-0.57, -0.19, 0.19, 0.57):
add_hex_bolt(t, x, y, bx, 0.0, pocket_r=0.115, head_r=0.075, base_h=0.93)
return t
def tile_03_intake_grille(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(3) Slotted intake grille."""
t = new_tile()
n1 = fbm(x, y, 10.0, 4, seed=401)
n2 = fbm(x, y, 32.0, 3, seed=402)
d_outer = sd_box(x, y, 0.0, 0.0, 0.80, 0.76, r=0.07)
d_inner = sd_box(x, y, 0.0, 0.0, 0.66, 0.60, r=0.04)
outer_m = smoothstep(0.025, -0.025, d_outer)
inner_m = smoothstep(0.02, -0.02, d_inner)
h = np.where(inner_m > 0.5, 0.88, 0.96)
h -= 0.38 * smoothstep(0.03, 0.0, np.abs(d_inner))
# 6 vertical intake slots (2 rows of 6 or 6 tall slots)
slot_void = np.zeros_like(x)
for sx in np.linspace(-0.48, 0.48, 6):
for sy in (-0.27, 0.27):
ds = sd_box(x, y, float(sx), float(sy), 0.046, 0.21, r=0.038)
sm = smoothstep(0.015, -0.015, ds)
# Chamfered rim then deep void
rim = smoothstep(0.035, 0.0, np.abs(ds - 0.012))
h = np.where(sm > 0.5, 0.02, h - 0.18 * rim)
slot_void = np.maximum(slot_void, sm)
plate_col = np.array([0.16, 0.17, 0.16], dtype=np.float32) * (0.85 + 0.3 * n1[..., None])
rib_wear = smoothstep(0.45, 0.75, n2) * inner_m * (1.0 - slot_void) * 0.45
col = plate_col * (1.0 - rib_wear[..., None]) + np.array([0.30, 0.31, 0.30], dtype=np.float32) * rib_wear[..., None]
col = col * (1.0 - slot_void[..., None]) + np.array([0.02, 0.02, 0.022], dtype=np.float32) * slot_void[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = outer_m
t["height"] = np.where(outer_m > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.55 + 0.35 * rib_wear - 0.5 * slot_void, 0.0, 1.0)
t["rough"] = np.clip(0.46 - 0.15 * rib_wear + 0.4 * slot_void, 0.2, 0.95)
for rx, ry in [(-0.72, -0.68), (0.72, -0.68), (-0.72, 0.68), (0.72, 0.68)]:
add_domed_rivet(t, x, y, rx, ry, r=0.042, base_h=0.95)
return t
def tile_04_rivet_seam(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(4) Rivet panel seam."""
t = new_tile()
n1 = fbm(x, y, 10.0, 4, seed=501)
n2 = fbm(x, y, 36.0, 3, seed=502)
d_strip = sd_box(x, y, 0.0, 0.0, 0.84, 0.32, r=0.04)
mask = smoothstep(0.025, -0.025, d_strip)
# Central recessed panel seam groove along y=0, clipped inside strip
groove = smoothstep(0.042, 0.0, np.abs(y)) * mask
h = 0.90 - 0.72 * groove
col = np.array([0.20, 0.21, 0.17], dtype=np.float32) * (0.85 + 0.3 * n1[..., None])
chip = smoothstep(0.08, 0.0, np.abs(y)) * smoothstep(0.48, 0.70, n2) * mask
col = col * (1.0 - chip[..., None]) + np.array([0.34, 0.35, 0.34], dtype=np.float32) * chip[..., None]
col = col * (1.0 - groove[..., None]) + np.array([0.04, 0.04, 0.036], dtype=np.float32) * groove[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = mask
t["height"] = np.where(mask > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.32 + 0.55 * chip, 0.0, 1.0)
t["rough"] = np.clip(0.56 - 0.24 * chip + 0.30 * groove, 0.2, 0.95)
for rx in np.linspace(-0.70, 0.70, 6):
add_domed_rivet(t, x, y, float(rx), -0.15, r=0.046, base_h=0.90)
add_domed_rivet(t, x, y, float(rx), 0.15, r=0.046, base_h=0.90)
return t
def tile_05_welded_patch(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(5) Welded armor repair patch."""
t = new_tile()
n1 = fbm(x, y, 9.0, 4, seed=601)
n2 = fbm(x, y, 42.0, 3, seed=602)
# Slightly rotated/chamfered patch shape
ca, sa = np.cos(0.08), np.sin(0.08)
xr = x * ca - y * sa
yr = x * sa + y * ca
d_patch = sd_box(xr, yr, 0.0, 0.0, 0.64, 0.50, r=0.05)
# Irregular outer weld apron
d_outer = d_patch - 0.12
outer_m = smoothstep(0.025, -0.025, d_outer)
patch_m = smoothstep(0.018, -0.018, d_patch)
# Weld bead ripple along perimeter d_patch ~= 0
bead_band = smoothstep(0.085, 0.0, np.abs(d_patch - 0.01))
# Ripple along perimeter coordinate
ripple = 0.5 + 0.5 * np.sin((xr + yr) * 48.0 + n2 * 6.0)
bead_h = 0.72 + 0.27 * bead_band * (0.65 + 0.35 * ripple)
h = np.where(patch_m > 0.5, 0.92 - 0.03 * n1, 0.68)
h = np.maximum(h, bead_h * bead_band)
patch_col = np.array([0.23, 0.24, 0.21], dtype=np.float32) * (0.85 + 0.30 * n1[..., None])
weld_col = np.array([0.38, 0.36, 0.33], dtype=np.float32) * (0.80 + 0.35 * ripple[..., None])
# Heat-affected straw/blue oxide halo outside weld
haz = smoothstep(0.14, 0.02, np.abs(d_patch - 0.03)) * (1.0 - bead_band)
haz_col = np.array([0.14, 0.12, 0.14], dtype=np.float32)
col = haz_col * haz[..., None] + patch_col * patch_m[..., None]
col = col * (1.0 - bead_band[..., None]) + weld_col * bead_band[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = np.clip(np.maximum(patch_m, bead_band * 0.95 + haz * 0.75) * outer_m, 0.0, 1.0)
t["height"] = np.where(t["alpha"] > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.35 + 0.58 * bead_band, 0.0, 1.0)
t["rough"] = np.clip(0.55 - 0.28 * bead_band, 0.18, 0.92)
return t
def tile_06_lift_lug(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(6) Recessed lift-lug pocket."""
t = new_tile()
n1 = fbm(x, y, 11.0, 4, seed=701)
n2 = fbm(x, y, 34.0, 3, seed=702)
d_outer = sd_box(x, y, 0.0, 0.0, 0.74, 0.74, r=0.10)
d_pocket = sd_box(x, y, 0.0, 0.0, 0.52, 0.52, r=0.09)
outer_m = smoothstep(0.025, -0.025, d_outer)
pocket_m = smoothstep(0.02, -0.02, d_pocket)
# Chamfered pit wall
wall_t = np.clip(-d_pocket / 0.14, 0.0, 1.0)
pit_h = 0.94 - 0.84 * smoothstep(0.0, 1.0, wall_t)
h = np.where(pocket_m > 0.5, pit_h, 0.96)
# Cylindrical steel crossbar along X (spanning the recessed pocket)
d_bar_y = np.abs(y) / 0.135
d_bar_x = np.abs(x) - 0.50
bar_m = smoothstep(1.06, 0.94, d_bar_y) * smoothstep(0.02, -0.02, d_bar_x)
cyl_z = np.sqrt(np.maximum(1.0 - np.clip(d_bar_y, 0.0, 1.0) ** 2, 0.0))
bar_h = 0.45 + 0.50 * cyl_z
h = np.where(bar_m > 0.5, np.maximum(h, bar_h), h)
flange_col = np.array([0.18, 0.19, 0.16], dtype=np.float32) * (0.85 + 0.30 * n1[..., None])
pit_col = np.array([0.055, 0.056, 0.055], dtype=np.float32) * (0.8 + 0.3 * n1[..., None])
bar_col = np.array([0.36, 0.37, 0.36], dtype=np.float32) * (0.85 + 0.25 * n2[..., None])
col = flange_col * (1.0 - pocket_m[..., None]) + pit_col * pocket_m[..., None]
col = col * (1.0 - bar_m[..., None]) + bar_col * bar_m[..., None]
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = outer_m
t["height"] = np.where(outer_m > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.35 + 0.58 * bar_m, 0.0, 1.0)
t["rough"] = np.clip(0.55 - 0.28 * bar_m + 0.20 * pocket_m * (1.0 - bar_m), 0.18, 0.95)
return t
def tile_07_hazard_chevron(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(7) Weathered hazard caution chevron strip."""
t = new_tile()
n1 = fbm(x, y, 8.0, 4, seed=801)
n2 = fbm(x, y, 34.0, 4, seed=802)
d_strip = sd_box(x, y, 0.0, 0.0, 0.84, 0.26, r=0.025)
d_inner = sd_box(x, y, 0.0, 0.0, 0.78, 0.20, r=0.015)
strip_m = smoothstep(0.02, -0.02, d_strip)
inner_m = smoothstep(0.015, -0.015, d_inner)
# Diagonal stripes
stripe_wave = np.sin((x * 2.2 + y * 2.2) * np.pi * 2.4)
is_yellow = smoothstep(-0.08, 0.08, stripe_wave)
yellow = np.array([0.68, 0.44, 0.06], dtype=np.float32)
black = np.array([0.055, 0.055, 0.052], dtype=np.float32)
steel = np.array([0.28, 0.29, 0.28], dtype=np.float32)
col = black * (1.0 - is_yellow[..., None]) + yellow * is_yellow[..., None]
# Thin dark border frame
col = black * (1.0 - inner_m[..., None]) + col * inner_m[..., None]
# Grime + paint chips
chip = smoothstep(0.62, 0.69, n2)
col *= (0.78 + 0.35 * n1[..., None])
col = col * (1.0 - chip[..., None] * 0.75) + steel * (chip[..., None] * 0.75)
# Subtle paint film thickness + border recess
h = 0.98 - 0.08 * (1.0 - inner_m) - 0.04 * chip
edge_wear = smoothstep(0.06, 0.0, np.abs(d_strip)) * smoothstep(0.55, 0.72, n2)
alpha = np.clip(strip_m * (1.0 - 0.80 * edge_wear), 0.0, 1.0)
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = np.clip(alpha, 0.0, 1.0)
t["height"] = np.where(strip_m > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.15 + 0.65 * chip, 0.0, 1.0)
t["rough"] = np.clip(0.60 - 0.25 * chip, 0.25, 0.92)
return t
# ---------------------------------------------------------------------------
# Row 2: Stencils & Emblems
# ---------------------------------------------------------------------------
def _sd_digit_0(x: np.ndarray, y: np.ndarray, cx: float, cy: float) -> np.ndarray:
d_out = sd_box(x, y, cx, cy, 0.28, 0.46, r=0.14)
d_in = sd_box(x, y, cx, cy, 0.11, 0.28, r=0.05)
d = np.maximum(d_out, -d_in)
# Stencil bridge gaps top/bottom
gap = np.abs(x - cx) - 0.032
d_bridge = np.maximum(gap, 0.25 - np.abs(y - cy))
return np.maximum(d, -d_bridge)
def _sd_digit_3(x: np.ndarray, y: np.ndarray, cx: float, cy: float) -> np.ndarray:
d_out = sd_box(x, y, cx, cy, 0.28, 0.46, r=0.14)
d_in_top = sd_box(x, y, cx - 0.04, cy - 0.20, 0.16, 0.11, r=0.03)
d_in_bot = sd_box(x, y, cx - 0.04, cy + 0.20, 0.16, 0.11, r=0.03)
d_open_l = sd_box(x, y, cx - 0.24, cy, 0.16, 0.15, r=0.0)
d = np.maximum(d_out, -np.minimum(np.minimum(d_in_top, d_in_bot), d_open_l))
# Stencil bridge on right spine
gap = np.maximum(np.abs(y - cy) - 0.028, (cx - 0.05) - x)
return np.maximum(d, -gap)
def _sd_digit_7(x: np.ndarray, y: np.ndarray, cx: float, cy: float) -> np.ndarray:
d_top = sd_box(x, y, cx, cy - 0.37, 0.28, 0.09, r=0.02)
# Slanted leg from (cx+0.20, cy-0.36) to (cx-0.08, cy+0.39)
d_leg = sd_segment(x, y, cx + 0.18, cy - 0.34, cx - 0.07, cy + 0.38) - 0.088
d = np.minimum(d_top, d_leg)
# Stencil gap between top bar & leg
gap = sd_box(x, y, cx + 0.12, cy - 0.25, 0.20, 0.025, r=0.0)
return np.maximum(d, -gap)
def _finish_stencil(
x: np.ndarray,
y: np.ndarray,
mask: np.ndarray,
paint_col: np.ndarray,
seed: int,
) -> dict[str, np.ndarray]:
t = new_tile()
n1 = fbm(x, y, 10.0, 4, seed=seed)
n2 = fbm(x, y, 40.0, 4, seed=seed + 1)
# Flaking & scratching across stencil paint
flake = smoothstep(0.58, 0.72, n2)
scratches = smoothstep(0.68, 0.74, fbm(x * 0.4 + y * 1.8, y * 0.4, 24.0, 3, seed=seed + 2))
wear = np.clip(flake * 0.85 + scratches * 0.7, 0.0, 1.0)
alpha = np.clip(mask * (1.0 - wear * 0.85), 0.0, 1.0)
col = paint_col * (0.82 + 0.25 * n1[..., None])
h = 1.0 - 0.02 * mask * (1.0 - wear) - 0.04 * (1.0 - mask)
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = alpha
t["height"] = np.where(alpha > 0.02, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.full_like(x, 0.08)
t["rough"] = np.clip(0.68 + 0.15 * n1, 0.4, 0.9)
return t
def tile_08_stencil_03(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(8) Tactical stencil '03'."""
d = np.minimum(_sd_digit_0(x, y, -0.36, 0.0), _sd_digit_3(x, y, 0.36, 0.0))
mask = smoothstep(0.02, -0.02, d)
return _finish_stencil(x, y, mask, np.array([0.74, 0.71, 0.62], dtype=np.float32), seed=901)
def tile_09_stencil_07(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(9) Tactical stencil '07'."""
d = np.minimum(_sd_digit_0(x, y, -0.36, 0.0), _sd_digit_7(x, y, 0.36, 0.0))
mask = smoothstep(0.02, -0.02, d)
return _finish_stencil(x, y, mask, np.array([0.74, 0.71, 0.62], dtype=np.float32), seed=1001)
def tile_10_radiation_warning(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(10) Radiation / thermal warning stencil."""
r = np.sqrt(x * x + y * y)
ang = np.arctan2(y, x)
# Outer dashed warning ring
d_ring = np.abs(r - 0.66) - 0.065
ring_seg = np.abs(((ang + np.pi) / (np.pi / 3.0)) % 1.0 - 0.5) - 0.34
d_ring = np.maximum(d_ring, ring_seg * 0.5)
# Central dot + 3 trefoil blades
d_core = r - 0.11
blade_annulus = np.maximum(0.18 - r, r - 0.52)
blade_ang = np.cos(3.0 * (ang + np.pi / 6.0))
d_blades = np.maximum(blade_annulus, (0.45 - blade_ang) * 0.28)
d = np.minimum(np.minimum(d_ring, d_core), d_blades)
mask = smoothstep(0.02, -0.02, d)
return _finish_stencil(x, y, mask, np.array([0.78, 0.36, 0.09], dtype=np.float32), seed=1101)
def tile_11_faction_emblem(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(11) Faction chevron emblem."""
ax = np.abs(x)
# Double military chevron + diamond center
d1 = np.abs((y + 0.14) + ax * 0.85) - 0.085
d1 = np.maximum(d1, ax - 0.68)
d2 = np.abs((y - 0.22) + ax * 0.85) - 0.065
d2 = np.maximum(d2, ax - 0.52)
d_diamond = (ax * 0.9 + np.abs(y + 0.42)) - 0.18
d_chev = np.minimum(d1, d2)
m_chev = smoothstep(0.02, -0.02, d_chev)
m_dia = smoothstep(0.02, -0.02, d_diamond)
mask = np.maximum(m_chev, m_dia)
t = _finish_stencil(x, y, mask, np.array([0.76, 0.72, 0.60], dtype=np.float32), seed=1201)
# Signal orange center diamond
orange = np.array([0.74, 0.27, 0.10], dtype=np.float32)
t["rgb"] = t["rgb"] * (1.0 - m_dia[..., None]) + orange * m_dia[..., None]
return t
# ---------------------------------------------------------------------------
# Row 3: Dynamic combat hits (12..15)
# ---------------------------------------------------------------------------
def tile_12_ap_penetration(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(12) Deep AP autocannon penetration hole (rolled metallic rim + black bore + hot rim)."""
t = new_tile()
n1 = fbm(x, y, 7.0, 4, seed=1301)
n2 = fbm(x, y, 24.0, 4, seed=1302)
ang = np.arctan2(y, x)
# Jagged petal modulation around bore
jagged = 0.065 * np.sin(ang * 7.0 + 1.1) + 0.045 * np.cos(ang * 13.0 - 0.4) + 0.09 * (n2 - 0.5)
r = np.sqrt(x * x + y * y) + jagged
bore_r = 0.28
rim_r = 0.44
scorch_r = 0.82
bore_m = smoothstep(bore_r + 0.03, bore_r - 0.02, r)
rim_m = smoothstep(0.10, 0.0, np.abs(r - (bore_r + 0.05)))
scorch_m = smoothstep(scorch_r, bore_r * 0.8, r) * (0.55 + 0.45 * n1)
# Height: flush 1.0 outside -> raised/rolled rim at 0.96 -> sharp drop into 0.0 pitch-black bore
hole_wall = smoothstep(bore_r - 0.04, rim_r, r)
h = np.clip(hole_wall * 0.96 + 0.04 * smoothstep(rim_r + 0.12, rim_r, r), 0.0, 1.0)
h = np.where(r > rim_r + 0.12, 1.0, h)
soot_col = np.array([0.04, 0.035, 0.032], dtype=np.float32)
steel_col = np.array([0.52, 0.54, 0.56], dtype=np.float32) * (0.75 + 0.45 * n2[..., None])
bore_col = np.array([0.012, 0.010, 0.010], dtype=np.float32)
col = soot_col * (1.0 - rim_m[..., None]) + steel_col * rim_m[..., None]
col = col * (1.0 - bore_m[..., None]) + bore_col * bore_m[..., None]
# Alpha: opaque in bore + metal rim, softly feathered soot halo
alpha = np.clip(np.maximum(np.maximum(bore_m, rim_m), scorch_m * 0.88), 0.0, 1.0)
# Keep zero bleed at outer margin
border = smoothstep(0.92, 0.78, np.maximum(np.abs(x), np.abs(y)))
alpha *= border
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = alpha
t["height"] = np.where(alpha > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(rim_m * 0.94 + bore_m * 0.10, 0.0, 1.0)
t["rough"] = np.clip(0.92 - rim_m * 0.66, 0.22, 0.96)
return t
def tile_13_shrapnel_gouge(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(13) Diagonal shrapnel/flak armor gouge."""
t = new_tile()
n1 = fbm(x, y, 8.0, 4, seed=1401)
n2 = fbm(x, y, 28.0, 4, seed=1402)
# Rotate -35 degrees for diagonal ricochet trench
ca, sa = np.cos(-0.62), np.sin(-0.62)
u = x * ca - y * sa
v = x * sa + y * ca + 0.04 * (n2 - 0.5)
# Tapered V-trough from u=-0.62 to u=+0.62
d_trench = sd_segment(u, v, -0.58, 0.0, 0.58, 0.0)
width = 0.13 + 0.05 * np.clip((u + 0.58) / 1.16, 0.0, 1.0)
trough_t = np.clip(1.0 - d_trench / width, 0.0, 1.0)
burr_m = smoothstep(0.06, 0.0, np.abs(d_trench - width))
h = 1.0 - 0.88 * smoothstep(0.0, 1.0, trough_t)
# Upturned burr ridge at edge
h = np.clip(h + 0.04 * burr_m, 0.0, 1.0)
soot = np.array([0.045, 0.04, 0.036], dtype=np.float32)
torn_steel = np.array([0.50, 0.52, 0.54], dtype=np.float32) * (0.75 + 0.45 * n2[..., None])
furrow_dark = np.array([0.09, 0.09, 0.095], dtype=np.float32)
trench_m = smoothstep(0.05, 0.25, trough_t)
col = soot * (1.0 - trench_m[..., None]) + torn_steel * trench_m[..., None]
col = col * (1.0 - smoothstep(0.60, 0.95, trough_t)[..., None] * 0.7) + furrow_dark * (smoothstep(0.60, 0.95, trough_t)[..., None] * 0.7)
col = col * (1.0 - burr_m[..., None] * 0.65) + torn_steel * (burr_m[..., None] * 0.65)
scorch_halo = smoothstep(0.42, 0.08, d_trench) * (0.5 + 0.5 * n1)
alpha = np.clip(np.maximum(trench_m, np.maximum(burr_m, scorch_halo * 0.85)), 0.0, 1.0)
border = smoothstep(0.92, 0.78, np.maximum(np.abs(x), np.abs(y)))
alpha *= border
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = alpha
t["height"] = np.where(alpha > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(np.maximum(trench_m, burr_m) * 0.90, 0.0, 1.0)
t["rough"] = np.clip(0.90 - np.maximum(trench_m, burr_m) * 0.62, 0.24, 0.95)
return t
def tile_14_plasma_crater(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(14) Molten plasma burn crater."""
t = new_tile()
n1 = fbm(x, y, 7.5, 4, seed=1501)
n2 = fbm(x, y, 22.0, 4, seed=1502)
r = np.sqrt(x * x + y * y) + 0.08 * (n2 - 0.5)
crater_r = 0.44
bowl_m = smoothstep(crater_r + 0.04, crater_r - 0.08, r)
rim_m = smoothstep(0.08, 0.0, np.abs(r - crater_r))
scorch_m = smoothstep(0.84, 0.36, r) * (0.5 + 0.5 * n1)
# Slag ripples in bowl + crisp crater rim
ripples = 0.5 + 0.5 * np.sin(r * 34.0 + n2 * 4.0)
bowl_depth = smoothstep(crater_r, 0.04, r)
h = 1.0 - 0.88 * bowl_depth + 0.08 * ripples * bowl_m + 0.06 * rim_m
carbon = np.array([0.035, 0.030, 0.028], dtype=np.float32)
slag = np.array([0.22, 0.16, 0.14], dtype=np.float32) * (0.8 + 0.4 * ripples[..., None])
molten_lip = np.array([0.46, 0.38, 0.32], dtype=np.float32)
col = carbon * (1.0 - bowl_m[..., None]) + slag * bowl_m[..., None]
col = col * (1.0 - rim_m[..., None] * 0.7) + molten_lip * (rim_m[..., None] * 0.7)
alpha = np.clip(np.maximum(bowl_m, np.maximum(rim_m, scorch_m * 0.90)), 0.0, 1.0)
border = smoothstep(0.92, 0.78, np.maximum(np.abs(x), np.abs(y)))
alpha *= border
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = alpha
t["height"] = np.where(alpha > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(bowl_m * 0.78 + rim_m * 0.85, 0.0, 1.0)
t["rough"] = np.clip(0.92 - bowl_m * 0.50 - rim_m * 0.45, 0.28, 0.96)
return t
def tile_15_blast_scorch(x: np.ndarray, y: np.ndarray) -> dict[str, np.ndarray]:
"""(15) Radial blast scorch mark."""
t = new_tile()
n1 = fbm(x, y, 6.0, 4, seed=1601)
n2 = fbm(x, y, 20.0, 4, seed=1602)
ang = np.arctan2(y, x)
r = np.sqrt(x * x + y * y)
# Radial blast rays
rays = 0.55 + 0.45 * value_noise(np.cos(ang) * 3.0, np.sin(ang) * 3.0, 3.5, seed=1603)
rays *= (0.7 + 0.3 * np.sin(ang * 11.0 + n2 * 3.0))
r_eff = r / np.maximum(rays, 0.35)
scorch = smoothstep(0.95, 0.08, r_eff) * (0.65 + 0.35 * n1)
pock = smoothstep(0.24, 0.05, r + 0.05 * (n2 - 0.5))
h = 1.0 - 0.45 * pock - 0.04 * scorch
soot = np.array([0.032, 0.028, 0.025], dtype=np.float32)
ash = np.array([0.11, 0.095, 0.082], dtype=np.float32)
col = soot * (1.0 - pock[..., None] * 0.35) + ash * (pock[..., None] * 0.35)
border = smoothstep(0.93, 0.78, np.maximum(np.abs(x), np.abs(y)))
alpha = np.clip(scorch * 0.92 * border, 0.0, 1.0)
t["rgb"] = np.clip(col, 0.0, 1.0)
t["alpha"] = alpha
t["height"] = np.where(alpha > 0.01, np.clip(h, 0.0, 1.0), 1.0)
t["metal"] = np.clip(0.05 + 0.25 * pock, 0.0, 1.0)
t["rough"] = np.clip(0.94 - 0.20 * pock, 0.65, 0.98)
return t
# ---------------------------------------------------------------------------
# Normal map, AO, color dilation, and atlas assembly
# ---------------------------------------------------------------------------
def compute_normal_map(height: np.ndarray, strength: float = 5.5) -> np.ndarray:
"""Sobel tangent-space normal map matching OpenGL/Godot (+X right, +Y down, +Z out)."""
h = np.pad(height, 1, mode="edge")
# Sobel X (+right) and Y (+down)
dx = ((h[:-2, 2:] + 2.0 * h[1:-1, 2:] + h[2:, 2:])
- (h[:-2, :-2] + 2.0 * h[1:-1, :-2] + h[2:, :-2])) * 0.125
dy = ((h[2:, :-2] + 2.0 * h[2:, 1:-1] + h[2:, 2:])
- (h[:-2, :-2] + 2.0 * h[:-2, 1:-1] + h[:-2, 2:])) * 0.125
nx = -dx * strength
ny = -dy * strength
nz = np.ones_like(nx)
inv_len = 1.0 / np.sqrt(nx * nx + ny * ny + nz * nz + 1e-12)
return np.stack([nx * inv_len * 0.5 + 0.5,
ny * inv_len * 0.5 + 0.5,
nz * inv_len * 0.5 + 0.5], axis=-1)
def compute_height_ao(height: np.ndarray) -> np.ndarray:
"""Fast multi-radius horizon/cavity AO from the heightfield."""
ao = np.ones_like(height, dtype=np.float32)
dirs = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, 1), (1, -1), (-1, -1)]
radii = (2, 5, 10)
occ_sum = np.zeros_like(height, dtype=np.float32)
count = 0
h_pad = np.pad(height, 12, mode="edge")
H, W = height.shape
for r in radii:
for dx, dy in dirs:
ox = 12 + dx * r
oy = 12 + dy * r
sample_h = h_pad[oy : oy + H, ox : ox + W]
diff = np.maximum(sample_h - height, 0.0)
occ_sum += np.clip(diff * 2.8, 0.0, 1.0)
count += 1
cavity = occ_sum / float(count)
# Also darken deep recesses naturally
ao = np.clip((1.0 - cavity * 1.35) * (0.30 + 0.70 * height), 0.08, 1.0)
return ao
def dilate_albedo(rgb: np.ndarray, alpha: np.ndarray, steps: int = 8) -> np.ndarray:
"""Propagate opaque RGB into transparent pixels to eliminate bilinear dark fringes."""
out = rgb.copy()
mask = alpha > 0.04
for _ in range(steps):
if np.all(mask):
break
acc = np.zeros_like(out)
wsum = np.zeros(mask.shape, dtype=np.float32)
p_rgb = np.pad(out, ((1, 1), (1, 1), (0, 0)), mode="edge")
p_m = np.pad(mask.astype(np.float32), ((1, 1), (1, 1)), mode="edge")
H, W = mask.shape
for dy in (-1, 0, 1):
for dx in (-1, 0, 1):
if dx == 0 and dy == 0:
continue
m_nb = p_m[1 + dy : 1 + dy + H, 1 + dx : 1 + dx + W]
acc += p_rgb[1 + dy : 1 + dy + H, 1 + dx : 1 + dx + W] * m_nb[..., None]
wsum += m_nb
fill = (~mask) & (wsum > 0.0)
out[fill] = acc[fill] / wsum[fill, None]
mask = mask | fill
return out
def main() -> int:
OUT_DIR.mkdir(parents=True, exist_ok=True)
x, y = tile_coords()
builders = [
tile_00_louvered_vent,
tile_01_bolted_hatch,
tile_02_fastener_strip,
tile_03_intake_grille,
tile_04_rivet_seam,
tile_05_welded_patch,
tile_06_lift_lug,
tile_07_hazard_chevron,
tile_08_stencil_03,
tile_09_stencil_07,
tile_10_radiation_warning,
tile_11_faction_emblem,
tile_12_ap_penetration,
tile_13_shrapnel_gouge,
tile_14_plasma_crater,
tile_15_blast_scorch,
]
atlas_albedo = np.zeros((ATLAS_SIZE, ATLAS_SIZE, 4), dtype=np.uint8)
atlas_normal = np.zeros((ATLAS_SIZE, ATLAS_SIZE, 3), dtype=np.uint8)
atlas_ormh = np.zeros((ATLAS_SIZE, ATLAS_SIZE, 4), dtype=np.uint8)
for idx, fn in enumerate(builders):
row = idx // GRID
col = idx % GRID
t = fn(x, y)
rgb_dilated = dilate_albedo(t["rgb"], t["alpha"], steps=12)
nrm = compute_normal_map(t["height"], strength=6.0)
ao = compute_height_ao(t["height"])
y0, y1 = row * TILE_SIZE, (row + 1) * TILE_SIZE
x0, x1 = col * TILE_SIZE, (col + 1) * TILE_SIZE
albedo_rgba = np.dstack([rgb_dilated, t["alpha"]])
ormh_rgba = np.dstack([ao, t["rough"], t["metal"], t["height"]])
atlas_albedo[y0:y1, x0:x1] = np.clip(np.round(albedo_rgba * 255.0), 0, 255).astype(np.uint8)
atlas_normal[y0:y1, x0:x1] = np.clip(np.round(nrm * 255.0), 0, 255).astype(np.uint8)
atlas_ormh[y0:y1, x0:x1] = np.clip(np.round(ormh_rgba * 255.0), 0, 255).astype(np.uint8)
Image.fromarray(atlas_albedo, mode="RGBA").save(OUT_DIR / "decal_atlas_albedo.png")
Image.fromarray(atlas_normal, mode="RGB").save(OUT_DIR / "decal_atlas_normal.png")
Image.fromarray(atlas_ormh, mode="RGBA").save(OUT_DIR / "decal_atlas_ormh.png")
print(f"Wrote 1024x1024 decal atlas textures to {OUT_DIR}")
return 0
if __name__ == "__main__":
raise SystemExit(main())

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 KiB