"""PBR holo foil (Pokemon-card style) for a friend, 2026-10-13. Tessel (Claude Opus 5.5). A metallic foil: rainbow base colour (for metals, base colour tints the reflections), a faceted normal map (tileable Voronoi shards, each tilted a little, so different shards catch the light at different view angles: the glitter), "cosmos" dots and rings like the classic holo cards, and low roughness. Writes 1024 px, all tileable: pbr_base.png base colour pbr_normal.png tangent-space normal (OpenGL, +Y up, which glTF and SL use) pbr_orm.png R occlusion (1), G roughness, B metallic (glTF packing) pbr_preview.png the three side by side, plus a fake lit render at three light angles Run with local/hear-venv python. """ import colorsys import os import numpy as np from PIL import Image HERE = os.path.dirname(os.path.abspath(__file__)) N = 1024 rng = np.random.default_rng(11) yy, xx = np.mgrid[0:N, 0:N].astype(np.float32) u, v = xx / N, yy / N def wrapd(a, b): d = np.abs(a - b) return np.minimum(d, N - d) # --- tileable Voronoi shards: nearest of K seeds with wrap-around distance K = 900 seeds = rng.uniform(0, N, (K, 2)).astype(np.float32) best = np.full((N, N), 1e9, np.float32) second = np.full((N, N), 1e9, np.float32) cell = np.zeros((N, N), np.int32) for k, (sx, sy) in enumerate(seeds): d = np.sqrt(wrapd(xx, sx) ** 2 + wrapd(yy, sy) ** 2) closer = d < best second = np.where(closer, best, np.minimum(second, d)) best = np.where(closer, d, best) cell = np.where(closer, k, cell) edge = np.clip((second - best) / 2.0, 0, 1) # 0 on shard borders tilt = rng.normal(0, 0.16, (K, 2)).astype(np.float32) # per-shard normal tilt (x, y) nx = tilt[cell, 0] * edge ny = tilt[cell, 1] * edge # --- cosmos: scattered discs and rings (each a soft dome in the normal map, a hue jump in the colour) cos_mask = np.zeros((N, N), np.float32) cos_hue = np.zeros((N, N), np.float32) for _ in range(70): cx, cy = rng.uniform(0, N, 2) r = rng.choice([6, 9, 14, 22, 34]) dx = (xx - cx + N / 2) % N - N / 2 dy = (yy - cy + N / 2) % N - N / 2 d = np.sqrt(dx * dx + dy * dy) ring = rng.random() < 0.4 m = np.clip(1 - np.abs(d - r * 0.8) / (r * 0.18), 0, 1) if ring else np.clip(1 - d / r, 0, 1) h = rng.random() upd = m > cos_mask cos_hue = np.where(upd, h, cos_hue) cos_mask = np.maximum(cos_mask, m) dome = np.clip(1 - d / r, 0, 1) nx += np.where(d < r, dx / r * 0.5 * dome, 0) ny += np.where(d < r, -dy / r * 0.5 * dome, 0) nz = np.ones_like(nx) ln = np.sqrt(nx ** 2 + ny ** 2 + nz ** 2) normal = np.dstack([nx / ln, ny / ln, nz / ln]) Image.fromarray(((normal * 0.5 + 0.5) * 255).astype(np.uint8), "RGB").save(os.path.join(HERE, "pbr_normal.png")) # --- base colour: a diagonal rainbow (period 1, tiles), nudged per shard so neighbours differ a little hue = ((u + v) * 1.0 + rng.normal(0, 0.035, K)[cell]) % 1.0 hue = np.where(cos_mask > 0.3, (cos_hue + 0.5 * hue) % 1.0, hue) sat = 0.42 + 0.18 * cos_mask val = 0.92 + 0.06 * edge hsv = np.dstack([hue, sat, val]).reshape(-1, 3) rgb = np.array([colorsys.hsv_to_rgb(*p) for p in hsv], np.float32).reshape(N, N, 3) rgb *= (0.75 + 0.25 * edge)[..., None] # faint dark seams between shards Image.fromarray((np.clip(rgb, 0, 1) * 255).astype(np.uint8), "RGB").save(os.path.join(HERE, "pbr_base.png")) # --- ORM: occlusion 1, roughness low with a little per-shard variety (rougher seams), metallic 1 rough = 0.16 + rng.uniform(0, 0.12, K)[cell] + 0.25 * (1 - edge) orm = np.dstack([np.ones_like(rough), np.clip(rough, 0, 1), np.ones_like(rough)]) Image.fromarray((orm * 255).astype(np.uint8), "RGB").save(os.path.join(HERE, "pbr_orm.png")) # --- preview: fake lighting with a light swept across, so I can see the shards catch it prev = Image.new("RGB", (512 * 3, 512 * 2)) small = lambda a: Image.fromarray(a).resize((512, 512)) prev.paste(small((np.clip(rgb, 0, 1) * 255).astype(np.uint8)), (0, 0)) prev.paste(small(((normal * 0.5 + 0.5) * 255).astype(np.uint8)), (512, 0)) prev.paste(small((orm * 255).astype(np.uint8)), (1024, 0)) for i, ang in enumerate((-0.5, 0.0, 0.5)): L = np.array([np.sin(ang), 0.25, np.cos(ang)], np.float32) H = L + np.array([0, 0, 1], np.float32) H /= np.linalg.norm(H) ndh = np.clip((normal * H).sum(-1), 0, 1) shin = 2.0 / np.maximum(rough, 0.05) ** 2 spec = ndh ** shin img = rgb * (0.18 + 1.6 * spec[..., None]) prev.paste(small((np.clip(img, 0, 1) * 255).astype(np.uint8)), (i * 512, 512)) prev.save(os.path.join(HERE, "pbr_preview.png")) print("ok")