A 3D model pipeline, pushed by Gemini 4 Argon
agent (cont.)
+55:38read_file{"EndLine":280,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":160}
input
{ "EndLine": 280, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 160 }result, 122 lines
Showing lines 160-280 of 1807 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);read_file{"EndLine":880,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":740}
input
{ "EndLine": 880, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 740 }result, 142 lines
Showing lines 740-880 of 1807 740: if (this.closed) { 741: _A.set(_v.x - axis.x, 0, _v.z - axis.z); // outward, horizontally 742: _B.set(_v.x - _cp.x, 0, _v.z - _cp.z); 743: if (_A.lengthSq() > 1e-8 && _B.dot(_A) < 0) { // the nearest way out is inward: go round 744: _A.normalize(); _v.set(_cp.x + _A.x * c.r, _v.y, _cp.z + _A.z * c.r); jumped = true; continue; 745: } 746: } 747: _v.sub(_cp).multiplyScalar(c.r / d).add(_cp); 748: } 749: } 750: // inelastic contact: most of a push-out doesn't turn into velocity, so a limb moving into the 751: // cloth carries it instead of flinging it 752: const px = _v.x - x[3*k], py = _v.y - x[3*k+1], pz = _v.z - x[3*k+2]; 753: if (jumped) { pv[3*k] = _v.x; pv[3*k+1] = _v.y; pv[3*k+2] = _v.z; } // a jump round a leg carries no speed 754: else if (px * px + py * py + pz * pz > 1e-12) { 755: pv[3*k] += px * 0.8; pv[3*k+1] += py * 0.8; pv[3*k+2] += pz * 0.8; 756: touch[k] = 1; 757: } 758: x[3*k] = _v.x; x[3*k+1] = _v.y; x[3*k+2] = _v.z; 759: } 760: } 761: // friction, once per step: cloth touching a limb keeps 40% of its speed, so a stepping knee 762: // carries a skirt forward instead of the fabric sliding off round the leg 763: for (let k = 0; k < this.n; k++) if (touch[k]) for (let c = 0; c < 3; c++) { const i = 3*k + c; pv[i] = x[i] - (x[i] - pv[i]) * 0.4; } 764: } 765: write() { 766: const p = this.display.geometry.attributes.position; 767: p.array.set(this.x); p.needsUpdate = true; 768: this.display.geometry.computeVertexNormals(); this.display.geometry.computeBoundingSphere(); 769: const pts = [], idx = (i, j) => i * this.V + j, X = this.x; 770: const seg = (a, b) => pts.push(X[3*a], X[3*a+1], X[3*a+2], X[3*b], X[3*b+1], X[3*b+2]); 771: const U = this.U, last = this.closed ? U : U - 1; 772: for (let i = 0; i < last; i++) { if (!this.hemOnly) seg(idx(i, 0), idx((i + 1) % U, 0)); seg(idx(i, this.V - 1), idx((i + 1) % U, this.V - 1)); } 773: if (this.trims.length > 1 && !this.closed) for (let j = 0; j + 1 < this.V; j++) { seg(idx(0, j), idx(0, j + 1)); seg(idx(this.U - 1, j), idx(this.U - 1, j + 1)); } 774: const g = this.lines.geometry; 775: g.setAttribute("position", new THREE.Float32BufferAttribute(pts, 3)); g.computeBoundingSphere(); 776: } 777: } 778: 779: // A long skirt is posed, not simulated: each column hangs from its waist point at its rest shape; 780: // anything that would sit inside a leg is pushed straight out along its column, and everything below 781: // a contact hangs from it, so the skirt tents over a stepping knee. Column lengths are kept (the hem 782: // rises as it tents) and the pushes are smoothed round the skirt and over time. A free cloth tube 783: // against moving leg colliders slid off the knee, jumped round the legs or drifted, whatever the 784: // friction; this can't end up between the legs. 785: class SkirtRig extends Cloth { 786: constructor(skinned, U, V, trims, capsules, bone, closed = true, hemOnly = false) { 787: super(skinned, U, V, trims, capsules, bone, closed, hemOnly); 788: this.hip = bone("J_Bip_C_Hips"); 789: const src = skinned.geometry.attributes.position, idx = (i, j) => i * V + j; 790: const P = k => new THREE.Vector3(src.getX(k), src.getY(k), src.getZ(k)); 791: const C = new THREE.Vector3(); 792: if (closed) { for (let i = 0; i < U; i++) C.add(P(idx(i, 0))); C.multiplyScalar(1 / U); } 793: else if (this.hip) { this.hip.getWorldPosition(C); skinned.worldToLocal(C); } 794: this.r0 = new Float32Array(U * V); this.h0 = new Float32Array(U * V); this.t0 = new Float32Array(U * V); 795: this.push = new Float32Array(U * V); 796: for (let i = 0; i < U; i++) { 797: const W = P(idx(i, 0)), d = new THREE.Vector3(W.x - C.x, 0, W.z - C.z).normalize(), t = new THREE.Vector3(-d.z, 0, d.x); 798: for (let j = 0; j < V; j++) { 799: const o = P(idx(i, j)).sub(W); 800: this.r0[idx(i, j)] = o.dot(d); this.h0[idx(i, j)] = o.y; this.t0[idx(i, j)] = o.dot(t); 801: } 802: } 803: } 804: pose(dt, instant) { 805: const U = this.U, V = this.V, X = this.x, idx = (i, j) => i * V + j; 806: const W = [], C = new THREE.Vector3(); 807: for (let i = 0; i < U; i++) { W.push(this.rest(idx(i, 0), new THREE.Vector3())); C.add(W[i]); } 808: if (this.closed || !this.hip) C.multiplyScalar(1 / U); 809: else this.hip.getWorldPosition(C); 810: const caps = this.caps.map(c => ({ a: c.a.getWorldPosition(new THREE.Vector3()), b: c.b.getWorldPosition(new THREE.Vector3()), r: c.r + 0.012 })); 811: const target = new Float32Array(U * V), p = new THREE.Vector3(), cp = new THREE.Vector3(), ab = new THREE.Vector3(), ap = new THREE.Vector3(); 812: for (let i = 0; i < U; i++) { 813: const d = new THREE.Vector3(W[i].x - C.x, 0, W[i].z - C.z).normalize(), t = new THREE.Vector3(-d.z, 0, d.x); 814: let carry = 0; 815: for (let j = 1; j < V; j++) { 816: const k = idx(i, j); 817: let need = carry; // below a contact the cloth hangs from it 818: for (let it = 0; it < 6; it++) { 819: p.copy(W[i]).addScaledVector(d, this.r0[k] + need).addScaledVector(t, this.t0[k]); p.y += this.h0[k]; 820: let worst = 0; 821: for (const c of caps) { 822: ab.subVectors(c.b, c.a); const tt = THREE.MathUtils.clamp(ap.subVectors(p, c.a).dot(ab) / ab.lengthSq(), 0, 1); 823: cp.copy(c.a).addScaledVector(ab, tt); 824: const dx = p.x - cp.x, dz = p.z - cp.z, dist = Math.hypot(dx, p.y - cp.y, dz); 825: if (dist < c.r) worst = Math.max(worst, c.r - dist); 826: } 827: if (worst < 1e-4) break; 828: need += worst * 1.15; 829: } 830: target[k] = carry = need; 831: } 832: } 833: for (let pass = 0; pass < 2; pass++) // smooth round the skirt 834: for (let j = 1; j < V; j++) { 835: const row = []; 836: for (let i = 0; i < U; i++) { 837: const i0 = this.closed ? (i + U - 1) % U : Math.max(0, i - 1); 838: const i1 = this.closed ? (i + 1) % U : Math.min(U - 1, i + 1); 839: row.push((target[idx(i0, j)] + 2 * target[idx(i, j)] + target[idx(i1, j)]) / 4); 840: } 841: for (let i = 0; i < U; i++) target[idx(i, j)] = Math.max(row[i], target[idx(i, j)] * 0.6); 842: } 843: const ease = instant ? 1 : Math.min(1, dt * 9); 844: for (let k = 0; k < U * V; k++) this.push[k] += (target[k] - this.push[k]) * ease; 845: for (let i = 0; i < U; i++) { 846: const d = new THREE.Vector3(W[i].x - C.x, 0, W[i].z - C.z).normalize(), t = new THREE.Vector3(-d.z, 0, d.x); 847: let prev = W[i].clone(), pr = 0, ph = 0, pt = 0; 848: X[3 * idx(i, 0)] = prev.x; X[3 * idx(i, 0) + 1] = prev.y; X[3 * idx(i, 0) + 2] = prev.z; 849: for (let j = 1; j < V; j++) { 850: const k = idx(i, j), r = this.r0[k] + this.push[k], h0 = this.h0[k], tt = this.t0[k]; 851: // keep the rest length of this segment: what the push adds outward comes off the drop 852: const L = Math.hypot(this.r0[k] - this.r0[k - 1], h0 - this.h0[k - 1], tt - this.t0[k - 1]); 853: const dr = r - pr, dtan = tt - pt, dh = -Math.sqrt(Math.max(L * L - dr * dr - dtan * dtan, 1e-6)); 854: const h = ph + (j === 1 ? Math.min(dh, h0) : dh); 855: const q = W[i].clone().addScaledVector(d, r).addScaledVector(t, tt); q.y += h; 856: X[3 * k] = q.x; X[3 * k + 1] = q.y; X[3 * k + 2] = q.z; 857: pr = r; ph = h; pt = tt; 858: } 859: } 860: this.prev.set(X); 861: } 862: reset() { this.push.fill(0); this.pose(0, true); } 863: step(dt) { this.pose(dt, false); } 864: } 865: 866: // ---- materials per mesh ---------------------------------------------------------------------------------------------- 867: const KEY = new THREE.Vector3(-0.45, 0.55, 0.70).normalize(); 868: // stage grades: ambient multiply, key colour, back rim (characters and stage share them) 869: const GRADE = { battle: { ambient: [0.84, 0.87, 0.98], key: [1.05, 1.0, 0.92], rim: [0.38, 0.34, 0.26] }, 870: bust: { ambient: [0.90, 0.90, 0.98], key: [1.03, 1.0, 0.96], rim: [0.24, 0.24, 0.34] } }; 871: // Brows draw over the bangs: they are lifted this far (m) toward the camera, more than the bangs stand off the 872: // forehead and much less than the head is deep, so a brow still hides behind the skull when the head turns away. 873: const BROW_LIFT = 0.04; 874: const KIND = { cloth: 0, skin: 1, hair: 2, steel: 3, gold: 4, leather: 5, world: 6 }; 875: function paintMaterial(V, role, map, index, infoRole = role, decal = false) { 876: const Rl = V.roles[role] || { mode: "flat", color: "#ff00ff" }, P = (V.paint || {})[role]; 877: const u = { uKind: { value: 9 }, uBase: { value: new THREE.Color(0.8, 0.8, 0.8) }, uKey: { value: KEY.clone() }, 878: uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 }, 879: uInfo: { value: new THREE.Vector4(roleId(infoRole) / 255, (index % 256) / 255, Math.floor(index / 256) / 255, 1) }, 880: uEye: { value: V.roles.iris.colors.map(hex) }, uFlat: { value: new THREE.Color() }, uSkinRef: { value: new THREE.Vector3(0.965, 0.878, 0.80) },read_file{"EndLine":1060,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":881}
input
{ "EndLine": 1060, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 881 }result, 181 lines
Showing lines 881-1060 of 1807 881: uGold: { value: hex((V.paint && V.paint.gold && V.paint.gold.base) || "#b08b3f") }, 882: uAmbient: { value: new THREE.Vector3(1, 1, 1) }, uKeyCol: { value: new THREE.Vector3(1, 1, 1) }, uRimCol: { value: new THREE.Vector3() }, 883: uGrain: { value: 0.05 }, uFaceTex: { value: 0 }, uDecal: { value: decal ? 1 : 0 }, uBand: { value: null }, 884: uSkinTone: { value: new THREE.Vector3(1, 1, 1) }, uShadeOnly: { value: 0 }, 885: uSkinRamp: { value: 0 }, uSkinL: { value: new THREE.Color() }, uSkinS: { value: new THREE.Color() }, uSkinC: { value: new THREE.Color() }, 886: tCastInfo: { value: null }, tCastDepth: { value: null }, uCastRes: { value: new THREE.Vector2(1, 1) }, uCastOn: { value: 0 }, 887: uCastNear: { value: 0.1 }, uCastFar: { value: 40 }, uCastPpm: { value: 1 }, 888: uMotif: { value: hex((V.paint && V.paint.motif && V.paint.motif.base) || "#3a44a0") }, uLift: { value: 0 } }; 889: if (P) { u.uKind.value = KIND[P.kind] ?? 0; if (P.base) u.uBase.value = hex(P.base); if (P.grain != null) u.uGrain.value = P.grain; } 890: else if (Rl.bands) { u.uKind.value = Rl.world ? 6 : 0; u.uBase.value = hex(Rl.bands[Math.min(1, Rl.bands.length - 1)][1]); } 891: if (P && P.kind === "world") { u.uKey.value = new THREE.Vector3(...V.sun); u.uGrain.value = 0.12; } 892: if (P && P.shade) u.uShadeOnly.value = 1; // shadow cards: skin, always in its shade tone 893: if (P && P.kind === "skin" && P.ramp) { // a designed ramp: lit, shade, deep shade 894: u.uSkinRamp.value = 1; u.uSkinL.value = hex(P.ramp[0]); u.uSkinS.value = hex(P.ramp[1]); u.uSkinC.value = hex(P.ramp[2]); 895: } 896: if (P && P.kind === "skin" && P.base) { // skin tone: the base colour against the default light skin 897: const c = hex(P.base); u.uSkinTone.value.set(c.r / 0.973, c.g / 0.882, c.b / 0.835); 898: } 899: if (role === "face" && map) u.uFaceTex.value = 1; 900: if (role === "hair" && map) u.uAlpha.value = 1; 901: if (role === "iris") { u.uKind.value = 7; u.uAlpha.value = 1; } 902: else if (role === "white" || role === "highlight") { u.uKind.value = map ? 8 : 9; if (map) u.uAlpha.value = 1; u.uFlat.value = hex(Rl.color || "#ffffff"); } 903: else if (!P && Rl.mode === "flat") { u.uKind.value = 9; u.uFlat.value = hex(Rl.color); if (map) u.uAlpha.value = role === "line" ? 2 : 1; } 904: if (role === "brow") u.uLift.value = BROW_LIFT; 905: if (role === "mouth" && map) u.uKind.value = 10; 906: u.uBand.value = u.uGold.value.clone(); 907: const m = new THREE.ShaderMaterial({ uniforms: u, vertexShader: PAINT_VS, fragmentShader: PAINT_FS, side: THREE.DoubleSide, 908: extensions: { derivatives: true } }); 909: // meshes without plate data or a cloth edge read zeros, not whatever another program left in that slot 910: m.defaultAttributeValues = { ...m.defaultAttributeValues, _plate: [0, 0, 0, 0], edge: [0] }; 911: return m; 912: } 913: 914: // ---- models ------------------------------------------------------------------------------------------------------ 915: const loader = new GLTFLoader(); 916: const chars = new Map(); // name -> loaded character 917: let ground = null; 918: const stage = new THREE.Group(); // the duel: both fighters stand on it; the turn slider rotates it 919: scene.add(stage); 920: // the lineup: every enemy model standing in a row (camera.json's lineup), each turning in place 921: const LINEUP = CAM.lineup || { order: [], spacing: 0.9 }; 922: const ROW_VIEW = () => state.view === "lineup" || state.view === "compare"; // several models in a row, each turning in place 923: const CAM_VIEW = () => state.view === "duel" || ROW_VIEW() ? CAM.duel.cam : charDef(state.who).cams[state.view]; 924: const activeNames = () => state.view === "duel" ? [CAM.duel.order.player, CAM.duel.order.opponent] 925: : state.view === "lineup" ? LINEUP.order : state.view === "compare" ? state.compare : [state.who]; 926: const active = () => activeNames().map(n => chars.get(n)).filter(Boolean); 927: 928: async function parseGlb(file) { 929: const j = await (await fetch(file)).json(); 930: const bin = Uint8Array.from(atob(j.glb), c => c.charCodeAt(0)); 931: return await new Promise((ok, bad) => loader.parse(bin.buffer, "", ok, bad)); 932: } 933: let meshIndex = 1; 934: function prepMesh(o, V, opts = {}) { 935: const m0 = o.material, role = o.userData.role || "body", raw = rawTex(m0.map); 936: const infoRole = role === "hair" && opts.hairB ? "hair_b" : role === "shadow" ? "body" : role; 937: const decal = !!(m0.userData && m0.userData.decal); // the map is a design mask, not a colour 938: const base = { map: decal ? null : (m0.map || null), color: m0.color.clone(), side: THREE.DoubleSide, alphaTest: m0.alphaTest || 0 }; 939: const clay = new THREE.MeshStandardMaterial({ ...base, roughness: 0.85, metalness: m0.metalness || 0 }); 940: const toon = new THREE.MeshToonMaterial({ ...base, gradientMap: gradient }); 941: if (role === "hair" && m0.map && V.paint && V.paint.hair) { 942: // the VRoid sample's hair texture carries its own colour (dark on some samples): in 3D use the 943: // character's hair colour, with the texture's light and dark only for strand detail 944: for (const m of [clay, toon]) { 945: m.color = hex(V.paint.hair.base); 946: m.onBeforeCompile = sh => { sh.fragmentShader = sh.fragmentShader.replace("#include <map_fragment>", 947: `#ifdef USE_MAP 948: vec4 texel_ = texture2D(map, vMapUv); 949: diffuseColor.rgb *= mix(1.0, clamp(dot(texel_.rgb, vec3(0.3333)) / 0.5, 0.45, 1.35), 0.6); 950: diffuseColor.a *= texel_.a; 951: #endif`); }; 952: m.customProgramCacheKey = () => "hairlum"; 953: } 954: } 955: o.userData.mats = { clay, toon, painted: paintMaterial(V, role, raw, meshIndex, infoRole, decal) }; 956: meshIndex++; 957: o.userData.group = o.userData.group || "body"; 958: o.userData.role = role; 959: o.frustumCulled = false; 960: } 961: 962: async function loadCharacter(name) { 963: if (chars.has(name)) return chars.get(name); 964: const def = charDef(name), V = def.info, ci = CAM.characters.indexOf(def); 965: const gltf = await parseGlb(`${name}.glb.json`); 966: const turn = new THREE.Group(), holder = new THREE.Group(); 967: turn.add(holder); holder.add(gltf.scene); 968: const meshes = []; 969: gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V, { hairB: ci > 0 }); meshes.push(o); } }); 970: gltf.scene.updateMatrixWorld(true); 971: const bone = n => gltf.scene.getObjectByName(n); 972: const cloths = [], world = new THREE.Group(); 973: for (const [cname, info] of Object.entries(V.cloth || {})) { 974: const skinned = meshes.find(m => m.userData.material === cname); 975: if (!skinned) continue; 976: const trims = meshes.filter(m => info.trims.includes(m.userData.material)); 977: const caps = V.capsules.filter(c => !info.collide || info.collide.some(k => c.bones[0].includes(k))); 978: const cl = (info.closed || cname.includes("tabard")) 979: ? new SkirtRig(skinned, info.u, info.v, trims, caps, bone, !!info.closed, info.edges === "hem") 980: : new Cloth(skinned, info.u, info.v, trims, caps, bone, false, info.edges === "hem"); 981: const band = info.band || "gold", BR = V.roles[band] || V.roles.gold; 982: const gold = hex(BR.bands ? BR.bands[Math.min(1, BR.bands.length - 1)][1] : BR.color); 983: const PB = (V.paint || {})[band]; 984: if (PB && PB.base) skinned.userData.mats.painted.uniforms.uBand.value = hex(PB.base); // gold stays gold for decals 985: cl.lines3d = new THREE.LineSegments(cl.lines.geometry, new THREE.LineBasicMaterial({ color: gold })); 986: cl.lines3d.frustumCulled = false; 987: world.add(cl.display, cl.lines3d); 988: cloths.push(cl); 989: } 990: const mixer = new THREE.AnimationMixer(gltf.scene); 991: const actions = Object.fromEntries(gltf.animations.map(c => [c.name, mixer.clipAction(c)])); 992: const skeleton = meshes.find(m => m.isSkinnedMesh)?.skeleton; 993: const c = { name, info: V, turn, holder, root: gltf.scene, meshes, cloths, world, mixer, actions, skeleton, 994: clip: "idle", t: 0, groups: [...new Set(meshes.map(m => m.userData.group))] }; 995: c.springs = makeSprings(c, V.springs); 996: chars.set(name, c); 997: return c; 998: } 999: 1000: async function loadGround() { 1001: if (ground) return ground; 1002: const V = CAM.characters[0].info, gltf = await parseGlb("plains.glb.json"), meshes = []; 1003: gltf.scene.traverse(o => { if (o.isMesh) { prepMesh(o, V); meshes.push(o); } }); 1004: ground = { root: gltf.scene, meshes }; 1005: return ground; 1006: } 1007: 1008: const allMeshes = () => [...active().flatMap(c => [...c.meshes, ...c.cloths.map(cl => cl.display)]), 1009: ...(ground && ground.root.parent && state.view !== "bust" ? ground.meshes : [])]; 1010: const isSimTrim = o => state.cloth && active().some(c => c.cloths.some(cl => cl.trims.includes(o) || cl.skinned === o)); 1011: function applyMaterials() { 1012: allMeshes().forEach(o => { 1013: const mat = state.toon ? o.userData.mats.toon : o.userData.mats.clay; 1014: const x = state.xray && COSTUME.has(o.userData.group); 1015: mat.transparent = x; mat.opacity = x ? 0.28 : 1; mat.depthWrite = !x; mat.needsUpdate = true; 1016: o.userData.mat3d = mat; 1017: const isDisplay = o.userData.cloth; 1018: o.visible = !state.hidden.has(o.userData.group) && (isDisplay ? state.cloth : !isSimTrim(o)); 1019: }); 1020: } 1021: const trimsShown = c => state.cloth && !state.hidden.has("trim") && !state.hidden.has(c.skinned.userData.group); 1022: 1023: // ---- animation ------------------------------------------------------------------------------------------------------ 1024: // A clip only carries the bones it moves away from the reference pose, so each one starts from the 1025: // reference pose (otherwise "arms out" would keep the idle's legs). 1026: const CLIP_VIEW = { clash: "duel", idle: "battle", attack: "battle", apose: "battle" }; 1027: const lineupX = i => (i - (LINEUP.order.length - 1) / 2) * LINEUP.spacing; 1028: function setClip(name, blendFrom = null) { 1029: for (const c of active()) { 1030: const n = c.actions[name] ? name : "idle"; 1031: if (!blendFrom) c.skeleton && c.skeleton.pose(); 1032: c.clip = n; c.t = 0; 1033: Object.entries(c.actions).forEach(([k, a]) => { if (k === n) { a.reset(); a.setEffectiveWeight(1); a.play(); } else a.stop(); }); 1034: // ease in from another clip: legs stepping out gradually push the cloth (a long skirt) instead of 1035: // jumping through it 1036: c.blend = blendFrom && c.actions[blendFrom] ? { from: blendFrom, t: 0, dur: 0.8 } : null; 1037: } 1038: state.clip = name; 1039: document.querySelectorAll("[data-clip]").forEach(b => b.setAttribute("aria-pressed", String(b.dataset.clip === name && state.view !== "bust"))); 1040: } 1041: function animate(dt) { 1042: for (const c of active()) { 1043: if (ARMORY_PAGE && !SHEET) { c.mixer.stopAllAction(); c.skeleton && c.skeleton.pose(); applyPose(c); applyMotion(c, dt); continue; } 1044: if (state.view === "bust") { c.mixer.stopAllAction(); c.skeleton && c.skeleton.pose(); continue; } 1045: const a = c.actions[c.clip]; if (!a) continue; 1046: if (!a.isRunning()) a.play(); 1047: const dur = a.getClip().duration; 1048: c.t += dt; 1049: if (c.clip === "attack" && c.t > dur + 0.25) { setClip("idle"); return animate(0); } 1050: const t = state.stepped ? Math.floor(c.t * 12) / 12 : c.t; 1051: a.time = c.clip === "attack" ? Math.min(t, dur) : t % dur; // the others loop 1052: if (c.blend) { 1053: c.blend.t += dt; 1054: const w = Math.min(1, c.blend.t / c.blend.dur), b = c.actions[c.blend.from]; 1055: if (!b.isRunning()) b.play(); 1056: b.time = t % b.getClip().duration; b.setEffectiveWeight(1 - w); a.setEffectiveWeight(w); 1057: if (w >= 1) { b.stop(); a.setEffectiveWeight(1); c.blend = null; } 1058: } 1059: c.mixer.update(0); 1060: }read_file{"EndLine":480,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":340}
input
{ "EndLine": 480, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 340 }result, 142 lines
Showing lines 340-480 of 1807 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); 400: vec3 s0, s1, s2, s3; 401: if (!gold) { s0 = tone(base, 0.68, 0.10, 2.4, 0.32); s1 = tone(base, 0.68, 0.06, 1.7, 0.76); 402: s2 = tone(base, 0.12, 0.0, 0.8, 0.88); s3 = vec3(0.97, 0.96, 0.92); } 403: else { s0 = vec3(0.30, 0.20, 0.30); s1 = tone(base, 0.20, 0.03, 1.0, 0.72); s2 = base; s3 = tone(base, 0.16, 0.03, 0.5, 1.5); } 404: vec3 hard = mix(s0, s1, st(ry, -0.42)); // facing down: dark 405: hard = mix(hard, s2, st(ry, -0.08)); // facing us: the plate's own grey 406: hard = mix(hard, s0, st(ry, 0.36)); // dark core under the streak 407: hard = mix(hard, s3, st(ry, 0.47)); // the white streak 408: hard = mix(hard, s2 * 1.06, st(ry, 0.70)); 409: float k = smoothstep(-0.55, 0.30, r.y); // broad: darker toward the ground (no jitter: 410: if (hgt >= 0.0) k = clamp(k * 0.45 + hgt * 0.80 - 0.18, 0.0, 1.0); // on a flat plate it streaks) 411: else k = clamp(k * 0.6 + n.y * 0.35 + 0.05, 0.0, 1.0); // without plate data: lighter facing up 412: vec3 soft = mix(s1 * 0.9, s2, k); 413: float hl = dot(n, normalize(uKey + v)); // the key's highlight, a hard-edged shape 414: if (hgt >= 0.0) soft = mix(soft, mix(s2, s3, 0.6), st(hl, 0.955) * smoothstep(0.45, 0.8, hgt)); // the upper part only 415: vec3 col = mix(soft, hard, sharp); 416: return mix(col * 0.72 + s0 * 0.28, col, st(lit, 0.30)); 417: } 418: void main() { 419: vec4 tex = texture2D(uMap, vUv); 420: if (uAlpha == 1 && tex.a < 0.5) discard; 421: if (uAlpha == 2 && (tex.a < 0.5 || dot(tex.rgb, vec3(1.0 / 3.0)) >= 0.42)) discard; 422: if (uPass == 1) { gl_FragColor = uInfo; return; } 423: vec3 n = normalize(vN); if (!gl_FrontFacing) n = -n; 424: vec3 v = normalize(vView); 425: float lit = dot(n, uKey) * 0.5 + 0.5; 426: if (uShadeOnly == 1) lit = min(lit, 0.37); // shadow cards only ever darken skin, to a soft shade 427: else if (uCastOn == 1 && uKind == 1 && int(uInfo.x * 255.0 + 0.5) == 2 && castShadow() > 0.5) 428: lit = min(lit, 0.37); // body skin under the jaw's or the hair's shadow 429: float g1 = vnoise(vObj * 40.0), g2 = vnoise(vObj * 150.0); 430: vec3 col; 431: if (uKind == 0 || uKind == 5 || uKind == 6) { // cloth, leather, ground 432: vec3 hb = rgb2hsv(uBase); 433: bool cool = hb.x > 0.42 && hb.x < 0.86; 434: float sh = uKind == 5 ? 0.93 : (cool ? 0.70 : 0.96); 435: float li = cool ? 0.52 : 0.13; 436: vec3 c0 = tone(uBase, sh, 0.09, 1.12, 0.40), c1 = tone(uBase, sh, 0.05, 1.08, 0.64); 437: vec3 c3 = tone(uBase, li, 0.03, 0.80, 1.20); 438: float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.22 : 0.0); // ground: a flat top sits at the base colour 439: col = mix(c0, c1, st(l, 0.30)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.91)); 440: if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0); // mottled leather 441: } else if (uKind == 1) { // skin: pale, nearly unshaded from the front 442: vec3 sL = vec3(0.973, 0.882, 0.835), sS = vec3(0.776, 0.659, 0.608), sC = vec3(0.451, 0.322, 0.310); 443: if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; } // the character's tone, designed per tone 444: col = mix(sC, sS, st(lit, 0.20)); col = mix(col, sL, st(lit, 0.38)); 445: if (uFaceTex == 1) col *= clamp(tex.rgb / uSkinRef, 0.55, 1.05); 446: if (uFaceTex == 1 && vUv.x > 0.38 && vUv.x < 0.62 && vUv.y > 0.68 && vUv.y < 0.84) { 447: // the closed mouth: VRoid paints a 2-texel line that the clamp above leaves faint; ink it and widen it 448: // (the darkest of a few taps), so it follows the mouth's shape keys as a drawn line 449: float d = 0.0, sl = dot(uSkinRef, vec3(1.0 / 3.0)); 450: for (int k = -2; k <= 2; k++) for (int j = -1; j <= 1; j++) { 451: vec3 t = texture2D(uMap, vUv + vec2(float(j) * 1.2, float(k) * 0.8) / 512.0).rgb; 452: d = max(d, 1.0 - dot(t, vec3(1.0 / 3.0)) / sl); 453: } 454: float taper = 1.0 - 0.55 * smoothstep(0.035, 0.065, abs(vUv.x - 0.5)); // a brush stroke: lighter at the corners 455: col = mix(col, vec3(0.42, 0.22, 0.22), smoothstep(0.10, 0.22, d) * taper); 456: } 457: if (uSkinRamp == 0) col *= uSkinTone; // older builds: one tint over the light skin 458: } else if (uKind == 2) { // hair: four even bands, hard strand highlights 459: float strand = dot(tex.rgb, vec3(1.0 / 3.0)); 460: vec3 c0 = tone(uBase, 0.72, 0.07, 1.10, 0.45), c1 = tone(uBase, 0.72, 0.035, 1.05, 0.68); 461: vec3 c2 = tone(uBase, 0.56, 0.02, 0.92, 1.10), c3 = tone(uBase, 0.56, 0.03, 0.55, 1.42); 462: float l = lit + (strand - 0.6) * 0.12; 463: col = mix(c0, c1, st(l, 0.40)); col = mix(col, uBase, st(l, 0.56)); col = mix(col, c2, st(l, 0.84)); 464: float sp = dot(n, normalize(uKey + v)) + (strand - 0.6) * 0.18; 465: col = mix(col, c3, st(sp, 0.90) * (1.0 - st(sp, 0.985))); 466: } else if (uKind == 3 || uKind == 4) { // steel, gold 467: bool plate = vPlate.x > 0.5; 468: float e = vPlate.y, w = vPlate.z; 469: bool gilt = uKind == 4 || (plate && w > 0.0 && e < w); // an outline plate's gold border 470: col = metal(gilt, gilt && uKind == 3 ? uGold : uBase, n, v, lit, plate ? vPlate.w : -1.0); 471: if (plate && w > 0.0) { // engraved lines: one inside the border, one on its seam 472: float aa = fwidth(e) * 1.2 + 1e-5; 473: float l1 = 1.0 - smoothstep(0.0010, 0.0010 + aa, abs(e - (w + 0.0050))); 474: float l2 = 1.0 - smoothstep(0.0006, 0.0006 + aa, abs(e - w)); 475: col = mix(col, col * 0.42, max(l1, l2 * 0.8)); 476: } 477: } else if (uKind == 7) { // iris 478: float l = dot(tex.rgb, vec3(1.0 / 3.0)); 479: col = l < 0.3 ? mix(uEye[0], uEye[1], l / 0.3) : mix(uEye[1], uEye[2], clamp((l - 0.3) / 0.6, 0.0, 1.0)); 480: } else if (uKind == 8) { col = tex.rgb; }read_file{"EndLine":345,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":315}
input
{ "EndLine": 345, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 315 }result, 32 lines
Showing lines 315-345 of 1807 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;read_file{"EndLine":590,"Path":"~/work/lowmarch/review/vroid-02/index.html","StartLine":495}
input
{ "EndLine": 590, "Path": "~/work/lowmarch/review/vroid-02/index.html", "StartLine": 495 }result, 97 lines
Showing lines 495-590 of 1807 495: float pm = smoothstep(0.3, 0.7, dm.r), gm = smoothstep(0.3, 0.7, dm.g), au = smoothstep(0.3, 0.7, dm.b); 496: if (au > 0.0) col = mix(col, metal(true, uGold, n, v, lit, -1.0), au); 497: if (pm > 0.0) { 498: vec3 pc = mix(tone(uMotif, 0.70, 0.05, 1.10, 0.62), uMotif, st(lit, 0.42)); 499: col = mix(col, mix(pc, tone(uMotif, 0.56, 0.03, 0.8, 1.25), st(lit, 0.92)), pm); 500: } 501: if (gm > 0.0) col = mix(col, col * 0.30, gm); 502: } 503: if (vEdge > 0.5) { // the cloth's border band 504: vec3 gd = tone(uBand, 0.20, 0.03, 1.0, 0.72); 505: col = mix(gd, uBand, st(lit, 0.45)); col = mix(col, tone(uBand, 0.16, 0.03, 0.5, 1.45), st(lit, 0.85)); 506: } 507: if (uKind <= 6) { 508: vec3 grade = mix(uAmbient, uKeyCol, st(lit, 0.55)); 509: col *= uKind == 1 && uSkinRamp == 1 ? mix(vec3(1.0), grade, 0.3) : grade; // a designed skin ramp takes less of it 510: float fr = pow(1.0 - max(dot(n, v), 0.0), 4.0); 511: float back = clamp(dot(n, normalize(vec3(0.55, 0.45, -0.35))), 0.0, 1.0); 512: col += uRimCol * fr * smoothstep(0.1, 0.5, back); 513: if (uKind != 1) col *= 1.0 + (g2 - 0.5) * 0.06; 514: } 515: gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0); 516: }`; 517: const PAINT_COMP = ` 518: uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes; 519: uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm; 520: ${HSV} 521: float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); } 522: int rid(vec4 i) { return int(i.r * 255.0 + 0.5); } 523: float pid(vec4 i) { return floor(i.g * 255.0 + 0.5) + floor(i.b * 255.0 + 0.5) * 256.0; } 524: vec3 ink(vec3 c) { vec3 h = rgb2hsv(c); return hsv2rgb(vec3(h.x, clamp(h.y, 0.20, 0.45), 0.19)); } 525: // How far (px) the mouth's opening runs from this pixel in direction d (2 px steps, up to 128 px). 526: float mouthRun(vec2 uv, vec2 d) { 527: float n = 0.0; 528: for (int s = 1; s <= 64; s++) { vec4 a = texture2D(tInfo, uv + d * float(2 * s)); if (a.a < 0.5 || rid(a) != 9) break; n += 2.0; } 529: return n; 530: } 531: // Brows drawn over the bangs: where hair lies just above or below the stroke, the brow is seen through the hair, 532: // so it takes some of the hair's colour and doesn't sit on it like a sticker. 533: vec3 browOverHair(vec2 uv, vec2 px, vec3 col) { 534: float d = 3.5 * uSil; 535: vec4 a = texture2D(tInfo, uv + vec2(0.0, d) * px), b = texture2D(tInfo, uv - vec2(0.0, d) * px); 536: bool ha = a.a > 0.5 && (rid(a) == 3 || rid(a) == 11), hb = b.a > 0.5 && (rid(b) == 3 || rid(b) == 11); 537: if (!(ha || hb)) return col; 538: vec3 hc = ha ? texture2D(tColor, uv + vec2(0.0, d) * px).rgb : texture2D(tColor, uv - vec2(0.0, d) * px).rgb; 539: return mix(col, hc * 0.80, ha && hb ? 0.68 : 0.34); 540: } 541: void main() { 542: vec2 uv = gl_FragCoord.xy / uRes, px = 1.0 / uRes; 543: vec4 inf = texture2D(tInfo, uv); 544: if (inf.a < 0.5) { // outer line: grow the silhouette outward 545: vec4 best = vec4(0.0); vec2 bq = uv; 546: for (int k = 0; k < 12; k++) { 547: float a = float(k) * 0.5236; 548: for (int s = 1; s <= 2; s++) { 549: vec2 q = uv + vec2(cos(a), sin(a)) * uSil * float(s) * 0.5 * px; 550: vec4 ni = texture2D(tInfo, q); 551: if (ni.a > 0.5) { best = ni; bq = q; } 552: } 553: } 554: if (best.a > 0.5) { 555: int r = rid(best); 556: if (r >= 4 && r <= 7) { gl_FragColor = vec4(0.0); return; } 557: gl_FragColor = vec4(ink(texture2D(tColor, bq).rgb), 1.0); return; 558: } 559: gl_FragColor = vec4(0.0); return; 560: } 561: vec3 col = texture2D(tColor, uv).rgb; int r0 = rid(inf); float p0 = pid(inf); float z0 = z(uv); 562: bool feature = r0 >= 4 && r0 <= 9; 563: if (r0 == 9) { // the open mouth's rim: a lip line where it meets the face 564: for (int k = 0; k < 8; k++) { 565: float a = float(k) * 0.785398; 566: vec2 q = uv + vec2(cos(a), sin(a)) * uSil * 0.9 * px; 567: vec4 ni = texture2D(tInfo, q); 568: if (ni.a > 0.5 && rid(ni) == 1) { col = mix(ink(texture2D(tColor, q).rgb), vec3(0.30, 0.10, 0.12), 0.4); break; } 569: } 570: float hu = mouthRun(uv, vec2(0.0, px.y)), hd = mouthRun(uv, vec2(0.0, -px.y)), h = hu + hd + 1.0; 571: // teeth only in an opening tall enough to show them (8 to 11 mm, measured on the face): a slit or parted lips 572: // (angry, sad) is all teeth in VRoid's mesh and read as a white pill; it reads as the dark inside instead 573: float thin = 1.0 - smoothstep(0.008, 0.011, h / uPpm); 574: if (thin > 0.0 && dot(col, vec3(1.0 / 3.0)) >= 0.8) col = mix(col, vec3(0.30, 0.10, 0.13), thin); 575: float up = 0.0; // the upper lip's shadow: the top of the opening is dark 576: for (int s = 2; s <= 5; s++) { vec4 a = texture2D(tInfo, uv + vec2(0.0, float(s)) * uSil * px); if (a.a > 0.5 && rid(a) == 1) up = 1.0; } 577: if (up > 0.5 && dot(col, vec3(1.0 / 3.0)) < 0.8) col = min(col, vec3(0.36, 0.11, 0.14)); // not the teeth 578: // a tall opening (shout, surprise) is dark in its upper part, the tongue only low in it; VRoid's map stretched 579: // over a big opening would fill it with tongue. Small openings keep the map's read. 580: float deep = 0.5 * smoothstep(14.0 * uSil, 30.0 * uSil, h), t = (hu + 0.5) / h; 581: if (deep > 0.0 && dot(col, vec3(1.0 / 3.0)) < 0.8) col = mix(vec3(0.30, 0.10, 0.13), col, smoothstep(deep - 0.08, deep + 0.08, t)); 582: } 583: if (r0 == 8) col = browOverHair(uv, px, col); 584: if (!feature) { 585: for (int k = 0; k < 4; k++) { 586: vec2 d = k == 0 ? vec2(1.0, 0.0) : (k == 1 ? vec2(-1.0, 0.0) : (k == 2 ? vec2(0.0, -1.0) : vec2(0.0, 1.0))); 587: vec2 q = uv + d * px * uInner; 588: vec4 ni = texture2D(tInfo, q); 589: if (z(q) > z0 + uGap && pid(ni) != p0) { col = ink(col); break; } 590: }