diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-10 17:37:01 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-10 17:37:01 +0100 |
| commit | f3c7ef8cd612f5ac908f39310c4c11566879313f (patch) | |
| tree | 1e66127a855f30282c852731c0dd88ae6c7039bc /workspaces/main/shaders/cnn/cnn_layer.wgsl | |
| parent | 0aa35e895d70f4535b7fac0f5df318888a6847dc (diff) | |
fix: Support variable kernel sizes in CNN layer generation
Training script was hardcoded to generate cnn_conv3x3_* calls regardless
of actual kernel size, causing shader validation errors when layer 1 used
5×5 kernel (100 weights) but called 3×3 function (expected 36).
Changes:
- train_cnn.py: Generate correct conv function based on kernel_sizes[i]
- cnn_conv5x5.wgsl: Add cnn_conv5x5_7to4 and cnn_conv5x5_7to1 variants
- Regenerate cnn_layer.wgsl with correct function calls for [3,5,3]
- Document kernel size→function mapping in HOWTO.md
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_layer.wgsl')
| -rw-r--r-- | workspaces/main/shaders/cnn/cnn_layer.wgsl | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_layer.wgsl b/workspaces/main/shaders/cnn/cnn_layer.wgsl index 5834f78..fad283c 100644 --- a/workspaces/main/shaders/cnn/cnn_layer.wgsl +++ b/workspaces/main/shaders/cnn/cnn_layer.wgsl @@ -8,6 +8,7 @@ #include "common_uniforms" #include "cnn_activation" #include "cnn_conv3x3" +#include "cnn_conv5x5" #include "cnn_weights_generated" struct CNNLayerParams { @@ -33,24 +34,33 @@ struct CNNLayerParams { let original = textureSample(original_input, smplr, uv); var result = vec4<f32>(0.0); - // Layer 0 uses coordinate-aware convolution + // Layer 0: 7→4 (RGBD output) if (params.layer_index == 0) { - result = cnn_conv3x3_with_coord(txt, smplr, uv, uniforms.resolution, - rgba_weights_layer0, coord_weights_layer0, bias_layer0); - result = cnn_tanh(result); + result = cnn_conv3x3_7to4(txt, smplr, uv, uniforms.resolution, + original, weights_layer0); + result = cnn_tanh(result); // Output in [-1,1] + // Denormalize to [0,1] for texture storage + result = (result + 1.0) * 0.5; } else if (params.layer_index == 1) { - result = cnn_conv3x3(txt, smplr, uv, uniforms.resolution, - weights_layer1, bias_layer1); - result = cnn_tanh(result); + result = cnn_conv5x5_7to4(txt, smplr, uv, uniforms.resolution, + original, weights_layer1); + result = cnn_tanh(result); // Output in [-1,1] + // Denormalize to [0,1] for texture storage + result = (result + 1.0) * 0.5; } else if (params.layer_index == 2) { - result = cnn_conv3x3(txt, smplr, uv, uniforms.resolution, - weights_layer2, bias_layer2); + let gray_out = cnn_conv3x3_7to1(txt, smplr, uv, uniforms.resolution, + original, weights_layer2); + // Denormalize from [-1,1] to [0,1] + let gray_01 = (gray_out + 1.0) * 0.5; + result = vec4<f32>(gray_01, gray_01, gray_01, 1.0); // Expand to RGB } else { result = input; } - return mix(original, result, params.blend_amount); + // Blend with ORIGINAL input from layer 0 +return original; +// return mix(original, result, params.blend_amount); } |
