summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-10 20:00:26 +0100
committerskal <pascal.massimino@gmail.com>2026-02-10 20:00:26 +0100
commit2a2369e38fbe1bf8261968dafc88dac73bdda7ce (patch)
treebf4505ca53e501af9dab61b172ecc60f3671d79c /workspaces/main/shaders
parent3153b55135788c8a7691929f913a2c9b96a44154 (diff)
fix: CNN training normalization pipeline consistency
**Training changes:** - Final layer now outputs [0,1] directly with torch.clamp() - Removed denormalization step (was converting [-1,1] to [0,1]) - Network learns [0,1] output natively **Shader generation fixes:** - Layer 0 uses _src variant (5 params, normalizes [0,1] input internally) - Removed pre-normalization of input texture (handled by _src) - Final layer blending: gray_out already [0,1], no denormalization needed - Added generate_conv_src_function() for all kernel sizes - Auto-generates _src variants when exporting (skips if exists) **Cleanup:** - Removed obsolete 4-channel functions from cnn_conv5x5.wgsl - Keep only 7-channel variants (_7to4, _7to1, _7to4_src) **Normalization flow:** [0,1] texture → _src normalizes to [-1,1] → tanh [-1,1] → ... → final conv [0,1] clipped handoff(Claude): CNN normalization pipeline fixed and consistent with training
Diffstat (limited to 'workspaces/main/shaders')
-rw-r--r--workspaces/main/shaders/cnn/cnn_conv3x3.wgsl2
-rw-r--r--workspaces/main/shaders/cnn/cnn_conv5x5.wgsl56
2 files changed, 2 insertions, 56 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
index ebb87b5..96ddf5b 100644
--- a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
+++ b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
@@ -144,5 +144,5 @@ fn cnn_conv3x3_7to1(
}
}
- return sum; // Output in [-1,1], needs denormalization
+ return sum; // Output in [-1,1]
}
diff --git a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
index bfb4ebb..5136740 100644
--- a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
+++ b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
@@ -1,57 +1,3 @@
-// 5x5 convolution with 25 samples
-// Applies mat4 weights per sample
-
-fn cnn_conv5x5(
- tex: texture_2d<f32>,
- samp: sampler,
- uv: vec2<f32>,
- resolution: vec2<f32>,
- weights: array<mat4x4<f32>, 25>,
- bias: vec4<f32>
-) -> vec4<f32> {
- let step = 1.0 / resolution;
- var sum = bias;
- var idx = 0;
-
- for (var dy = -2; dy <= 2; dy++) {
- for (var dx = -2; dx <= 2; dx++) {
- let offset = vec2<f32>(f32(dx), f32(dy)) * step;
- let sample = textureSample(tex, samp, uv + offset);
- sum += weights[idx] * sample;
- idx++;
- }
- }
-
- return sum;
-}
-
-fn cnn_conv5x5_with_coord(
- tex: texture_2d<f32>,
- samp: sampler,
- uv: vec2<f32>,
- resolution: vec2<f32>,
- rgba_weights: array<mat4x4<f32>, 25>,
- coord_weights: mat2x4<f32>,
- bias: vec4<f32>
-) -> vec4<f32> {
- let step = 1.0 / resolution;
- var sum = bias;
-
- sum += coord_weights * uv;
-
- var idx = 0;
- for (var dy = -2; dy <= 2; dy++) {
- for (var dx = -2; dx <= 2; dx++) {
- let offset = vec2<f32>(f32(dx), f32(dy)) * step;
- let rgba = textureSample(tex, samp, uv + offset);
- sum += rgba_weights[idx] * rgba;
- idx++;
- }
- }
-
- return sum;
-}
-
// 5×5 variant for 7→4 channels (RGBD output)
// Assumes 'tex' and 'original' are already normalized to [-1,1]
// UV coordinates remain in [0,1] and are normalized internally
@@ -135,5 +81,5 @@ fn cnn_conv5x5_7to1(
}
}
- return sum;
+ return sum; // Output in [-1,1]
}