agent (cont.)

+31:19
  • read_file{"Path":"~/work/lowmarch/review/slice/index.html"}

    input

    {
      "Path": "~/work/lowmarch/review/slice/index.html"
    }

    result, 710 lines

    Showing lines 1-709 of 709
    1: <!doctype html>
    2: <html lang="en">
    3: <head>
    4: <meta charset="utf-8">
    5: <meta name="viewport" content="width=device-width, initial-scale=1">
    6: <title>Battle Slice · Lowmarch</title>
    7: <style>
    8:   html, body { margin: 0; height: 100%; background: #1e1d26; color: #ece8e0; font-family: system-ui, sans-serif; overflow: hidden; }
    9:   #stage { position: fixed; inset: 0; display: grid; place-items: center; }
    10:   canvas { max-width: 100%; max-height: 100%; display: block; }
    11:   #sheetOut { display: none; }
    12: </style>
    13: <script type="importmap">
    14: {
    15:   "imports": {
    16:     "three": "./three/build/three.module.js",
    17:     "three/addons/": "./three/examples/jsm/"
    18:   }
    19: }
    20: </script>
    21: </head>
    22: <body>
    23: <div id="stage"></div>
    24: <pre id="sheetOut"></pre>
    25: <script type="module">
    26: import * as THREE from "three";
    27: import { GLTFLoader } from "three/addons/loaders/GLTFLoader.js";
    28: 
    29: const params = new URLSearchParams(location.search);
    30: const SHOT = params.has("shot");
    31: const SCENE = await (await fetch("scene.json")).json();
    32: 
    33: const stageEl = document.getElementById("stage");
    34: const R = new THREE.WebGLRenderer({ antialias: false, alpha: true, preserveDrawingBuffer: true });
    35: R.outputColorSpace = THREE.LinearSRGBColorSpace;
    36: R.setClearColor(0x000000, 0);
    37: stageEl.appendChild(R.domElement);
    38: 
    39: const hex = h => {
    40:   const n = parseInt(h.slice(1), 16);
    41:   return new THREE.Color().setRGB((n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255, THREE.LinearSRGBColorSpace);
    42: };
    43: const rawTex = t => { if (!t) return null; const c = t.clone(); c.colorSpace = THREE.NoColorSpace; c.needsUpdate = true; return c; };
    44: const white = (() => { const t = new THREE.DataTexture(new Uint8Array([255, 255, 255, 255]), 1, 1, THREE.RGBAFormat); t.needsUpdate = true; return t; })();
    45: 
    46: const R_ID = { face: 1, body: 2, hair: 3, iris: 4, white: 5, highlight: 6, line: 7, brow: 8, mouth: 9, hair_b: 11, hair_cap: 12, grass: 20, dirt: 21, stone: 22 };
    47: const roleId = r => R_ID[r] || 10;
    48: 
    49: const scene = new THREE.Scene();
    50: const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0.1, 40);
    51: 
    52: const SKIN_HEAD = `#include <common>
    53:   #include <skinning_pars_vertex>`;
    54: const SKIN_BODY = `#include <beginnormal_vertex>
    55:     #include <skinbase_vertex>
    56:     #include <skinnormal_vertex>
    57:     #include <begin_vertex>
    58:     #include <skinning_vertex>`;
    59: 
    60: const PAINT_VS = `${SKIN_HEAD}
    61:   attribute float edge; attribute vec4 _plate; uniform float uLift;
    62:   varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;
    63:   varying float vEdge; varying vec4 vPlate;
    64:   void main() {
    65:     ${SKIN_BODY}
    66:     vN = normalize(normalMatrix * objectNormal); vUv = uv; vObj = position; vEdge = edge; vPlate = _plate;
    67:     vec4 wp = modelMatrix * vec4(transformed, 1.0);
    68:     vWPos = wp.xyz;
    69:     vec4 mv = modelViewMatrix * vec4(transformed, 1.0); vView = -mv.xyz;
    70:     mv.z += uLift;
    71:     gl_Position = projectionMatrix * mv;
    72:   }`;
    73: 
    74: const HSV = `
    75:   vec3 rgb2hsv(vec3 c) {
    76:     vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
    77:     vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
    78:     vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
    79:     float d = q.x - min(q.w, q.y);
    80:     return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + 1e-10)), d / (q.x + 1e-10), q.x);
    81:   }
    82:   vec3 hsv2rgb(vec3 c) {
    83:     vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
    84:     vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
    85:     return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
    86:   }`;
    87: 
    88: const PAINT_FS = `
    89:   uniform int uKind; uniform vec3 uBase; uniform vec3 uKey; uniform sampler2D uMap; uniform int uAlpha;
    90:   uniform int uPass; uniform vec4 uInfo; uniform vec3 uEye[3]; uniform vec3 uFlat; uniform vec3 uSkinRef;
    91:   uniform vec3 uGold; uniform vec3 uAmbient; uniform vec3 uKeyCol; uniform vec3 uRimCol; uniform float uGrain;
    92:   uniform int uFaceTex; uniform int uDecal; uniform vec3 uMotif; uniform vec3 uBand; uniform vec3 uSkinTone; uniform int uShadeOnly;
    93:   uniform int uSkinRamp; uniform vec3 uSkinL; uniform vec3 uSkinS; uniform vec3 uSkinC;
    94:   uniform float uCrownY;
    95:   uniform vec2 uFootA; uniform vec2 uFootB; uniform vec2 uFootC; uniform vec2 uFootD;
    96:   uniform sampler2D tCastInfo; uniform sampler2D tCastDepth; uniform vec2 uCastRes; uniform int uCastOn;
    97:   uniform float uCastNear; uniform float uCastFar; uniform float uCastPpm;
    98: 
    99:   float castShadow(int selfRole) {
    100:     vec2 uv = gl_FragCoord.xy / uCastRes, px = 1.0 / uCastRes;
    101:     float z0 = uCastNear + texture2D(tCastDepth, uv).x * (uCastFar - uCastNear);
    102:     float sxy = length(uKey.xy);
    103:     if (sxy < 0.05) return 0.0;
    104:     vec2 dir = uKey.xy / sxy;
    105:     float lz = uKey.z / sxy;
    106:     int steps = selfRole == 1 ? 8 : 15;
    107:     float stepM = selfRole == 1 ? 0.0026 : 0.0032;
    108:     for (int s = 1; s <= 15; s++) {
    109:       if (s > steps) break;
    110:       float dm = float(s) * stepM;
    111:       vec2 q = uv + dir * dm * uCastPpm * px;
    112:       vec4 ni = texture2D(tCastInfo, q);
    113:       if (ni.a < 0.5) continue;
    114:       int r = int(ni.r * 255.0 + 0.5);
    115:       if (selfRole == 1) {
    116:         if (r != 3 && r != 11 && r != 12) continue;
    117:       } else {
    118:         if (r != 1 && r != 3 && r != 11 && r != 12) continue;
    119:       }
    120:       float zq = uCastNear + texture2D(tCastDepth, q).x * (uCastFar - uCastNear);
    121:       float zr = z0 - lz * dm;
    122:       if (zq < zr - 0.004 && zq > zr - 0.22) return 1.0;
    123:     }
    124:     return 0.0;
    125:   }
    126: 
    127:   varying vec3 vN; varying vec2 vUv; varying vec3 vView; varying vec3 vObj; varying vec3 vWPos;
    128:   varying float vEdge; varying vec4 vPlate;
    129:   ${HSV}
    130:   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)); }
    131:   float vnoise(vec3 x) {
    132:     vec3 i = floor(x), f = fract(x); f = f * f * (3.0 - 2.0 * f);
    133:     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),
    134:                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);
    135:   }
    136:   float toward(float h, float target, float amt) { float d = target - h; d -= floor(d + 0.5); return fract(h + clamp(d, -amt, amt)); }
    137:   vec3 tone(vec3 base, float hue, float amt, float sMul, float vMul) {
    138:     vec3 h = rgb2hsv(base);
    139:     return hsv2rgb(vec3(toward(h.x, hue, amt), clamp(h.y * sMul, 0.0, 1.0), clamp(h.z * vMul, 0.0, 1.0)));
    140:   }
    141:   float st(float x, float t) { return smoothstep(t - 0.025, t + 0.025, x); }
    142: 
    143:   vec3 metal(bool gold, vec3 base, vec3 n, vec3 v, float lit, float hgt) {
    144:     vec3 r = reflect(-v, n);
    145:     vec3 s0, s1, s2, s3;
    146:     if (!gold) {
    147:       s0 = tone(base, 0.65, 0.09, 1.9, 0.40);
    148:       s1 = tone(base, 0.65, 0.05, 1.35, 0.72);
    149:       s2 = tone(base, 0.12, 0.0, 0.82, 0.94);
    150:       s3 = vec3(0.98, 0.97, 0.94);
    151:     } else {
    152:       s0 = vec3(0.32, 0.21, 0.16);
    153:       s1 = tone(base, 0.11, 0.03, 1.08, 0.72);
    154:       s2 = base;
    155:       s3 = tone(base, 0.13, 0.03, 0.50, 1.48);
    156:     }
    157:     // Clean painted cel metal: vertical sky-earth reflection + key light cel step + crisp specular
    158:     float sky = smoothstep(-0.45, 0.45, r.y);
    159:     float grad = hgt >= 0.0 ? clamp(sky * 0.45 + hgt * 0.65 - 0.06, 0.0, 1.0)
    160:                             : clamp(sky * 0.65 + n.y * 0.28 + 0.08, 0.0, 1.0);
    161:     vec3 body = mix(s1, s2, grad);
    162:     vec3 shaded = mix(s0, s1 * 0.94, grad * 0.75);
    163:     vec3 col = mix(shaded, body, st(lit, 0.42));
    164:     float hl = dot(n, normalize(uKey + v));
    165:     float specMask = hgt >= 0.0 ? smoothstep(0.25, 0.65, hgt) : 1.0;
    166:     col = mix(col, mix(s2, s3, 0.72), st(hl, 0.91) * specMask * st(lit, 0.50));
    167:     return col;
    168:   }
    169: 
    170:   void main() {
    171:     vec4 tex = texture2D(uMap, vUv);
    172:     if (uAlpha == 1 && tex.a < 0.5) discard;
    173:     if (uAlpha == 2 && (tex.a < 0.5 || dot(tex.rgb, vec3(1.0 / 3.0)) >= 0.42)) discard;
    174:     if (uPass == 1) { gl_FragColor = uInfo; return; }
    175: 
    176:     bool back = !gl_FrontFacing;
    177:     vec3 n = normalize(vN); if (back) n = -n;
    178:     vec3 v = normalize(vView);
    179:     float lit = dot(n, uKey) * 0.5 + 0.5;
    180:     int selfRole = int(uInfo.x * 255.0 + 0.5);
    181: 
    182:     if (uShadeOnly == 1) {
    183:       lit = 0.12;
    184:     } else if (uCastOn == 1 && uKind == 1 && (selfRole == 1 || selfRole == 2)) {
    185:       if (castShadow(selfRole) > 0.5) lit = min(lit, 0.34);
    186:     }
    187: 
    188:     float g1 = vnoise(vObj * 40.0), g2 = vnoise(vObj * 150.0);
    189:     vec3 col;
    190:     if (uKind == 0 || uKind == 5 || uKind == 6) {
    191:       vec3 hb = rgb2hsv(uBase);
    192:       bool cool = hb.x > 0.42 && hb.x < 0.86;
    193:       float sh = uKind == 5 ? 0.93 : (cool ? 0.68 : 0.96);
    194:       float li = cool ? 0.55 : 0.12;
    195:       vec3 c0 = tone(uBase, sh, 0.08, 1.12, 0.42), c1 = tone(uBase, sh, 0.05, 1.08, 0.66);
    196:       vec3 c3 = tone(uBase, li, 0.03, 0.82, 1.18);
    197:       float l = lit + (g1 - 0.5) * uGrain - (uKind == 6 ? 0.20 : 0.0);
    198:       if (uKind == 6) {
    199:         // Contact shadow on ground beneath planted feet
    200:         vec2 xz = vWPos.xz;
    201:         float da = length((xz - uFootA) * vec2(1.0, 1.35));
    202:         float db = length((xz - uFootB) * vec2(1.0, 1.35));
    203:         float dc = length((xz - uFootC) * vec2(1.0, 1.35));
    204:         float dd = length((xz - uFootD) * vec2(1.0, 1.35));
    205:         float dmin = min(min(da, db), min(dc, dd));
    206:         float contact = 1.0 - smoothstep(0.08, 0.30, dmin);
    207:         l -= 0.36 * contact;
    208:       }
    209:       col = mix(c0, c1, st(l, 0.32)); col = mix(col, uBase, st(l, 0.50)); col = mix(col, c3, st(l, 0.90));
    210:       if (uKind == 5) col *= 0.965 + 0.07 * vnoise(vObj * 22.0);
    211:     } else if (uKind == 1) {
    212:       // Skin: genuine 3/4 shadow plane (threshold 0.50 instead of 0.38) + warm hue-shifted ramp
    213:       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);
    214:       if (uSkinRamp == 1) { sL = uSkinL; sS = uSkinS; sC = uSkinC; }
    215:       col = mix(sC, sS, st(lit, 0.24)); col = mix(col, sL, st(lit, 0.50));
    216:       if (uFaceTex == 1) col *= clamp(tex.rgb / uSkinRef, 0.58, 1.04);
    217:       if (uFaceTex == 1 && vUv.x > 0.37 && vUv.x < 0.63 && vUv.y > 0.68 && vUv.y < 0.84) {
    218:         float d = 0.0, sl = dot(uSkinRef, vec3(1.0 / 3.0));
    219:         for (int k = -2; k <= 2; k++) for (int j = -2; j <= 2; j++) {
    220:           vec3 t = texture2D(uMap, vUv + vec2(float(j) * 1.1, float(k) * 0.9) / 512.0).rgb;
    221:           d = max(d, 1.0 - dot(t, vec3(1.0 / 3.0)) / sl);
    222:         }
    223:         float taper = 1.0 - 0.45 * smoothstep(0.038, 0.068, abs(vUv.x - 0.5));
    224:         vec3 lipInk = mix(sC * 0.68, vec3(0.32, 0.14, 0.15), 0.55);
    225:         col = mix(col, lipInk, smoothstep(0.09, 0.20, d) * taper);
    226:       }
    227:       if (uSkinRamp == 0) col *= uSkinTone;
    228:     } else if (uKind == 2) {
    229:       // Calm 2-tone cel hair + dark inner backfaces + one restrained crown halo band
    230:       float strand = dot(tex.rgb, vec3(1.0 / 3.0));
    231:       vec3 c0 = tone(uBase, 0.70, 0.06, 1.12, 0.38);
    232:       vec3 c1 = tone(uBase, 0.70, 0.04, 1.06, 0.66);
    233:       vec3 c2 = tone(uBase, 0.12, 0.02, 0.78, 1.24);
    234:       if (back || uShadeOnly == 1 || selfRole == 12) {
    235:         col = c0;
    236:       } else {
    237:         float l = lit + (strand - 0.58) * 0.035;
    238:         col = mix(c0, c1, st(l, 0.28));
    239:         col = mix(col, uBase, st(l, 0.48));
    240:         // Clean horizontal anime halo band around upper crown locks
    241:         float dy = (vWPos.y - uCrownY);
    242:         float bandMask = exp(-pow(dy / 0.028, 2.0)) * smoothstep(0.54, 0.68, lit);
    243:         float sp = dot(n, normalize(uKey + v)) + (strand - 0.58) * 0.04;
    244:         float halo = bandMask * smoothstep(0.76, 0.86, sp);
    245:         col = mix(col, c2, 0.62 * halo);
    246:       }
    247:     } else if (uKind == 3 || uKind == 4) {
    248:       bool plate = vPlate.x > 0.5;
    249:       float e = vPlate.y, w = vPlate.z;
    250:       bool gilt = uKind == 4 || (plate && w > 0.0 && e < w);
    251:       col = metal(gilt, gilt && uKind == 3 ? uGold : uBase, n, v, lit, plate ? vPlate.w : -1.0);
    252:       if (plate && w > 0.0) {
    253:         float aa = fwidth(e) * 1.2 + 1e-5;
    254:         float l1 = 1.0 - smoothstep(0.0010, 0.0010 + aa, abs(e - (w + 0.0050)));
    255:         float l2 = 1.0 - smoothstep(0.0006, 0.0006 + aa, abs(e - w));
    256:         col = mix(col, col * 0.42, max(l1, l2 * 0.8));
    257:       }
    258:     } else if (uKind == 7) {
    259:       float l = dot(tex.rgb, vec3(1.0 / 3.0));
    260:       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));
    261:     } else if (uKind == 8) { col = tex.rgb; }
    262:     else if (uKind == 10) {
    263:       float lum = dot(tex.rgb, vec3(1.0 / 3.0));
    264:       col = mix(vec3(0.36, 0.11, 0.14), vec3(0.78, 0.38, 0.42), smoothstep(0.53, 0.58, tex.g));
    265:       col = mix(col, vec3(0.98, 0.96, 0.95), smoothstep(0.80, 0.86, lum));
    266:     } else { col = uFlat; }
    267: 
    268:     if (vPlate.x > 0.5 && vPlate.z > 0.0 && uKind != 3 && uKind != 4) {
    269:       float e = vPlate.y, w = vPlate.z, aa = fwidth(e) * 1.2 + 1e-5;
    270:       float band = 1.0 - smoothstep(w - aa, w, e);
    271:       float l1 = 1.0 - smoothstep(0.0006, 0.0006 + aa, abs(e - (w + 0.0040)));
    272:       col = mix(col, metal(true, uGold, n, v, lit, -1.0), max(band, l1 * 0.9));
    273:     }
    274:     if (uDecal == 1) {
    275:       vec3 dm = tex.rgb;
    276:       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);
    277:       if (au > 0.0) col = mix(col, metal(true, uGold, n, v, lit, -1.0), au);
    278:       if (pm > 0.0) {
    279:         vec3 pc = mix(tone(uMotif, 0.70, 0.05, 1.10, 0.62), uMotif, st(lit, 0.42));
    280:         col = mix(col, mix(pc, tone(uMotif, 0.56, 0.03, 0.8, 1.25), st(lit, 0.92)), pm);
    281:       }
    282:       if (gm > 0.0) col = mix(col, col * 0.30, gm);
    283:     }
    284:     if (vEdge > 0.5) {
    285:       vec3 gd = tone(uBand, 0.20, 0.03, 1.0, 0.72);
    286:       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));
    287:     }
    288:     if (uKind <= 6) {
    289:       vec3 grade = mix(uAmbient, uKeyCol, st(lit, 0.52));
    290:       col *= uKind == 1 && uSkinRamp == 1 ? mix(vec3(1.0), grade, 0.25) : grade;
    291:       float fr = pow(1.0 - max(dot(n, v), 0.0), 4.2);
    292:       float rimBack = clamp(dot(n, normalize(vec3(0.55, 0.45, -0.35))), 0.0, 1.0);
    293:       col += uRimCol * fr * smoothstep(0.12, 0.55, rimBack) * (uKind == 1 ? 0.45 : 0.85);
    294:       if (uKind != 1 && uKind != 2) col *= 1.0 + (g2 - 0.5) * 0.05;
    295:     }
    296:     gl_FragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
    297:   }`;
    298: 
    299: const PAINT_COMP = `
    300:   uniform sampler2D tColor; uniform sampler2D tInfo; uniform sampler2D tDepth; uniform vec2 uRes;
    301:   uniform float uNear; uniform float uFar; uniform float uGap; uniform float uSil; uniform float uInner; uniform float uPpm;
    302:   ${HSV}
    303:   float z(vec2 p) { return uNear + texture2D(tDepth, p).x * (uFar - uNear); }
    304:   int rid(vec4 i) { return int(i.r * 255.0 + 0.5); }
    305:   float pid(vec4 i) { return floor(i.g * 255.0 + 0.5) + floor(i.b * 255.0 + 0.5) * 256.0; }
    306:   vec3 ink(vec3 c) { vec3 h = rgb2hsv(c); return hsv2rgb(vec3(h.x, clamp(h.y, 0.20, 0.45), 0.18)); }
    307: 
    308:   vec3 backdrop(vec2 uv) {
    309:     // Painted dusk-parchment SRPG stage backdrop (replaces pitch-black #0e0d12 void)
    310:     vec3 skyTop = vec3(0.22, 0.27, 0.36);
    311:     vec3 skyMid = vec3(0.46, 0.47, 0.52);
    312:     vec3 horizon = vec3(0.76, 0.69, 0.60);
    313:     vec3 lowMist = vec3(0.58, 0.54, 0.50);
    314:     vec3 underEarth = vec3(0.15, 0.14, 0.18);
    315: 
    316:     float y = uv.y;
    317:     vec3 bg = mix(horizon, skyMid, smoothstep(0.22, 0.62, y));
    318:     bg = mix(bg, skyTop, smoothstep(0.58, 0.98, y));
    319: 
    320:     // Distant painted ridge line above the turf horizon
    321:     float ridge1 = 0.215 + 0.024 * sin(uv.x * 5.2 + 0.8) + 0.012 * sin(uv.x * 13.0 + 2.1);
    322:     float ridge2 = 0.185 + 0.016 * sin(uv.x * 7.8 + 3.4) + 0.008 * cos(uv.x * 19.0);
    323:     vec3 rCol1 = vec3(0.38, 0.40, 0.46);
    324:     vec3 rCol2 = vec3(0.30, 0.33, 0.38);
    325:     bg = mix(bg, mix(rCol1, horizon, 0.38), 1.0 - smoothstep(ridge1 - 0.004, ridge1 + 0.004, y));
    326:     bg = mix(bg, mix(rCol2, lowMist, 0.25), 1.0 - smoothstep(ridge2 - 0.003, ridge2 + 0.003, y));
    327:     bg = mix(underEarth, bg, smoothstep(0.05, 0.13, y));
    328:     // Subtle vignette at extreme left/right corners
    329:     float vig = smoothstep(0.0, 0.35, 1.0 - length((uv - vec2(0.5, 0.52)) * vec2(0.85, 0.95)));
    330:     return bg * mix(0.86, 1.0, vig);
    331:   }
    332: 
    333:   void main() {
    334:     vec2 uv = gl_FragCoord.xy / uRes, px = 1.0 / uRes;
    335:     vec4 inf = texture2D(tInfo, uv);
    336:     if (inf.a < 0.5) {
    337:       vec4 best = vec4(0.0); vec2 bq = uv;
    338:       for (int k = 0; k < 12; k++) {
    339:         float a = float(k) * 0.5236;
    340:         for (int s = 1; s <= 2; s++) {
    341:           vec2 q = uv + vec2(cos(a), sin(a)) * uSil * float(s) * 0.5 * px;
    342:           vec4 ni = texture2D(tInfo, q);
    343:           if (ni.a > 0.5) { best = ni; bq = q; }
    344:         }
    345:       }
    346:       if (best.a > 0.5) {
    347:         int r = rid(best);
    348:         if (r >= 4 && r <= 7) { gl_FragColor = vec4(backdrop(uv), 1.0); return; }
    349:         gl_FragColor = vec4(ink(texture2D(tColor, bq).rgb), 1.0); return;
    350:       }
    351:       gl_FragColor = vec4(backdrop(uv), 1.0); return;
    352:     }
    353: 
    354:     vec3 col = texture2D(tColor, uv).rgb; int r0 = rid(inf); float p0 = pid(inf); float z0 = z(uv);
    355:     bool feature = r0 >= 4 && r0 <= 9;
    356:     if (!feature) {
    357:       for (int k = 0; k < 4; k++) {
    358:         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)));
    359:         vec2 q = uv + d * px * uInner;
    360:         vec4 ni = texture2D(tInfo, q);
    361:         if (ni.a > 0.5 && z(q) > z0 + uGap && pid(ni) != p0) { col = ink(col); break; }
    362:       }
    363:       float acc = 0.0, rad = uSil * 2.8;
    364:       for (int k = 0; k < 8; k++) {
    365:         float a = float(k) * 0.785398 + 0.39;
    366:         vec2 q = uv + vec2(cos(a), sin(a)) * rad * px;
    367:         vec4 ni = texture2D(tInfo, q);
    368:         if (ni.a > 0.5) acc += clamp((z0 - z(q)) / 0.05, 0.0, 1.0);
    369:       }
    370:       col *= 1.0 - 0.18 * acc / 8.0;
    371:     }
    372:     gl_FragColor = vec4(col, 1.0);
    373:   }`;
    374: 
    375: const compCam = new THREE.Camera();
    376: function compPass(fs, uniforms) {
    377:   const mat = new THREE.ShaderMaterial({
    378:     uniforms,
    379:     vertexShader: `void main() { gl_Position = vec4(position.xy, 0.0, 1.0); }`,
    380:     fragmentShader: fs, depthTest: false, depthWrite: false
    381:   });
    382:   const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), mat);
    383:   const sc = new THREE.Scene(); sc.add(quad);
    384:   return { scene: sc, mat };
    385: }
    386: const paint = compPass(PAINT_COMP, {
    387:   tColor: { value: null }, tInfo: { value: null }, tDepth: { value: null },
    388:   uRes: { value: new THREE.Vector2() }, uNear: { value: 0.1 }, uFar: { value: 40 },
    389:   uGap: { value: 0.012 }, uSil: { value: 2.0 }, uInner: { value: 1.0 }, uPpm: { value: 1.0 }
    390: });
    391: 
    392: const targets = { rt: null, rtInfo: null, key: "" };
    393: function targetsFor(w, h) {
    394:   const key = `${w}x${h}`;
    395:   if (targets.key === key) return;
    396:   [targets.rt, targets.rtInfo].forEach(t => t && t.dispose());
    397:   const o = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter };
    398:   targets.rt = new THREE.WebGLRenderTarget(w, h, o);
    399:   targets.rtInfo = new THREE.WebGLRenderTarget(w, h, { ...o, depthTexture: new THREE.DepthTexture(w, h) });

    310 more lines not shown.

agent

+31:26
reasoning

The code in review/slice/index.html has a probable indexing error on line 419 within the len function: r[3*a+1] - r[3*a+1] should likely be r[3*b+1]. This would impact the hypotenuse calculation, suggesting a bug in distance computation.

  • edit_file{"Path":"~/work/lowmarch/review/slice/index.html","Replacement":" const len = ([a, b]) => Math.hypot(r[3*a] - r[3*b], r[3*a+1] - r[3*b+1], r[3*a+2] - r[3*b+2]);","Target":" const len = ([a, b]) => Math.hypot(r[3*a] - r[3*b], r[3*a+1] - r[3*a+1], r[3*a+2] - r[3*b+2]);"}

    input

    {
      "Path": "~/work/lowmarch/review/slice/index.html",
      "Replacement": "    const len = ([a, b]) => Math.hypot(r[3*a] - r[3*b], r[3*a+1] - r[3*b+1], r[3*a+2] - r[3*b+2]);",
      "Target": "    const len = ([a, b]) => Math.hypot(r[3*a] - r[3*b], r[3*a+1] - r[3*a+1], r[3*a+2] - r[3*b+2]);"
    }

    result, 1 line

    Made 1 replacement in ~/work/lowmarch/review/slice/index.html starting at line 419 (+1/-1 lines).