diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-10 21:01:47 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-10 21:01:47 +0100 |
| commit | 2fbfc406abe5a42f45face9b07a91ec64c0d4f78 (patch) | |
| tree | 2a65ffc385ad6edbdb24cf3c945bb701f601e1f3 /workspaces/main/shaders/cnn/cnn_layer.wgsl | |
| parent | bbef66d114ddd8091f79c8b27e6877c80236031b (diff) | |
update train_cnn.py and shader
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_layer.wgsl')
| -rw-r--r-- | workspaces/main/shaders/cnn/cnn_layer.wgsl | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_layer.wgsl b/workspaces/main/shaders/cnn/cnn_layer.wgsl index 1b1b539..3f970df 100644 --- a/workspaces/main/shaders/cnn/cnn_layer.wgsl +++ b/workspaces/main/shaders/cnn/cnn_layer.wgsl @@ -30,28 +30,27 @@ struct CNNLayerParams { @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { let uv = p.xy / uniforms.resolution; - let original = (textureSample(original_input, smplr, uv) - 0.5) * 2.0; // Normalize to [-1,1] + let original_raw = textureSample(original_input, smplr, uv); + let original = (original_raw - 0.5) * 2.0; // Normalize to [-1,1] var result = vec4<f32>(0.0); - // Layer 0: 7→4 (RGBD output) + // Layer 0: 7→4 (RGBD output, normalizes [0,1] input) if (params.layer_index == 0) { - result = cnn_conv3x3_7to4_src(txt, smplr, uv, uniforms.resolution, weights_layer0); - result = cnn_tanh(result); // Keep in [-1,1] + result = cnn_conv3x3_7to4_src(txt, smplr, uv, uniforms.resolution, + weights_layer0); + result = cnn_tanh(result); } else if (params.layer_index == 1) { result = cnn_conv5x5_7to4(txt, smplr, uv, uniforms.resolution, original, weights_layer1); - result = cnn_tanh(result); // Keep in [-1,1] + result = cnn_tanh(result); // Keep in [-1,1] } - else if (params.layer_index == 2) { // last layer + else if (params.layer_index == 2) { let gray_out = cnn_conv3x3_7to1(txt, smplr, uv, uniforms.resolution, - original, weights_layer2); - - // At this point here, 'gray_out' is what the training script should have learned. - // Below is some extra code for visual output, excluded from training: - result = vec4<f32>(gray_out, gray_out, gray_out, 1.0); // Keep in [-1,1] - let blended = mix(original, result, params.blend_amount); - return (blended + 1.0) * 0.5; // Denormalize to [0,1] for display + original, weights_layer2); + // gray_out already in [0,1] from clipped training + result = vec4<f32>(gray_out, gray_out, gray_out, 1.0); + return mix(original_raw, result, params.blend_amount); // [0,1] } - return result; + return result; // [-1,1] } |
