summaryrefslogtreecommitdiff
path: root/cnn_v3/shaders
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-23 00:43:20 +0100
committerskal <pascal.massimino@gmail.com>2026-03-23 00:43:20 +0100
commit13cf1438caa56b34529d4031ddf73d38286b70e5 (patch)
treeb8de1b0a597edcbfadcea5fca862be4b3d72a3db /cnn_v3/shaders
parent1470dd240f48652d1fe97957fe44a49b0e1ee9a6 (diff)
feat(cnn_v3): shadow→dif migration complete (ch18)
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
Diffstat (limited to 'cnn_v3/shaders')
-rw-r--r--cnn_v3/shaders/gbuf_deferred.wgsl4
-rw-r--r--cnn_v3/shaders/gbuf_pack.wgsl8
-rw-r--r--cnn_v3/shaders/gbuf_view.wgsl20
3 files changed, 14 insertions, 18 deletions
diff --git a/cnn_v3/shaders/gbuf_deferred.wgsl b/cnn_v3/shaders/gbuf_deferred.wgsl
index bcc42cc..7257122 100644
--- a/cnn_v3/shaders/gbuf_deferred.wgsl
+++ b/cnn_v3/shaders/gbuf_deferred.wgsl
@@ -40,9 +40,9 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let normal = oct_decode(vec2f(bx.y, ny_d.x));
let diffuse = max(0.0, dot(normal, KEY_LIGHT));
- // feat_tex1[3] = pack4x8unorm(dif.r, dif.g, dif.b, spare) — dif = diffuse*shadow
+ // feat_tex1[2] = pack4x8unorm(mip2.g, mip2.b, dif, transp) — dif at byte 2
let t1 = textureLoad(feat_tex1, coord, 0);
- let dif = unpack4x8unorm(t1.w).x;
+ let dif = unpack4x8unorm(t1.z).z;
return vec4f(albedo * (AMBIENT + dif), 1.0);
}
diff --git a/cnn_v3/shaders/gbuf_pack.wgsl b/cnn_v3/shaders/gbuf_pack.wgsl
index dd8d73b..777b4e5 100644
--- a/cnn_v3/shaders/gbuf_pack.wgsl
+++ b/cnn_v3/shaders/gbuf_pack.wgsl
@@ -106,13 +106,13 @@ fn pack_features(@builtin(global_invocation_id) id: vec3u) {
// Texture 1: 4 u32, each = pack4x8unorm of four u8 values
// [0] mat_id | prev.r | prev.g | prev.b
// [1] mip1.r | mip1.g | mip1.b | mip2.r
- // [2] mip2.g | mip2.b | transp | (spare)
- // [3] dif.r | dif.g | dif.b | (spare) — dif = diffuse*shadow (scalar, stored in all 3)
+ // [2] mip2.g | mip2.b | dif | transp — ch18=dif, ch19=transp
+ // [3] spare
let t1 = vec4u(
pack4x8unorm(vec4f(mat_id_u8, prev.r, prev.g, prev.b)),
pack4x8unorm(vec4f(mip1.r, mip1.g, mip1.b, mip2.r)),
- pack4x8unorm(vec4f(mip2.g, mip2.b, transp, 0.0)),
- pack4x8unorm(vec4f(dif, dif, dif, 0.0))
+ pack4x8unorm(vec4f(mip2.g, mip2.b, dif, transp)),
+ 0u
);
textureStore(feat_tex1, coord, t1);
}
diff --git a/cnn_v3/shaders/gbuf_view.wgsl b/cnn_v3/shaders/gbuf_view.wgsl
index d53b6f6..6a812e6 100644
--- a/cnn_v3/shaders/gbuf_view.wgsl
+++ b/cnn_v3/shaders/gbuf_view.wgsl
@@ -1,5 +1,5 @@
-// G-buffer channel visualization — 4×6 grid of 23 feature channels.
-// Takes feat_tex0 (rgba32uint, ch 0-7 f16) and feat_tex1 (rgba32uint, ch 8-22 unorm8).
+// G-buffer channel visualization — 4×5 grid of 20 feature channels.
+// Takes feat_tex0 (rgba32uint, ch 0-7 f16) and feat_tex1 (rgba32uint, ch 8-19 unorm8).
// Outputs tiled channel view to a standard rgba8unorm render target.
//
// Channel layout (row×col):
@@ -7,8 +7,7 @@
// Row 1: ch4(nrm.y) ch5(depth) ch6(dzdx) ch7(dzdy)
// Row 2: ch8(matid) ch9(prv.r) ch10(prv.g) ch11(prv.b)
// Row 3: ch12(m1.r) ch13(m1.g) ch14(m1.b) ch15(m2.r)
-// Row 4: ch16(m2.g) ch17(m2.b) ch18(trns) ch19(spare)
-// Row 5: ch20(dif.r) ch21(dif.g) ch22(dif.b) ch23(spare)
+// Row 4: ch16(m2.g) ch17(m2.b) ch18(dif) ch19(trns)
#include "debug/debug_print"
@@ -30,12 +29,12 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let uv = pos.xy / u.resolution;
let COLS = 4.0;
- let ROWS = 6.0;
+ let ROWS = 5.0;
let col = u32(uv.x * COLS);
let row = u32(uv.y * ROWS);
let ch = row * 4u + col;
- if (col >= 4u || ch == 19u || ch >= 23u) {
+ if (col >= 4u || ch >= 20u) {
return vec4f(0.05, 0.05, 0.05, 1.0);
}
@@ -72,8 +71,7 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
var bytes: vec4f;
if (comp_idx == 0u) { bytes = unpack4x8unorm(t.x); }
else if (comp_idx == 1u) { bytes = unpack4x8unorm(t.y); }
- else if (comp_idx == 2u) { bytes = unpack4x8unorm(t.z); }
- else { bytes = unpack4x8unorm(t.w); }
+ else { bytes = unpack4x8unorm(t.z); }
var ba = array<f32, 4>(bytes.x, bytes.y, bytes.z, bytes.w);
v = ba[sub];
}
@@ -122,10 +120,8 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
case 15u: { out = debug_str(out, pos.xy, origin, vec4u(0x6D322E72u, 0u, 0u, 0u), 4u); } // m2.r
case 16u: { out = debug_str(out, pos.xy, origin, vec4u(0x6D322E67u, 0u, 0u, 0u), 4u); } // m2.g
case 17u: { out = debug_str(out, pos.xy, origin, vec4u(0x6D322E62u, 0u, 0u, 0u), 4u); } // m2.b
- case 18u: { out = debug_str(out, pos.xy, origin, vec4u(0x74726E73u, 0u, 0u, 0u), 4u); } // trns
- case 20u: { out = debug_str(out, pos.xy, origin, vec4u(0x6469662Eu, 0x72000000u, 0u, 0u), 5u); } // dif.r
- case 21u: { out = debug_str(out, pos.xy, origin, vec4u(0x6469662Eu, 0x67000000u, 0u, 0u), 5u); } // dif.g
- default: { out = debug_str(out, pos.xy, origin, vec4u(0x6469662Eu, 0x62000000u, 0u, 0u), 5u); } // dif.b
+ case 18u: { out = debug_str(out, pos.xy, origin, vec4u(0x64696600u, 0u, 0u, 0u), 3u); } // dif
+ default: { out = debug_str(out, pos.xy, origin, vec4u(0x74726E73u, 0u, 0u, 0u), 4u); } // trns
}
return out;
}