From ebceca338c902ffaa650f931a356c28a0659ebb1 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 18:46:45 +0100 Subject: refactor: Optimize CNN normalization to eliminate redundant conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Normalize textures once in fs_main instead of in every conv function. Keep all intermediate layers in [-1,1] range, denormalize only for final display. Changes: - train_cnn.py: Generator normalizes input once, keeps [-1,1] between layers - cnn_conv*.wgsl: Remove texture normalization (already [-1,1]) - cnn_layer.wgsl: Regenerated with new normalization flow - CNN_EFFECT.md: Updated documentation Eliminates redundant [0,1]↔[-1,1] conversions, reducing shader complexity. handoff(Claude): CNN normalization optimized, all tests passing (35/36). --- doc/CNN_EFFECT.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'doc/CNN_EFFECT.md') diff --git a/doc/CNN_EFFECT.md b/doc/CNN_EFFECT.md index b7d157f..d51c187 100644 --- a/doc/CNN_EFFECT.md +++ b/doc/CNN_EFFECT.md @@ -38,7 +38,7 @@ fn cnn_conv3x3_7to4( samp: sampler, uv: vec2, resolution: vec2, - original: vec4, # Original RGBD [0,1] + original: vec4, # Original RGBD [-1,1] weights: array, 36> # 9 pos × 4 out × (7 weights + bias) ) -> vec4 @@ -53,12 +53,14 @@ fn cnn_conv3x3_7to1( ) -> f32 ``` -**Input normalization (all to [-1,1]):** -- RGBD: `(rgbd - 0.5) * 2` -- UV coords: `(uv - 0.5) * 2` -- Grayscale: `(0.2126*R + 0.7152*G + 0.0722*B - 0.5) * 2` +**Input normalization:** +- **fs_main** normalizes textures once: `(tex - 0.5) * 2` → [-1,1] +- **Conv functions** normalize UV coords: `(uv - 0.5) * 2` → [-1,1] +- **Grayscale** computed from normalized RGBD: `0.2126*R + 0.7152*G + 0.0722*B` +- **Inter-layer data** stays in [-1,1] (no denormalization) +- **Final output** denormalized for display: `(result + 1.0) * 0.5` → [0,1] -**Activation:** tanh for inner layers, none for final layer +**Activation:** tanh for inner layers (output stays [-1,1]), none for final layer ### Multi-Layer Architecture -- cgit v1.2.3