Subagent: Model export and lens shot
agent (cont.)
+0:55Bashcat [redacted: private path]/trials/face-shading-2026-10-30/scripts/patch_lens_flattice.py; ls [redacted: private path]/trials/face-shading-2026-10-30/scripts/
command
cat [redacted: private path]/trials/face-shading-2026-10-30/scripts/patch_lens_flattice.py; ls [redacted: private path]/trials/face-shading-2026-10-30/scripts/
result, 126 lines
"""Patch a scratch copy of the built armory page: tiles may take a close-up lens (`lens`, mm on a 36 mm wide frame) and Flattice (`flat`, 0..1), drawn by the page's own painted renderer. Flattice is DillonGoo's add-on done in the vertex shader: every vertex is squashed toward a plane through the head bone's head, along the line from there to the camera, by `flat` times a weight that is 1 above the chin and fades to 0 over 5 cm below it (the add-on's MOD-Flattice group with the cursor at the chin). Normals are left as they were, as the Yin rig shades from normals stored before its lattice. Under a lens the outline pass reads perspective depth. At flat 1 every layer of the head lands on one plane and a depth buffer can't order them (hair, skin and mouth interior fight); 0.85 keeps enough depth, and the outline pass's depth step shrinks with the squash. python3 patch_lens_flattice.py SITE_DIR """ import sys path = sys.argv[1] + "/index.html" s = open(path, encoding="utf-8").read() def rep(old, new): global s assert s.count(old) == 1, old[:80] s = s.replace(old, new) # vertex shader: the squash, in view space, after skinning rep(""" varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; void main() { ${SKIN_BODY} vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate; vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz;""", """ varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; uniform float uFlattice; uniform float uFlChin; uniform float uFlFall; uniform vec3 uFlPivot; void main() { ${SKIN_BODY} vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate; vec4 mv = modelViewMatrix * vec4(transformed, 1.0); if (uFlattice > 0.0) { // Flattice: squash toward the pivot's plane, along pivot-to-camera float w = clamp((position.y - (uFlChin - uFlFall)) / uFlFall, 0.0, 1.0); vec3 u = normalize(-uFlPivot); mv.xyz -= u * dot(mv.xyz - uFlPivot, u) * w * uFlattice; } vView = -mv.xyz;""") rep(""" uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 },""", """ uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 }, uFlattice: { value: 0 }, uFlChin: { value: 0 }, uFlFall: { value: 0.05 }, uFlPivot: { value: new THREE.Vector3() },""") # outline [redacted: scan false positive] depth under a lens rep(""" float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); }""", """ uniform float uPersp; float z(vec2 p) { float d = texture2D(tDepth, p).x; return uPersp > 0.5 ? uNear * uFar / (uFar - d * (uFar - uNear)) : uNear + d * (uFar - uNear); }""") rep(""" uNear: { value: 0.1 }, uFar: { value: 40 },""", """ uNear: { value: 0.1 }, uFar: { value: 40 }, uPersp: { value: 0 },""") # tiles: after the page frames its orthographic view, a lens tile moves in and switches to a perspective projection rep(""" frameAt(centre, h, tw_, th_, pitch); render();""", """ frameAt(centre, h, tw_, th_, pitch); lensAndFlat(tile, centre, h, tw_, th_, pitch); render();""") rep("""async function runSheet(kind) {""", """function lensAndFlat(tile, centre, h, tw, th, pitch) { const pu = paint.mat.uniforms; pu.uPersp.value = 0; camera.near = 0.1; camera.far = 40; if (pu.uGap.userData === undefined) pu.uGap.userData = pu.uGap.value; pu.uGap.value = pu.uGap.userData * (1 - (tile.flat || 0)); // depth steps shrink with the squash; so does the line test const chr = active()[0]; if (tile.lens) { const w = h * tw / th, d = w * tile.lens / 36, a = THREE.MathUtils.degToRad(pitch), n = 0.01; camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(d)); camera.lookAt(centre); camera.updateMatrixWorld(true); camera.near = n; camera.far = 40; camera.projectionMatrix.makePerspective(-w / 2 * n / d, w / 2 * n / d, h / 2 * n / d, -h / 2 * n / d, n, 40); camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert(); pu.uPersp.value = 1; } const face = chr.meshes.find(o => /Face_00_SKIN/.test(o.name + " " + (o.userData.material || ""))); face.geometry.computeBoundingBox(); let pivot = chr.root.getObjectByName("J_Bip_C_Head").getWorldPosition(new THREE.Vector3()); if (tile.pivot === "chin") { // the chin's front: the face's lowest points, the most forward of them const P = face.geometry.attributes.position, low = face.geometry.boundingBox.min.y, v = new THREE.Vector3(); let best = null; for (let i = 0; i < P.count; i++) { v.fromBufferAttribute(P, i); if (v.y < low + 0.006 && (!best || v.z > best.z)) best = v.clone(); } pivot = best.applyMatrix4(face.matrixWorld); } pivot.applyMatrix4(camera.matrixWorldInverse); for (const o of chr.meshes) { const mu = o.material.uniforms; if (!mu || !mu.uFlattice) continue; mu.uFlattice.value = tile.flat || 0; mu.uFlChin.value = tile.whole ? -100 : face.geometry.boundingBox.min.y + 0.01; // whole: the body too mu.uFlFall.value = 0.05; mu.uFlPivot.value.copy(pivot); } } async function runSheet(kind) {""") # the rows: the armory camera, then a 24 mm close-up without and with Flattice i = s.index("const ARMORY_ROWS = [") j = s.index("const DUEL_YAWS") s = s[:i] + """const ARMORY_ROWS = [ { label: "Armory camera", tw: 340, th: 340, tiles: [0, 35, 60, 90].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.05, size: 0.40, label: `${y}°` })) }, { label: "Close-up lens 24 mm, Flattice off", tw: 340, th: 340, tiles: [0, 35, 60, 90].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.05, size: 0.40, lens: 24, flat: 0, label: `${y}°` })) }, { label: "Close-up lens 24 mm, Flattice on (0.85: a little depth kept)", tw: 340, th: 340, tiles: [0, 35, 60, 90].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.05, size: 0.40, lens: 24, flat: 0.85, label: `${y}°` })) }, { label: "Close-up lens 24 mm, Flattice on, pivot at the chin", tw: 340, th: 340, tiles: [0, 35, 60, 90].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.05, size: 0.40, lens: 24, flat: 0.85, pivot: "chin", label: `${y}°` })) }, { label: "Close-up lens 24 mm, Flattice on the whole body", tw: 340, th: 340, tiles: [0, 35, 60, 90].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.05, size: 0.40, lens: 24, flat: 0.85, whole: true, label: `${y}°` })) }, ]; """ + s[j:] open(path, "w", encoding="utf-8").write(s) print("patched", path) arm_shoot.py before_after.py flattice_pairs.py light_sheet.py patch_lens_flattice.py pivot_sheet.py rows_sheet.py run_range.sh skin_grid.py variant_build.py yin_pivot_probe.pyBashS=review/out/whole-lens/site/index.html; for t in "varying vec3 vN; varying vec2 vUv; varying vec3 vView" "uMap: { value: map || white }, uAlpha" "float z(vec2 p)" "uNear: { value: 0.1 }, uFar: { value: 40 }," "frameAt(centre, h, tw_, th_, pitch);" "async function runSheet" "const ARMORY_ROWS" "const DUEL_YAWS" "uGap" "Face_00_SKIN" "paint.mat" "camera ="; do echo "== $t: $(grep -c -F "$t" $S)"; grep -n -F "$t" $S | head -5; done; diff <(git show HEAD:review/vroid-02/index.html) $S && echo same-as-repo
command
S=review/out/whole-lens/site/index.html; for t in "varying vec3 vN; varying vec2 vUv; varying vec3 vView" "uMap: { value: map || white }, uAlpha" "float z(vec2 p)" "uNear: { value: 0.1 }, uFar: { value: 40 }," "frameAt(centre, h, tw_, th_, pitch);" "async function runSheet" "const ARMORY_ROWS" "const DUEL_YAWS" "uGap" "Face_00_SKIN" "paint.mat" "camera ="; do echo "== $t: $(grep -c -F "$t" $S)"; grep -n -F "$t" $S | head -5; done; diff <(git show HEAD:review/vroid-02/index.html) $S && echo same-as-reporesult, 29 lines
== varying vec3 vN; varying vec2 vUv; varying vec3 vView: 2 318: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; 373: varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; == uMap: { value: map || white }, uAlpha: 1 862: uMap: { value: map || white }, uAlpha: { value: 0 }, uPass: { value: 0 }, == float z(vec2 p): 1 521: float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); } == uNear: { value: 0.1 }, uFar: { value: 40 },: 1 623: uNear: { value: 0.1 }, uFar: { value: 40 }, uGap: { value: 0.012 }, uSil: { value: 2 }, uInner: { value: 1 }, uPpm: { value: 1000 } }); == frameAt(centre, h, tw_, th_, pitch);: 1 1587: frameAt(centre, h, tw_, th_, pitch); == async function runSheet: 1 1510:async function runSheet(kind) { == const ARMORY_ROWS: 1 1460:const ARMORY_ROWS = [ == const DUEL_YAWS: 1 1472:const DUEL_YAWS = [0, 40, 90, 320]; == uGap: 4 519: uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm; 589: if (z(q) > z0 + uGap && pid(ni) != p0) { col = ink(col); break; } 623: uNear: { value: 0.1 }, uFar: { value: 40 }, uGap: { value: 0.012 }, uSil: { value: 2 }, uInner: { value: 1 }, uPpm: { value: 1000 } }); 1344: paint.mat.uniforms.uGap.value = lead.depth_gap; == Face_00_SKIN: 0 == paint.mat: 2 1344: paint.mat.uniforms.uGap.value = lead.depth_gap; 1417: const u = paint.mat.uniforms; == camera =: 1 306:const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40); same-as-repoBashS=review/out/whole-lens/site/index.html; sed -n 300,420p $S
command
S=review/out/whole-lens/site/index.html; sed -n 300,420p $S
result, 120 lines
// ---- scene and camera ----------------------------------------------------------------------------------------------- const scene = new THREE.Scene(); const hemi = new THREE.HemisphereLight(0xfff6ee, 0x3a3450, 1.35); const sun = new THREE.DirectionalLight(0xffffff, 1.6); scene.add(hemi, sun); const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40); // ---- shaders -------------------------------------------------------------------------------------------------------- const SKIN_HEAD = `#include <common> #include <skinning_pars_vertex>`; const SKIN_BODY = `#include <beginnormal_vertex> #include <skinbase_vertex> #include <skinnormal_vertex> #include <begin_vertex> #include <skinning_vertex>`; const PAINT_VS = `${SKIN_HEAD} attribute float edge; attribute vec4 _plate; uniform float uLift; varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; void main() { ${SKIN_BODY} vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate; vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz; mv.z += uLift; // brows: drawn over the bangs (depth lift toward the camera) gl_Position = projectionMatrix * mv; }`; const HSV = ` vec3 rgb2hsv(vec3 c) { vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); float d = q.x - min(q.w, q.y); return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 1e-10)), d / (q.x + 1e-10), q.x); } vec3 hsv2rgb(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); }`; // painted renderer, after the Unicorn Overlord study: tight terminators, hue-shifted ramps built from // one base colour per material, hard reflection bands on steel, strand highlights on hair, a stage // grade and a back rim const PAINT_FS = ` uniform int uKind; uniform vec3 uBase; uniform vec3 uKey; uniform sampler2D uMap; uniform int uAlpha; uniform int uPass; uniform vec4 uInfo; uniform vec3 uEye[3]; uniform vec3 uFlat; uniform vec3 uSkinRef; uniform vec3 uGold; uniform vec3 uAmbient; uniform vec3 uKeyCol; uniform vec3 uRimCol; uniform float uGrain; uniform int uFaceTex; uniform int uDecal; uniform vec3 uMotif; uniform vec3 uBand; uniform vec3 uSkinTone; uniform int uShadeOnly; uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC; uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn; uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm; // Cast shadows on skin, in screen space (the "depth offset" shadows of anime toon shaders): walk from this pixel // toward the key light across the info pass already drawn; if the face (the jaw) or hair stands in front of that // ray, this pixel is in its shadow. The shape is the caster's own outline as the camera sees it, at any angle. float castShadow() { vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes; float z0 = uCastNear + texture2D(tCastDepth, uv).x * (uCastFar - uCastNear); float sxy = length(uKey.xy); if (sxy < 0.05) return 0.0; vec2 dir = uKey.xy / sxy; float lz = uKey.z / sxy; // the ray's rise toward the camera per metre across for (int s = 1; s <= 14; s++) { float dm = float(s) * 0.003; // 3 mm steps across the screen, up to 4.2 cm vec2 q = uv + dir * dm * uCastPpm * px; vec4 ni = texture2D(tCastInfo, q); if (ni.a < 0.5) continue; int r = int(ni.r * 255.0 + 0.5); if (r != 1 && r != 3 && r != 11) continue; // casters: the face (jaw, chin) and hair float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear); float zr = z0 - lz * dm; if (zq < zr - 0.004 && zq > zr - 0.20) return 1.0; } return 0.0; } varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; ${HSV} 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)); } float vnoise(vec3 x) { vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f); 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), 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); } float toward(float h, float target, float amt) { float d = target - h; d -= floor(d + 0.5); return fract(h + clamp(d, -amt, amt)); } vec3 tone(vec3 base, float hue, float amt, float sMul, float vMul) { vec3 h = rgb2hsv(base); return hsv2rgb(vec3(toward(h.x, hue, amt), clamp(h.y * sMul, 0.0, 1.0), clamp(h.z * vMul, 0.0, 1.0))); } float st(float x, float t) { return smoothstep(t - 0.03, t + 0.03, x); } // Steel and gold. Hard reflection bands (dark below the horizon, a dark core under a white streak) // read well where the surface turns fast: rims, tubes, lames. On a broad plate the reflection // barely changes, so a band there fills the whole plate (the blotches): bands fade by how sharply // the surface curves (normal change per metre on screen), and broad plates get a soft tone that // lightens up each outline plate (hgt: height in the plate 0..1, or -1 without plate data). vec3 metal(bool gold, vec3 base, vec3 n, vec3 v, float lit, float hgt) { vec3 r = reflect(-v, n); 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 float curv = length(fwidth(n)) / max(length(fwidth(vView)), 1e-5); float sharp = smoothstep(5.0, 14.0, curv); // a shaped plate's domes (over the bust, a crowned panel) turn the bands into closed rings: plates // keep only a little of them and take a crisp highlight toward the light instead if (hgt >= 0.0) sharp *= 0.25; else sharp = max(sharp, 0.3); vec3 s0, s1, s2, s3; if (!gold) { s0 = tone(base, 0.68, 0.10, 2.4, 0.32); s1 = tone(base, 0.68, 0.06, 1.7, 0.76); s2 = tone(base, 0.12, 0.0, 0.8, 0.88); s3 = vec3(0.97, 0.96, 0.92); } 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); } vec3 hard = mix(s0, s1, st(ry, -0.42)); // facing down: dark hard = mix(hard, s2, st(ry, -0.08)); // facing us: the plate's own grey hard = mix(hard, s0, st(ry, 0.36)); // dark core under the streak hard = mix(hard, s3, st(ry, 0.47)); // the white streak hard = mix(hard, s2 * 1.06, st(ry, 0.70)); float k = smoothstep(-0.55, 0.30, r.y); // broad: darker toward the ground (no jitter: if (hgt >= 0.0) k = clamp(k * 0.45 + hgt * 0.80 - 0.18, 0.0, 1.0); // on a flat plate it streaks) else k = clamp(k * 0.6 + n.y * 0.35 + 0.05, 0.0, 1.0); // without plate data: lighter facing up vec3 soft = mix(s1 * 0.9, s2, k); float hl = dot(n, normalize(uKey + v)); // the key's highlight, a hard-edged shape 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 vec3 col = mix(soft, hard, sharp); return mix(col * 0.72 + s0 * 0.28, col, st(lit, 0.30)); } void main() { vec4 tex = texture2D(uMap, vUv); if (uAlpha == 1 && tex.a < 0.5) discard;BashS=review/out/whole-lens/site/index.html; sed -n 366,380p $S; sed -n 500,640p $S
command
S=review/out/whole-lens/site/index.html; sed -n 366,380p $S; sed -n 500,640p $S
result, 155 lines
if (r != 1 && r != 3 && r != 11) continue; // casters: the face (jaw, chin) and hair float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear); float zr = z0 - lz * dm; if (zq < zr - 0.004 && zq > zr - 0.20) return 1.0; } return 0.0; } varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying float vEdge; varying vec4 vPlate; ${HSV} 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)); } float vnoise(vec3 x) { vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f); 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), 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); } } if (gm > 0.0) col = mix(col, col * 0.30, gm); } if (vEdge > 0.5) { // the cloth's border band vec3 gd = tone(uBand, 0.20, 0.03, 1.0, 0.72); 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)); } if (uKind <= 6) { vec3 grade = mix(uAmbient, uKeyCol, st(lit, 0.55)); col *= uKind == 1 && uSkinRamp == 1 ? mix(vec3(1.0), grade, 0.3) : grade; // a designed skin ramp takes less of it float fr = pow(1.0 - max(dot(n, v), 0.0), 4.0); float back = clamp(dot(n, normalize(vec3(0.55, 0.45, -0.35))), 0.0, 1.0); col += uRimCol * fr * smoothstep(0.1, 0.5, back); if (uKind != 1) col *= 1.0 + (g2 - 0.5) * 0.06; } gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0); }`; const PAINT_COMP = ` uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes; uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm; ${HSV} float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); } int rid(vec4 i) { return int(i.r * 255.0 + 0.5); } float pid(vec4 i) { return floor(i.g * 255.0 + 0.5) + floor(i.b * 255.0 + 0.5) * 256.0; } vec3 ink(vec3 c) { vec3 h = rgb2hsv(c); return hsv2rgb(vec3(h.x, clamp(h.y, 0.20, 0.45), 0.19)); } // How far (px) the mouth's opening runs from this pixel in direction d (2 px steps, up to 128 px). float mouthRun(vec2 uv, vec2 d) { float n = 0.0; 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; } return n; } // Brows drawn over the bangs: where hair lies just above or below the stroke, the brow is seen through the hair, // so it takes some of the hair's colour and doesn't sit on it like a sticker. vec3 browOverHair(vec2 uv, vec2 px, vec3 col) { float d = 3.5 * uSil; vec4 a = texture2D(tInfo, uv + vec2(0.0, d) * px), b = texture2D(tInfo, uv - vec2(0.0, d) * px); bool ha = a.a > 0.5 && (rid(a) == 3 || rid(a) == 11), hb = b.a > 0.5 && (rid(b) == 3 || rid(b) == 11); if (!(ha || hb)) return col; vec3 hc = ha ? texture2D(tColor, uv + vec2(0.0, d) * px).rgb : texture2D(tColor, uv - vec2(0.0, d) * px).rgb; return mix(col, hc * 0.80, ha && hb ? 0.68 : 0.34); } void main() { vec2 uv = gl_FragCoord.xy / uRes, px = 1.0 / uRes; vec4 inf = texture2D(tInfo, uv); if (inf.a < 0.5) { // outer line: grow the silhouette outward vec4 best = vec4(0.0); vec2 bq = uv; for (int k = 0; k < 12; k++) { float a = float(k) * 0.5236; for (int s = 1; s <= 2; s++) { vec2 q = uv + vec2(cos(a), sin(a)) * uSil * float(s) * 0.5 * px; vec4 ni = texture2D(tInfo, q); if (ni.a > 0.5) { best = ni; bq = q; } } } if (best.a > 0.5) { int r = rid(best); if (r >= 4 && r <= 7) { gl_FragColor = vec4(0.0); return; } gl_FragColor = vec4(ink(texture2D(tColor, bq).rgb), 1.0); return; } gl_FragColor = vec4(0.0); return; } vec3 col = texture2D(tColor, uv).rgb; int r0 = rid(inf); float p0 = pid(inf); float z0 = z(uv); bool feature = r0 >= 4 && r0 <= 9; if (r0 == 9) { // the open mouth's rim: a lip line where it meets the face for (int k = 0; k < 8; k++) { float a = float(k) * 0.785398; vec2 q = uv + vec2(cos(a), sin(a)) * uSil * 0.9 * px; vec4 ni = texture2D(tInfo, q); 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; } } float hu = mouthRun(uv, vec2(0.0, px.y)), hd = mouthRun(uv, vec2(0.0, -px.y)), h = hu + hd + 1.0; // teeth only in an opening tall enough to show them (8 to 11 mm, measured on the face): a slit or parted lips // (angry, sad) is all teeth in VRoid's mesh and read as a white pill; it reads as the dark inside instead float thin = 1.0 - smoothstep(0.008, 0.011, h / uPpm); if (thin > 0.0 && dot(col, vec3(1.0 / 3.0)) >= 0.8) col = mix(col, vec3(0.30, 0.10, 0.13), thin); float up = 0.0; // the upper lip's shadow: the top of the opening is dark 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; } 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 // a tall opening (shout, surprise) is dark in its upper part, the tongue only low in it; VRoid's map stretched // over a big opening would fill it with tongue. Small openings keep the map's read. float deep = 0.5 * smoothstep(14.0 * uSil, 30.0 * uSil, h), t = (hu + 0.5) / h; 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)); } if (r0 == 8) col = browOverHair(uv, px, col); if (!feature) { for (int k = 0; k < 4; k++) { 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))); vec2 q = uv + d * px * uInner; vec4 ni = texture2D(tInfo, q); if (z(q) > z0 + uGap && pid(ni) != p0) { col = ink(col); break; } } float acc = 0.0, rad = uSil * 3.0; for (int k = 0; k < 8; k++) { float a = float(k) * 0.785398 + 0.39; vec2 q = uv + vec2(cos(a), sin(a)) * rad * px; vec4 ni = texture2D(tInfo, q); if (ni.a > 0.5) acc += clamp((z0 - z(q)) / 0.05, 0.0, 1.0); } col *= 1.0 - 0.22 * acc / 8.0; if (r0 == 1) { // the bangs shade the forehead float hair = 0.0; for (int s = 1; s <= 4; s++) { vec4 a = texture2D(tInfo, uv + vec2(0.0, float(s)) * uSil * px); int ra = rid(a); if (a.a > 0.5 && (ra == 3 || ra == 11)) hair = 1.0; } col = mix(col, col * vec3(0.84, 0.74, 0.76), 0.75 * hair); } } gl_FragColor = vec4(col, 1.0); }`; const compCam = new THREE.Camera(); function compPass(fs, uniforms) { const mat = new THREE.ShaderMaterial({ uniforms, vertexShader: `void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }`, fragmentShader: fs, transparent: true }); const s = new THREE.Scene(); s.add(new THREE.Mesh(new THREE.PlaneGeometry(2, 2), mat)); return { mat, scene: s }; } // ---- the renderer --------------------------------------------------------------------------------------------------- const stageEl = $("stage"); const R = new THREE.WebGLRenderer({ antialias: false, alpha: true, preserveDrawingBuffer: !!SHEET }); R.setClearColor(0x000000, 0); R.outputColorSpace = THREE.LinearSRGBColorSpace; stageEl.appendChild(R.domElement); const paint = compPass(PAINT_COMP, { tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null }, uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 }, uGap: { value: 0.012 }, uSil: { value: 2 }, uInner: { value: 1 }, uPpm: { value: 1000 } }); const ctl = new OrbitControls(camera, R.domElement); ctl.enableDamping = true; ctl.zoomToCursor = true; ctl.screenSpacePanning = true; ctl.minZoom = 0.3; ctl.maxZoom = 12; let freeLook = false; ctl.addEventListener("start", () => { freeLook = true; }); R.domElement.addEventListener("dblclick", focusAt); const targets = { rt: null, rtInfo: null, key: "" }; function targetsFor(w, h) { const key = `${w}x${h}`; if (targets.key === key) return; [targets.rt, targets.rtInfo].forEach(t => t && t.dispose()); const o = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter }; targets.rt = new THREE.WebGLRenderTarget(w, h, o); targets.rtInfo = new THREE.WebGLRenderTarget(w, h, { ...o, depthTexture: new THREE.DepthTexture(w, h) }); targets.key = key; }BashS=review/out/whole-lens/site/index.html; sed -n 1388,1600p $S
command
S=review/out/whole-lens/site/index.html; sed -n 1388,1600p $S
result, 213 lines
function render() { const meshes = allMeshes(), cs = active(); applySkin(meshes); const cloths = cs.flatMap(c => c.cloths); if (state.mode === "3d") { meshes.forEach(o => o.material = o.userData.mat3d); cloths.forEach(c => c.lines3d.visible = trimsShown(c)); sun.position.copy(camera.position).add(new THREE.Vector3(-3, 4, 0)); sun.target.position.copy(ctl.target); sun.target.updateMatrixWorld(); R.setRenderTarget(null); R.setClearColor(0x191626, 1); R.clear(); R.render(scene, camera); R.setClearColor(0x000000, 0); return; } const buf = R.getDrawingBufferSize(new THREE.Vector2()); targetsFor(buf.x, buf.y); cloths.forEach(c => c.lines3d.visible = false); meshes.forEach(o => { o.material = o.userData.mats.painted; o.material.uniforms.uPass.value = 0; }); const G = GRADE[state.view === "bust" ? "bust" : "battle"]; // stage grade, shared by the characters and the stage for (const o of meshes) { const mu = o.material.uniforms; mu.uAmbient.value.set(...G.ambient); mu.uKeyCol.value.set(...G.key); mu.uRimCol.value.set(...G.rim); } // the info pass (roles, ids, depth) first: the colour pass reads it for cast shadows meshes.forEach(o => { // unbound while it is drawn: reading it now would be a feedback loop const mu = o.material.uniforms; mu.uPass.value = 1; mu.uCastOn.value = 0; mu.tCastInfo.value = null; mu.tCastDepth.value = null; }); R.setRenderTarget(targets.rtInfo); R.clear(); R.render(scene, camera); const ppmBuf = buf.y / (camera.top - camera.bottom) * camera.zoom; for (const o of meshes) { const mu = o.material.uniforms; mu.uPass.value = 0; mu.uCastOn.value = 1; mu.tCastInfo.value = targets.rtInfo.texture; mu.tCastDepth.value = targets.rtInfo.depthTexture; mu.uCastRes.value.set(buf.x, buf.y); mu.uCastNear.value = camera.near; mu.uCastFar.value = camera.far; mu.uCastPpm.value = ppmBuf; } R.setRenderTarget(targets.rt); R.clear(); R.render(scene, camera); const u = paint.mat.uniforms; u.tColor.value = targets.rt.texture; u.tInfo.value = targets.rtInfo.texture; u.tDepth.value = targets.rtInfo.depthTexture; u.uRes.value.set(buf.x, buf.y); u.uNear.value = camera.near; u.uFar.value = camera.far; // line weight follows the figure's size on screen (study: ~0.4% of its height) const ppm = buf.y / (camera.top - camera.bottom) * camera.zoom, dpr = R.getPixelRatio(); u.uSil.value = THREE.MathUtils.clamp(1.75 * ppm * 0.0042, dpr, 2.6 * dpr); u.uInner.value = Math.max(dpr * 0.75, u.uSil.value * 0.55); u.uPpm.value = ppm; R.setRenderTarget(null); R.clear(); R.render(paint.scene, compCam); } // ---- check sheets ---------------------------------------------------------------------------------------------------- // ?sheet=<name> poses one character through every check view; ?sheet=duel shows the bind. Each tile // is posed, its cloth settled at that angle, rendered by the same painted renderer as the page, and // drawn into one image, which lands in #sheetOut as a PNG data URL (a headless browser reads it). const ARMS_YAWS = [0, 45, 90, 135, 180, 270]; const CHAR_ROWS = [ // arms down, as character design sheets are drawn: the row to compare against references { label: "Reference pose", tiles: [0, 30, 90, 180, 270, 330].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°` })) }, { label: "Head", tiles: [0, 30, 90, 150, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.03, size: 0.42, hide: ["sword", "weapon"], label: `${y}°` })) }, { label: "Arms out", tiles: ARMS_YAWS.map(y => ({ clip: "apose", t: 0, yaw: y, label: `${y}°` })) }, { label: "Idle", tiles: ARMS_YAWS.map(y => ({ clip: "idle", t: 0, yaw: y, label: `${y}°` })) }, // the idle loop through time from one side (the camera holds still: the body's rise and sink shows) { label: "Idle loop", tiles: [0, 0.4, 0.8, 1.0, 1.3, 1.6].map(t => ({ clip: "idle", t, yaw: 300, label: `${t.toFixed(1)} s` })) }, { label: "Attack", tiles: [[0.32, "wind-up"], [0.56, "slash"], [0.68, "follow-through"]].flatMap(([t, n]) => [60, 300].map(y => ({ clip: "attack", t, yaw: y, label: `${n}, ${y}°` }))) }, { label: "Close-ups", tiles: [ { clip: "apose", t: 0, yaw: 0, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, front" }, { clip: "apose", t: 0, yaw: 90, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, side" }, { clip: "apose", t: 0, yaw: 180, focus: "J_Bip_C_Hips", dy: 0.10, size: 0.62, label: "waist, back" }, { clip: "idle", t: 0, yaw: 60, focus: "J_Bip_R_Hand", dy: 0, size: 0.45, label: "right wrist" }, { clip: "idle", t: 0, yaw: 300, focus: "J_Bip_L_Hand", dy: 0, size: 0.45, label: "left wrist" }, { clip: "idle", t: 0, yaw: 30, focus: "J_Bip_L_Foot", dy: 0.02, size: 0.5, label: "feet" }] }, // where a head meets its neck (grafted heads): from below the jaw, the side and behind, and mid-attack // when the head turns on the neck { label: "Neck and collar", tiles: [ ...[[0, -10, "front, from below"], [60, -10, "three-quarter"], [120, -4, "behind the ear"], [180, 0, "nape"]].map(([y, p, n]) => ({ clip: "ref", t: 0, yaw: y, pitch: p, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.30, hide: ["sword", "weapon"], label: n })), { clip: "attack", t: 0.32, yaw: 60, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.34, label: "wind-up, 60°" }, { clip: "attack", t: 0.56, yaw: 300, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.34, label: "slash, 300°" }] }, ]; // the armory (bodies, heads and hair to assemble from): the T-pose round, the head close, the joins const ARMORY_ROWS = [ { label: "T-pose", tiles: [0, 45, 90, 135, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, label: `${y}°` })) }, { label: "Head", tiles: [0, 30, 90, 150, 180, 270].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 4, focus: "J_Bip_C_Head", dy: 0.03, size: 0.42, label: `${y}°` })) }, { label: "Joins", tiles: [ ...[[0, -10, "neck, front"], [120, -4, "neck, behind the ear"]].map(([y, p, n]) => ({ clip: "ref", t: 0, yaw: y, pitch: p, focus: "J_Bip_C_Neck", dy: 0.03, size: 0.30, label: n })), { clip: "ref", t: 0, yaw: 0, focus: "J_Bip_L_UpperArm", dy: 0, size: 0.40, label: "shoulder, front" }, { clip: "ref", t: 0, yaw: 180, focus: "J_Bip_C_Hips", dy: -0.12, size: 0.55, label: "hips and thighs, back" }, { clip: "ref", t: 0, yaw: 0, focus: "J_Bip_C_Hips", dy: -0.12, size: 0.55, label: "hips and thighs, front" }, { clip: "ref", t: 0, yaw: 30, focus: "J_Bip_L_Foot", dy: 0.02, size: 0.5, label: "feet" }] }, ]; const DUEL_YAWS = [0, 40, 90, 320]; const LINEUP_ROWS = [ { label: "Lineup", tiles: [0, 30].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°, reference pose` })) }, { label: "Lineup", tiles: [90, 180].map(y => ({ clip: "ref", t: 0, yaw: y, pitch: 0, hide: ["sword", "weapon"], label: `${y}°, reference pose` })) }, { label: "Lineup", tiles: [20, 300].map(y => ({ clip: "idle", t: 0, yaw: y, label: `${y}°, idle` })) }, // faces with helmets and hoods off: the face structures underneath, one close-up each { label: "Faces (helmets and hoods off)", tw: 300, th: 340, tiles: LINEUP.order.map((n, i) => ({ clip: "ref", t: 0, yaw: 20, pitch: 0, hide: ["sword", "weapon", "helmet", "hood", "shield"], focusChar: i, size: 0.40, label: (charDef(n) || {}).label || n })) }, { label: "Faces (helmets on)", tw: 300, th: 340, tiles: LINEUP.order.map((n, i) => ({ clip: "ref", t: 0, yaw: 20, pitch: 0, hide: ["sword", "weapon", "shield"], focusChar: i, size: 0.40, label: (charDef(n) || {}).label || n })) }, ]; const DUEL_ROWS = [0, 0.8, 1.6].map(t => ({ label: `Clash ${t.toFixed(1)} s`, tiles: DUEL_YAWS.map(y => ({ clip: "clash", t, yaw: y, label: `${y}°` })) })) .concat([{ label: "The bind, close", tiles: [0, 90, 180, 300].map(y => ({ clip: "clash", t: 0, yaw: y, focusBind: true, size: 0.95, label: `${y}°` })) }]); function holdPose(clip, t) { for (const c of active()) { if (c.skeleton) c.skeleton.pose(); c.mixer.stopAllAction(); c.blend = null; c.clip = clip; if (clip === "ref") continue; // the reference (bind) pose itself const a = c.actions[clip] || c.actions.idle; a.reset(); a.setEffectiveWeight(1); a.play(); a.time = t; c.mixer.update(0); } scene.updateMatrixWorld(true); } function settleCloth() { const cs = active(); cs.forEach(c => c.cloths.forEach(cl => cl.reset(false))); for (let s = 0; s < 150; s++) cs.forEach(c => c.cloths.forEach(cl => cl.step(1 / 120, s / 120))); cs.forEach(c => c.cloths.forEach(cl => cl.write())); } function frameAt(centre, h, tw, th, pitch) { const w = h * tw / th, a = THREE.MathUtils.degToRad(pitch); camera.left = -w / 2; camera.right = w / 2; camera.top = h / 2; camera.bottom = -h / 2; camera.zoom = 1; camera.updateProjectionMatrix(); camera.position.copy(centre).add(new THREE.Vector3(0, Math.sin(a), Math.cos(a)).multiplyScalar(15)); camera.up.set(0, 1, 0); camera.lookAt(centre); ctl.target.copy(centre); } async function runSheet(kind) { document.body.classList.add("sheet"); const lineup = kind === "lineup", duel = kind === "duel" || lineup; if (!duel) state.who = kind; if (params.get("mode") === "3d") state.mode = "3d"; // ?mode=3d: the plain 3D renderer (tells a geometry fault from a shading one) await setView(lineup ? "lineup" : duel ? "duel" : "battle"); if ((!duel || lineup) && ground) { scene.remove(ground.root); } applyMaterials(); // ?rows=0,3 keeps some rows, ?scale=3 renders them larger (for side-by-sides against a reference) const keep = (params.get("rows") || "").split(",").filter(Boolean).map(Number); const scale = Math.max(1, Math.min(4, +(params.get("scale") || 1))); const rows = (lineup ? LINEUP_ROWS : duel ? DUEL_ROWS : PAGE && PAGE.armory ? ARMORY_ROWS : [...CHAR_ROWS]) .filter((r, i) => !keep.length || keep.includes(i)); if (!duel && !keep.length) { try { const chk = (await (await fetch("checks.json")).json())[kind]; const seen = new Set(), tiles = []; for (const it of chk.through) { const [limb] = it.hits[0], key = `${it.clip}@${it.t}`; if (seen.has(key) || tiles.length >= 6) continue; seen.add(key); for (const y of [60, 300]) tiles.push({ clip: it.clip, t: it.t, yaw: y, focus: `J_Bip_${limb.slice(0, 2)}LowerArm`, dy: 0, size: 0.75, label: `${it.clip} ${it.t} s, ${y}°` }); } // garments through plate: a close-up framed on the plate (two angles), reference pose first for (const it of (chk.layers ? chk.layers.items : [])) { const [, plate] = it.hits[0], key = `${it.clip}@${it.t}:${plate}`; if (seen.has(key) || tiles.length >= 10) continue; seen.add(key); const clip = it.clip === "reference pose" ? "ref" : it.clip; for (const y of [30, 330]) tiles.push({ clip, t: it.t, yaw: y, focusMesh: `OUTFIT_${plate}`, size: 0.5, label: `${plate}, ${it.clip === "reference pose" ? "as built" : it.clip + " " + it.t + " s"}, ${y}°` }); } if (tiles.length) rows.push({ label: "Flagged by the checks", tiles: tiles.slice(0, 6) }); if (tiles.length > 6) rows.push({ label: "Flagged by the checks (more)", tiles: tiles.slice(6, 12) }); } catch (e) { /* no checks: no row */ } } // the lineup's tiles shrink to stay under WebGL's largest drawing size (8192 here): past it they came out black const lw0 = Math.round(FIGURE.lineup.w / 2.5 * 480), lk = Math.min(1, 8000 / (lw0 * scale)), lw = Math.round(lw0 * lk); const tw = (lineup ? lw : duel ? 520 : 300) * scale, th = (duel ? 420 : lineup ? Math.round(520 * lk) : 520) * scale, lab = 22, rowHead = 30, gap = 6; const rw = r => (r.tw || tw / scale) * scale, rh = r => (r.th || th / scale) * scale; const cv = document.createElement("canvas"); cv.width = Math.max(...rows.map(r => r.tiles.length * (rw(r) + gap))) + gap; cv.height = rows.reduce((a, r) => a + rowHead + rh(r) + lab + gap, 0) + gap; const ctx = cv.getContext("2d"); ctx.fillStyle = "#100e18"; ctx.fillRect(0, 0, cv.width, cv.height); R.setPixelRatio(1); let y0 = gap; for (const row of rows) { const tw_ = rw(row), th_ = rh(row); R.setSize(tw_, th_, false); ctx.fillStyle = "#e9e6f2"; ctx.font = "bold 18px sans-serif"; ctx.fillText(`${lineup ? "Enemies" : duel ? "Duel" : charDef(kind).label} · ${row.label}`, gap + 2, y0 + 21); y0 += rowHead; row.tiles.forEach((tile, k) => { setYaw(tile.yaw); state.hidden = new Set(tile.hide || []); applyMaterials(); holdPose(tile.clip, tile.t); settleCloth(); let centre, h = tile.size || (lineup ? 2.5 : duel ? 2.3 : 2.05), pitch = tile.pitch ?? 8; if (tile.focusBind) { const hs = active().map(c => c.root.getObjectByName("J_Bip_R_Hand").getWorldPosition(new THREE.Vector3())); centre = hs[0].clone().add(hs[1]).multiplyScalar(0.5).add(new THREE.Vector3(0, 0.12, 0)); pitch = 4; } else if (tile.focusChar != null) { // one unit's head in the lineup centre = active()[tile.focusChar].root.getObjectByName("J_Bip_C_Head").getWorldPosition(new THREE.Vector3()); centre.y += 0.05; pitch = tile.pitch ?? 0; } else if (tile.focusMesh) { const m = active()[0].meshes.find(o => o.userData.material === tile.focusMesh); centre = m ? new THREE.Box3().setFromObject(m, true).getCenter(new THREE.Vector3()) : new THREE.Vector3(0, 1, 0); pitch = 4; } else if (tile.focus) { centre = active()[0].root.getObjectByName(tile.focus).getWorldPosition(new THREE.Vector3()); centre.y += tile.dy; pitch = tile.pitch ?? 4; } else { // follow the hips across the ground (a lunge steps out of a fixed frame) const p = duel ? new THREE.Vector3(0, 0, 0) : active()[0].root.getObjectByName("J_Bip_C_Hips").getWorldPosition(new THREE.Vector3()); centre = new THREE.Vector3(p.x, h / 2 - 0.06, p.z); } frameAt(centre, h, tw_, th_, pitch); render(); const x = gap + k * (tw_ + gap); ctx.drawImage(R.domElement, x, y0, tw_, th_); ctx.fillStyle = "#9c98b5"; ctx.font = "14px sans-serif"; ctx.fillText(tile.label, x + 4, y0 + th_ + 16); }); y0 += th_ + lab + gap; } $("sheetOut").textContent = cv.toDataURL("image/png"); document.title = "sheet ready"; } // ---- panel: checks and sheets ------------------------------------------------------------------------------------------ async function loadChecks() {