summaryrefslogtreecommitdiff
path: root/doc/CNN_EFFECT.md
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-10 18:46:45 +0100
committerskal <pascal.massimino@gmail.com>2026-02-10 18:46:45 +0100
commitebceca338c902ffaa650f931a356c28a0659ebb1 (patch)
tree85d73014e606979185d1cbd54432a724eaca403a /doc/CNN_EFFECT.md
parent6d7c10a3d2929c594fe66f6a16234eef18e033a8 (diff)
refactor: Optimize CNN normalization to eliminate redundant conversions
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).
Diffstat (limited to 'doc/CNN_EFFECT.md')
-rw-r--r--doc/CNN_EFFECT.md14
1 files changed, 8 insertions, 6 deletions
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<f32>,
resolution: vec2<f32>,
- original: vec4<f32>, # Original RGBD [0,1]
+ original: vec4<f32>, # Original RGBD [-1,1]
weights: array<array<f32, 8>, 36> # 9 pos × 4 out × (7 weights + bias)
) -> vec4<f32>
@@ -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