A 3D model pipeline, pushed by Gemini 4 Carbon
agent (cont.)
+1:43read_file{"EndLine":400,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":1}
input
{ "EndLine": 400, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 1 }result, 401 lines
Showing lines 1-400 of 1737 1: <meta charset="utf-8"> 2: <title>Lowmarch Model Viewer</title> 3: <meta name="viewport" content="width=device-width, initial-scale=1"> 4: <link rel="preconnect" href="https://fonts.googleapis.com"> 5: <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> 6: <link href="https://fonts.googleapis.com/css2?family=Alegreya+Sans:ital,wght@0,400;0,500;0,700;1,400&family=Pixelify+Sans:wght@500;700&family=Silkscreen&display=swap" rel="stylesheet"> 7: <style> 8: /* Layout: the stage fills the window. Controls float over it in two bars (top: what to show, bottom: 9: turn and camera); notes, display options, pieces and the round's checks live in a side panel that 10: docks on wide screens and slides over the stage on narrow ones. The stage and its bars are a 11: fixed dark "screen"; the panel follows the page theme. */ 12: :root { 13: --bg: #eceef4; --panel: #f7f8fb; --fg: #1d1a2c; --muted: #5d5a73; --line: #d5d7e3; 14: --accent: #3a4ca0; --bad: #a2302a; --ok: #2d6a3e; 15: --screen: #100e18; --screen-2: #191626; --screen-line: #2c2840; --screen-fg: #e9e6f2; --screen-dim: #9c98b5; 16: --screen-on: #2a3366; --screen-on-line: #5a6fc8; --hud: rgba(16, 14, 24, 0.82); --focus: #f0c64a; 17: --f-display: "Pixelify Sans", ui-monospace, "Courier New", monospace; 18: --f-body: "Alegreya Sans", "Gill Sans", "Trebuchet MS", system-ui, sans-serif; 19: --f-label: "Silkscreen", "Pixelify Sans", ui-monospace, monospace; 20: --panel-w: 380px; 21: } 22: @media (prefers-color-scheme: dark) { 23: :root:not([data-theme="light"]) { 24: --bg: #13121b; --panel: #1b1a27; --fg: #e9e8f2; --muted: #a29fba; --line: #2d2b40; 25: --accent: #8fa8f0; --bad: #f08a80; --ok: #8fd6a0; color-scheme: dark; 26: } 27: } 28: :root[data-theme="dark"] { 29: --bg: #13121b; --panel: #1b1a27; --fg: #e9e8f2; --muted: #a29fba; --line: #2d2b40; 30: --accent: #8fa8f0; --bad: #f08a80; --ok: #8fd6a0; color-scheme: dark; 31: } 32: * { box-sizing: border-box; } 33: html, body { height: 100%; margin: 0; } 34: body { background: var(--screen); color: var(--fg); font: 16px/1.5 var(--f-body); overflow: hidden; } 35: button:focus-visible, input:focus-visible, label:focus-within, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; } 36: p { margin: 0; } 37: 38: .app { position: fixed; inset: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; } 39: .view { position: relative; min-width: 0; overflow: hidden; background: var(--screen-2); } 40: .stage { position: absolute; inset: 0; touch-action: none; } 41: .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; } 42: .status[hidden] { display: none; } 43: .status { position: absolute; inset: 0; display: grid; place-items: center; font: 12px/1.4 var(--f-label); letter-spacing: 0.06em; 44: color: var(--screen-dim); text-transform: uppercase; text-align: center; padding: 20px; pointer-events: none; } 45: 46: .hud { position: absolute; left: 0; right: 0; display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; 47: padding: 10px 16px; color: var(--screen-fg); pointer-events: none; } 48: .hud > * { pointer-events: auto; } 49: .hud.top { top: 0; background: linear-gradient(var(--hud), rgba(16, 14, 24, 0.55) 70%, transparent); padding-bottom: 18px; } 50: .hud.bottom { bottom: 0; background: linear-gradient(transparent, rgba(16, 14, 24, 0.55) 30%, var(--hud)); padding-top: 18px; } 51: .brand { display: grid; gap: 0; margin-right: 6px; } 52: .brand .eyebrow { font: 10px/1.3 var(--f-label); letter-spacing: 0.1em; text-transform: uppercase; color: var(--screen-dim); } 53: .brand h1 { font: 700 20px/1.1 var(--f-display); margin: 0; white-space: nowrap; } 54: .btn { 55: font: 11px/1 var(--f-label); letter-spacing: 0.06em; text-transform: uppercase; 56: background: rgba(16, 14, 24, 0.6); color: var(--screen-fg); border: 1px solid var(--screen-line); 57: padding: 8px 10px; border-radius: 3px; cursor: pointer; white-space: nowrap; 58: } 59: .btn:hover { border-color: var(--screen-on-line); } 60: .btn[aria-pressed="true"] { background: var(--screen-on); border-color: var(--screen-on-line); } 61: .btn[disabled] { opacity: 0.4; cursor: default; } 62: .seg { display: inline-flex; } 63: .seg[hidden] { display: none; } 64: select.btn { max-width: 18rem; } /* the grouped character list */ 65: select.btn option, select.btn optgroup { background: var(--screen); color: var(--screen-fg); } 66: .seg .btn { border-radius: 0; margin-left: -1px; } 67: .seg .btn:first-child { border-radius: 3px 0 0 3px; margin-left: 0; } 68: .seg .btn:last-child { border-radius: 0 3px 3px 0; } 69: .grow { flex: 1; } 70: .turn { display: flex; gap: 10px; align-items: center; flex: 1 1 260px; min-width: 0; } 71: .turn input { flex: 1; min-width: 80px; accent-color: var(--screen-on-line); } 72: .turn output { font: 12px/1 var(--f-label); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; } 73: .camhint { font-size: 13px; color: var(--screen-dim); } 74: 75: .panel { width: var(--panel-w); background: var(--panel); color: var(--fg); border-left: 1px solid var(--line); 76: overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px 40px; display: grid; gap: 26px; align-content: start; } 77: .panel[hidden] { display: none; } 78: .panel header { display: flex; justify-content: space-between; align-items: center; gap: 12px; } 79: .panel h2 { font: 700 20px/1.15 var(--f-display); margin: 0; } 80: .panel h3 { font: 11px/1.4 var(--f-label); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; } 81: .panel section { display: grid; gap: 8px; align-content: start; } 82: .panel ul, .panel ol { margin: 0; padding-left: 1.15em; display: grid; gap: 8px; } 83: .panel .close { font: 11px/1 var(--f-label); text-transform: uppercase; letter-spacing: 0.06em; background: none; color: var(--muted); 84: border: 1px solid var(--line); border-radius: 3px; padding: 7px 9px; cursor: pointer; } 85: .opts { display: flex; flex-wrap: wrap; gap: 6px; } 86: .chip { font: 11px/1 var(--f-label); letter-spacing: 0.04em; text-transform: uppercase; display: inline-flex; gap: 6px; 87: align-items: center; padding: 7px 9px; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; user-select: none; } 88: .chip input { accent-color: var(--accent); margin: 0; } 89: .check { font-size: 15px; display: grid; gap: 4px; } 90: .check .sum { font-weight: 700; } 91: .check .sum.bad { color: var(--bad); } 92: .check .sum.ok { color: var(--ok); } 93: .check details { color: var(--muted); font-size: 14px; } 94: .check summary { cursor: pointer; } 95: .sheets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } 96: .sheets a { display: grid; gap: 4px; color: var(--accent); font-size: 14px; text-decoration: none; } 97: .sheets img { width: 100%; height: 120px; object-fit: cover; object-position: top; border: 1px solid var(--line); border-radius: 3px; background: var(--screen); } 98: .muted { color: var(--muted); } 99: .panel footer { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; } 100: 101: @media (max-width: 900px) { 102: .app { grid-template-columns: minmax(0, 1fr); } 103: .panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--panel-w), 100vw); z-index: 5; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.35); } 104: .camhint { display: none; } 105: .brand h1 { font-size: 17px; } 106: .hud { padding-inline: 12px; } 107: } 108: 109: /* compare: who stands where, under their feet; the picker's chips */ 110: .tags { position: absolute; inset: 0; pointer-events: none; overflow: hidden; } 111: .tags span { position: absolute; transform: translateX(-50%); font: 11px/1.25 var(--f-label); letter-spacing: 0.04em; 112: text-transform: uppercase; text-align: center; color: var(--screen-fg); background: rgba(16, 14, 24, 0.72); 113: border: 1px solid var(--screen-line); border-radius: 3px; padding: 4px 6px; max-width: 16rem; } 114: .pick { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; } 115: .pick .btn { display: inline-flex; gap: 6px; align-items: center; } 116: .pick .btn b { font-weight: 400; color: var(--screen-dim); } 117: body.sheet .hud, body.sheet .panel, body.sheet .tags { display: none; } 118: #sheetOut { display: none; } 119: </style> 120: 121: <div class="app"> 122: <div class="view"> 123: <div class="stage" id="stage"><div class="status" id="status">Loading the models…</div></div> 124: <div class="tags" id="tags" aria-hidden="true"></div> 125: <header class="hud top"> 126: <div class="brand"><span class="eyebrow">Lowmarch · Model viewer</span><h1>Lowmarch cast</h1></div> 127: <span class="seg" role="group" aria-label="View"> 128: <button class="btn" type="button" data-view="duel" aria-pressed="true">Duel</button> 129: <button class="btn" type="button" data-view="battle" aria-pressed="false">Battle</button> 130: <button class="btn" type="button" data-view="bust" aria-pressed="false">Portrait</button> 131: <button class="btn" type="button" data-view="lineup" aria-pressed="false" id="lineupBtn">Lineup</button> 132: <button class="btn" type="button" data-view="compare" aria-pressed="false" id="compareBtn" hidden>Compare</button> 133: </span> 134: <span class="seg" id="who" role="group" aria-label="Character"></span> 135: <span class="seg" role="group" aria-label="Pose" id="poseSeg" hidden> 136: <button class="btn" type="button" data-pose="up" aria-pressed="false">Arms up</button> 137: <button class="btn" type="button" data-pose="out" aria-pressed="true">Arms out</button> 138: <button class="btn" type="button" data-pose="down" aria-pressed="false">Arms down</button> 139: </span> 140: <select class="btn" id="skinSel" aria-label="Skin tone" hidden></select> 141: <span class="seg" role="group" aria-label="Motion" id="motionSeg" hidden> 142: <button class="btn" type="button" data-motion="still" aria-pressed="true">Still</button> 143: <button class="btn" type="button" data-motion="bounce" aria-pressed="false">Bounce</button> 144: <button class="btn" type="button" data-motion="twist" aria-pressed="false">Twist</button> 145: </span> 146: <span class="seg" role="group" aria-label="Animation" id="clipSeg"> 147: <button class="btn" type="button" data-clip="clash" aria-pressed="true">Clash</button> 148: <button class="btn" type="button" data-clip="idle" aria-pressed="false">Idle</button> 149: <button class="btn" type="button" data-clip="attack" aria-pressed="false">Attack</button> 150: <button class="btn" type="button" data-clip="apose" aria-pressed="false">Arms out</button> 151: </span> 152: <span class="seg" role="group" aria-label="Renderer"> 153: <button class="btn" type="button" data-mode="painted" aria-pressed="true">Painted</button> 154: <button class="btn" type="button" data-mode="3d" aria-pressed="false">3D</button> 155: </span> 156: <span class="grow"></span> 157: <button class="btn" type="button" id="panelBtn" aria-controls="panel" aria-expanded="false">Notes & options</button> 158: </header> 159: <footer class="hud bottom"> 160: <div class="turn"> 161: <button class="btn" type="button" id="play" aria-pressed="false">Turn</button> 162: <input type="range" id="yaw" min="0" max="359" step="1" value="0" aria-label="Turn angle"> 163: <output id="yawOut" for="yaw">0°</output> 164: </div> 165: <button class="btn" type="button" id="reset">Reset camera</button> 166: <span class="camhint" id="camHint">Drag to orbit · right-drag to pan · scroll to zoom · double-click a spot to orbit round it</span> 167: </footer> 168: </div> 169: 170: <aside class="panel" id="panel" hidden aria-label="Notes and options"> 171: <header><h2>This round</h2><button class="close" type="button" id="panelClose">Close</button></header> 172: <section> 173: <ul> 174: <li><b>Test: MakeHuman bodies with VRoid heads</b> (the first three in <b>Lineup</b>, labelled "MH", next to the VRoid soldier on the far left). Same soldier kit. The bodies come from MakeHuman's CC0 shape controls (a slim young soldier, a stocky 50-year-old, a huge brute); the head is VRoid's CC0 male head, with its anime eyes, expressions and hair, scaled to each body and set on its neck the way VRoid does it (the neck runs up inside the head). Faces vary through our face presets. Sleeves: the puffs are now sized to the arm's real thickness (they were buried in MakeHuman's thicker arms, which is what looked like muscle), and on these bodies cloth spans the hollows between muscles.</li> 175: <li><b>Common enemies.</b> Press <b>Lineup</b> to see ten generic units in the enemy army's crimson, after a study of Unicorn Overlord's generic classes: 176: <ul> 177: <li><b>Soldier:</b> kettle hat, army-colour doublet with puffed sleeves, breastplate with plackart, a fauld of round scales, big leather cuffs, halberd.</li> 178: <li><b>Fighter:</b> kettle hat worn low, quilted gambeson, breastplate, spaulders, knife-pleated skirt, greaves, wooden round shield, sword.</li> 179: <li><b>Housecarl:</b> nasal helm over a mail coif, mail hauberk over the gambeson, short cape, wide belt, long axe.</li> 180: <li><b>Hoplite:</b> close helm with eye slit and breaths, coat of plates over mail, spaulders, a puffed capelet, a big steel shield with the army's device, spear.</li> 181: <li><b>Berserker</b> (huge, bare-armed, fur capelet, great axe), <b>hunter</b> (hood, cape, bow, quiver), <b>witch</b> (robe, pointed hat, staff) and a masked <b>thief</b>.</li> 182: </ul></li> 183: <li><b>Builds and faces vary.</b> The soldier's kit is also worn by a stocky grey veteran and a slim woman. Builds run from petite (the thief, 1.4 m) to huge (the berserker), with a new overall height control and oversized hands, as the study's units have. Faces differ in shape (jaw, chin, brow, nose, cheeks), expression, hair and eye colour, skin tone, and beards and moustaches. The lineup's check sheet has rows of faces with helmets off and on.</li> 184: <li><b>Gear kit:</b> helmets drawn on the skull chart, coifs and hoods, quilted coats, mail and scale textures, coats of plates, breastplates, puffed sleeves, pleated skirts, flared cuffs, heater, round and tower shields, spears, a halberd, axes, a bow, a dagger, a staff, robes and a witch's hat.</li> 185: <li><b>Hair:</b> Elaine's side-swept bangs and the nape and temple fixes from last round. Next for hair: studying how VRoid's sample hair is built, since you prefer it to the kit's.</li> 186: </ul> 187: </section> 188: <section> 189: <h3>Checks this build</h3> 190: <div id="checks" class="muted">Loading…</div> 191: </section> 192: <section> 193: <h3>Check sheets</h3> 194: <p class="muted">What I looked at: every view and pose, rendered by this page.</p> 195: <div class="sheets" id="sheets"></div> 196: </section> 197: <section> 198: <h3>Display</h3> 199: <div class="opts"> 200: <button class="btn" type="button" id="cloth" aria-pressed="true">Cloth physics</button> 201: <button class="btn" type="button" id="physics" aria-pressed="true">Spring bones</button> 202: <button class="btn" type="button" id="wind" aria-pressed="false">Wind</button> 203: <button class="btn" type="button" id="resetCloth">Drop cloth</button> 204: <button class="btn" type="button" id="stepped" aria-pressed="false">12 fps</button> 205: <button class="btn" type="button" id="shade" aria-pressed="true">3D: toon</button> 206: <button class="btn" type="button" id="xray" aria-pressed="false">X-ray costume</button> 207: </div> 208: </section> 209: <section> 210: <h3>Pieces</h3> 211: <div class="opts" id="parts" aria-label="Pieces to show"></div> 212: </section> 213: <footer>Lowmarch, 8 October 2026. Base bodies: VRoid's CC0 sample models. Aldric's hair is from a VRoid Hub sample (commercial use and modification allowed). Costumes, swords, terrain, renderer and cloth are ours. Unicorn Overlord is Vanillaware's and Saber is Type-Moon's; we study their look, and no image of either is used here. The Saber study is built from written measurements of her design, to benchmark the armour kit; it is not part of the game.</footer> 214: </aside> 215: </div> 216: <textarea id="sheetOut" aria-hidden="true"></textarea> 217: 218: <script type="importmap"> 219: { "imports": { "three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js", 220: "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.160.0/examples/jsm/" } } 221: </script> 222: <script type="module"> 223: import * as THREE from "three"; 224: import { OrbitControls } from "three/addons/controls/OrbitControls.js"; 225: import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js"; 226: 227: const $ = id => document.getElementById(id); 228: const statusEl = $("status"); 229: const params = new URLSearchParams(location.search); 230: const SHEET = params.get("sheet"); // a character's name, or "duel": render a check sheet 231: let CAM; 232: try { CAM = await (await fetch("camera.json")).json(); } 233: catch (e) { statusEl.textContent = "Couldn't load camera.json. Open this page from its published link."; throw e; } 234: 235: const GROUP_LABELS = { body: "Body", hair: "Hair", tunic: "Tunic", tails: "Tails", belt: "Belt", trousers: "Trousers / tights", 236: boots: "Boots", gloves: "Gloves", collar: "Collar", pauldron: "Shoulder plates", cape: "Cape", trim: "Gold trim", 237: doublet: "Doublet", plate: "Plate", tabard: "Tabard", mantle: "Mantle", shield: "Shield", dress: "Dress", 238: sword: "Sword", weapon: "Weapon", helmet: "Helmet", hood: "Hood", padding: "Padded coat", mail: "Mail", 239: terrain: "Ground" }; 240: const COSTUME = new Set(["tunic", "tails", "belt", "trousers", "boots", "gloves", "collar", "pauldron", "cape", "trim", 241: "doublet", "plate", "tabard", "mantle", "shield", "dress", "helmet", "hood", "padding", "mail"]); 242: // role ids for the info pass (features 4-9 get no inner lines; hair 3 and 11 shade the forehead) 243: const ROLE_ID = { face: 1, body: 2, hair: 3, line: 4, iris: 5, white: 6, highlight: 7, brow: 8, mouth: 9, cloth: 10, hair_b: 11 }; 244: let nextRole = 12; 245: const roleId = r => (ROLE_ID[r] ??= nextRole++); 246: const VIEW_YAW = { duel: 0, battle: 60, bust: 30, lineup: 20, compare: 0 }; 247: const state = { view: "duel", who: CAM.characters[0].name, yaw: 0, mode: "painted", skin: "", toon: true, xray: false, hidden: new Set(), 248: cloth: true, wind: false, playing: false, stepped: false, clip: "clash", pose: "out", compare: [], motion: "still", 249: physics: true }; 250: const charDef = name => CAM.characters.find(c => c.name === name); 251: // a workshop page (camera.json "page"): its own title and notes, and no duel 252: const PAGE = CAM.page || null; 253: const NO_DUEL = PAGE?.duel === false; 254: if (PAGE) { 255: document.title = `${PAGE.title} · Lowmarch`; 256: document.querySelector(".brand .eyebrow").textContent = PAGE.eyebrow || "Lowmarch"; 257: document.querySelector(".brand h1").textContent = PAGE.title; 258: if (PAGE.notes) document.querySelector("#panel section ul").innerHTML = PAGE.notes; 259: } 260: // the armory: bodies compared side by side (the Compare view) in three poses, instead of clips and a lineup 261: const ARMORY_PAGE = !!PAGE?.armory; 262: const MAX_COMPARE = 6; 263: if (ARMORY_PAGE) { 264: $("compareBtn").hidden = false; $("poseSeg").hidden = false; $("clipSeg").hidden = true; $("lineupBtn").hidden = true; 265: $("motionSeg").hidden = false; 266: if (PAGE.skins && PAGE.skins.length) { // skin picker: try any tone of the range on the bodies shown 267: const sel = $("skinSel"); 268: sel.append(new Option("Skin: as built", "")); 269: for (const g of [...new Set(PAGE.skins.map(s => s.group))]) { 270: const og = document.createElement("optgroup"); og.label = g; 271: PAGE.skins.filter(s => s.group === g).forEach(s => og.append(new Option(s.label, s.name))); 272: sel.append(og); 273: } 274: if (PAGE.skins.some(s => s.name === params.get("skin"))) state.skin = params.get("skin"); // ?skin=<tone> 275: sel.value = state.skin || ""; 276: sel.hidden = false; 277: sel.addEventListener("change", () => { state.skin = sel.value; }); 278: } 279: if (["still", "bounce", "twist"].includes(params.get("motion"))) state.motion = params.get("motion"); 280: state.compare = (params.get("compare") || "").split(",").filter(n => charDef(n)).slice(0, MAX_COMPARE); 281: if (!state.compare.length) state.compare = CAM.characters.slice(0, 2).map(c => c.name); 282: if (["up", "out", "down"].includes(params.get("pose"))) state.pose = params.get("pose"); 283: } 284: if (NO_DUEL) { 285: document.querySelector('[data-view="duel"]').hidden = true; 286: document.querySelector('[data-clip="clash"]').hidden = true; 287: state.clip = "idle"; 288: } 289: 290: const hex = h => { // raw palette value, no colour-space conversion 291: const n = parseInt(h.slice(1), 16); 292: return new THREE.Color().setRGB((n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255, THREE.LinearSRGBColorSpace); 293: }; 294: const rawTex = t => { if (!t) return null; const c = t.clone(); c.colorSpace = THREE.NoColorSpace; c.needsUpdate = true; return c; }; 295: const gradient = (() => { 296: const d = new Uint8Array([70, 70, 70, 255, 140, 140, 140, 255, 205, 205, 205, 255, 255, 255, 255, 255]); 297: const t = new THREE.DataTexture(d, 4, 1, THREE.RGBAFormat); t.minFilter = t.magFilter = THREE.NearestFilter; t.needsUpdate = true; return t; 298: })(); 299: const white = (() => { const t = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1, THREE.RGBAFormat); t.needsUpdate = true; return t; })(); 300: 301: // ---- scene and camera ----------------------------------------------------------------------------------------------- 302: const scene = new THREE.Scene(); 303: const hemi = new THREE.HemisphereLight(0xfff6ee, 0x3a3450, 1.35); 304: const sun = new THREE.DirectionalLight(0xffffff, 1.6); 305: scene.add(hemi, sun); 306: const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40); 307: 308: // ---- shaders -------------------------------------------------------------------------------------------------------- 309: const SKIN_HEAD = `#include <common> 310: #include <skinning_pars_vertex>`; 311: const SKIN_BODY = `#include <beginnormal_vertex> 312: #include <skinbase_vertex> 313: #include <skinnormal_vertex> 314: #include <begin_vertex> 315: #include <skinning_vertex>`; 316: const PAINT_VS = `${SKIN_HEAD} 317: attribute float edge; attribute vec4 _plate; uniform float uLift; 318: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; 319: void main() { 320: ${SKIN_BODY} 321: vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate; 322: vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz; 323: mv.z += uLift; // brows: drawn over the bangs (depth lift toward the camera) 324: gl_Position = projectionMatrix * mv; 325: }`; 326: const HSV = ` 327: vec3 rgb2hsv(vec3 c) { 328: vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); 329: vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); 330: vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); 331: float d = q.x - min(q.w, q.y); 332: return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 1e-10)), d / (q.x + 1e-10), q.x); 333: } 334: vec3 hsv2rgb(vec3 c) { 335: vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 336: vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 337: return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 338: }`; 339: // painted renderer, after the Unicorn Overlord study: tight terminators, hue-shifted ramps built from 340: // one base colour per material, hard reflection bands on steel, strand highlights on hair, a stage 341: // grade and a back rim 342: const PAINT_FS = ` 343: uniform int uKind; uniform vec3 uBase; uniform vec3 uKey; uniform sampler2D uMap; uniform int uAlpha; 344: uniform int uPass; uniform vec4 uInfo; uniform vec3 uEye[3]; uniform vec3 uFlat; uniform vec3 uSkinRef; 345: uniform vec3 uGold; uniform vec3 uAmbient; uniform vec3 uKeyCol; uniform vec3 uRimCol; uniform float uGrain; 346: uniform int uFaceTex; uniform int uDecal; uniform vec3 uMotif; uniform vec3 uBand; uniform vec3 uSkinTone; uniform int uShadeOnly; 347: uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC; 348: uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn; 349: uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm; 350: // Cast shadows on skin, in screen space (the "depth offset" shadows of anime toon shaders): walk from this pixel 351: // toward the key light across the info pass already drawn; if the face (the jaw) or hair stands in front of that 352: // ray, this pixel is in its shadow. The shape is the caster's own outline as the camera sees it, at any angle. 353: float castShadow() { 354: vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes; 355: float z0 = uCastNear + texture2D(tCastDepth, uv).x * (uCastFar - uCastNear); 356: float sxy = length(uKey.xy); 357: if (sxy < 0.05) return 0.0; 358: vec2 dir = uKey.xy / sxy; 359: float lz = uKey.z / sxy; // the ray's rise toward the camera per metre across 360: for (int s = 1; s <= 14; s++) { 361: float dm = float(s) * 0.003; // 3 mm steps across the screen, up to 4.2 cm 362: vec2 q = uv + dir * dm * uCastPpm * px; 363: vec4 ni = texture2D(tCastInfo, q); 364: if (ni.a < 0.5) continue; 365: int r = int(ni.r * 255.0 + 0.5); 366: if (r != 1 && r != 3 && r != 11) continue; // casters: the face (jaw, chin) and hair 367: float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear); 368: float zr = z0 - lz * dm; 369: if (zq < zr - 0.004 && zq > zr - 0.20) return 1.0; 370: } 371: return 0.0; 372: } 373: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; 374: ${HSV} 375: float hash(vec3 p) { p = fract(p * 0.3183099 + 0.1); p *= 17.0; return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); } 376: float vnoise(vec3 x) { 377: vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f); 378: return mix(mix(mix(hash(i), hash(i + vec3(1,0,0)), f.x), mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y), 379: mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x), mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y), f.z); 380: } 381: float toward(float h, float target, float amt) { float d = target - h; d -= floor(d + 0.5); return fract(h + clamp(d, -amt, amt)); } 382: vec3 tone(vec3 base, float hue, float amt, float sMul, float vMul) { 383: vec3 h = rgb2hsv(base); 384: return hsv2rgb(vec3(toward(h.x, hue, amt), clamp(h.y * sMul, 0.0, 1.0), clamp(h.z * vMul, 0.0, 1.0))); 385: } 386: float st(float x, float t) { return smoothstep(t - 0.03, t + 0.03, x); } 387: // Steel and gold. Hard reflection bands (dark below the horizon, a dark core under a white streak) 388: // read well where the surface turns fast: rims, tubes, lames. On a broad plate the reflection 389: // barely changes, so a band there fills the whole plate (the blotches): bands fade by how sharply 390: // the surface curves (normal change per metre on screen), and broad plates get a soft tone that 391: // lightens up each outline plate (hgt: height in the plate 0..1, or -1 without plate data). 392: vec3 metal(bool gold, vec3 base, vec3 n, vec3 v, float lit, float hgt) { 393: vec3 r = reflect(-v, n); 394: float ry = r.y + (vnoise(vObj * vec3(3.0, 14.0, 3.0)) - 0.5) * 0.14; // jitter the bands along their length, not into blobs 395: float curv = length(fwidth(n)) / max(length(fwidth(vView)), 1e-5); 396: float sharp = smoothstep(5.0, 14.0, curv); 397: // a shaped plate's domes (over the bust, a crowned panel) turn the bands into closed rings: plates 398: // keep only a little of them and take a crisp highlight toward the light instead 399: if (hgt >= 0.0) sharp *= 0.25; else sharp = max(sharp, 0.3);1 more lines not shown.