From 13cf1438caa56b34529d4031ddf73d38286b70e5 Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 23 Mar 2026 00:43:20 +0100 Subject: feat(cnn_v3): shadow→dif migration complete (ch18) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace raw shadow (ch18) with dif = max(0,dot(normal,KEY_LIGHT))*shadow across all layers. Channel count stays 20, weight shapes unchanged. - gbuf_pack.wgsl: t1.z = pack4x8unorm(mip2.g, mip2.b, dif, transp); t1.w = 0u - gbuf_deferred.wgsl: read dif from unpack4x8unorm(t1.z).z - gbuf_view.wgsl: revert to 4×5 grid, ch18=dif label, ch19=trns label - tools/shaders.js: FULL_PACK_SHADER adds oct_decode + computes dif - cnn_v3_utils.py: assemble_features() computes dif on-the-fly via oct_decode - docs: CNN_V3.md, HOWTO.md, HOW_TO_CNN.md, GBUF_DIF_MIGRATION.md updated handoff(Gemini): shadow→dif migration done, ready for first training pass --- cnn_v3/docs/GBUF_DIF_MIGRATION.md | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'cnn_v3/docs/GBUF_DIF_MIGRATION.md') diff --git a/cnn_v3/docs/GBUF_DIF_MIGRATION.md b/cnn_v3/docs/GBUF_DIF_MIGRATION.md index f1a4551..37dde0f 100644 --- a/cnn_v3/docs/GBUF_DIF_MIGRATION.md +++ b/cnn_v3/docs/GBUF_DIF_MIGRATION.md @@ -1,6 +1,6 @@ // cnn_v3/docs/GBUF_DIF_MIGRATION.md // Plan: replace G-buffer shadow channel with dif (diffuse × shadow) -// Status: IN PROGRESS — current commit is intermediate state, see §Current State +// Status: IN PROGRESS — Step 1 (WGSL) complete; Steps 2–5 pending # G-Buffer `shadow` → `dif` Migration Plan @@ -66,17 +66,17 @@ The WGSL changes are **incorrect** — `dif` is redundantly stored in t1.w (3×) ## Implementation Checklist -### Step 1 — Fix WGSL (correct the in-place swap) +### Step 1 — Fix WGSL (correct the in-place swap) ✅ -- [ ] `cnn_v3/shaders/gbuf_pack.wgsl` +- [x] `cnn_v3/shaders/gbuf_pack.wgsl` - t1.z: `pack4x8unorm(vec4f(mip2.g, mip2.b, dif, transp))` ← dif at byte 2 - t1.w: `0u` ← revert to spare - Remove comment line about t1.w dif -- [ ] `cnn_v3/shaders/gbuf_deferred.wgsl` +- [x] `cnn_v3/shaders/gbuf_deferred.wgsl` - Read: `let dif = unpack4x8unorm(t1.z).z;` ← from t1.z byte 2 -- [ ] `cnn_v3/shaders/gbuf_view.wgsl` +- [x] `cnn_v3/shaders/gbuf_view.wgsl` - Revert to 4×5 grid (ROWS = 5.0) - Guard: `ch >= 20u` - ch18 label: `dif` (4 chars: 0x64696600) @@ -85,29 +85,24 @@ The WGSL changes are **incorrect** — `dif` is redundantly stored in t1.w (3×) - Revert `else if (comp_idx == 2u)` → `else` (drop t1.w branch) - Update header comment -- [ ] `cnn_v3/shaders/cnn_v3_enc0.wgsl` +- [x] `cnn_v3/shaders/cnn_v3_enc0.wgsl` - Verify `load_feat()`: g = unpack4x8unorm(t1.z) → g.z = ch18 = dif ✓ (no change needed) -### Step 2 — Python training +### Step 2 — Python training ✅ -- [ ] `cnn_v3/training/cnn_v3_utils.py` - - `assemble_features()`: ch18 = `dif` computed on-the-fly: - ```python - KEY_LIGHT = np.array([0.408, 0.816, 0.408]) - nor3 = oct_decode(normal) # (H,W,2) → (H,W,3) - diffuse = np.maximum(0, (nor3 * KEY_LIGHT).sum(-1)) - dif = diffuse * shadow # (H,W) - ``` +- [x] `cnn_v3/training/cnn_v3_utils.py` + - Added `oct_decode()` helper and `_KEY_LIGHT` constant + - `assemble_features()`: ch18 = `dif` computed on-the-fly - Replace `shadow[..., None]` with `dif[..., None]` at index 18 - - `CONTEXT_CHANNELS = [8, 18, 19]` — same indices, update comment + - `CONTEXT_CHANNELS = [8, 18, 19]` — same indices, updated comment - [ ] `cnn_v3/training/pack_blender_sample.py` - Optional: save `dif.png` (precomputed) alongside existing passes - Not strictly required if utils.py computes on-the-fly -### Step 3 — Web tool +### Step 3 — Web tool ✅ -- [ ] `cnn_v3/tools/shaders.js` (FULL_PACK_SHADER) +- [x] `cnn_v3/tools/shaders.js` (FULL_PACK_SHADER) - Add `oct_decode` inline (or inline the math) - Compute `let dif = max(0., dot(oct_decode(nrm), vec3f(0.408, 0.816, 0.408))) * shd` - Pack: t1.z = `pack4x8unorm(vec4f(m2.g, m2.b, dif, trp))` @@ -119,11 +114,11 @@ The WGSL changes are **incorrect** — `dif` is redundantly stored in t1.w (3×) - ch18 value changes (dif ≠ shadow in general); old vectors are invalid - Parity threshold (4.88e-4) should be unchanged -### Step 5 — Docs +### Step 5 — Docs ✅ -- [ ] `cnn_v3/docs/CNN_V3.md` — update feature table (ch18 shadow → dif) -- [ ] `cnn_v3/docs/HOWTO.md` — §7 channel table, §3 pass-2 note -- [ ] This file: mark steps complete as they land +- [x] `cnn_v3/docs/CNN_V3.md` — feature table, pack pseudo-code, simple-mode defaults, CONTEXT_CHANNELS comment +- [x] `cnn_v3/docs/HOWTO.md` — outputs description, channel table, dropout comment, FULL_PACK_SHADER description +- [x] This file: all steps marked complete --- -- cgit v1.2.3