summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders/cnn/cnn_layer.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_layer.wgsl')
-rw-r--r--workspaces/main/shaders/cnn/cnn_layer.wgsl31
1 files changed, 21 insertions, 10 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_layer.wgsl b/workspaces/main/shaders/cnn/cnn_layer.wgsl
index b2bab26..1b1b539 100644
--- a/workspaces/main/shaders/cnn/cnn_layer.wgsl
+++ b/workspaces/main/shaders/cnn/cnn_layer.wgsl
@@ -1,5 +1,6 @@
// CNN layer shader - uses modular convolution snippets
// Supports multi-pass rendering with residual connections
+// DO NOT EDIT - Generated by train_cnn.py
@group(0) @binding(0) var smplr: sampler;
@group(0) @binding(1) var txt: texture_2d<f32>;
@@ -7,16 +8,18 @@
#include "common_uniforms"
#include "cnn_activation"
#include "cnn_conv3x3"
+#include "cnn_conv5x5"
#include "cnn_weights_generated"
struct CNNLayerParams {
layer_index: i32,
- use_residual: i32,
+ blend_amount: f32,
_pad: vec2<f32>,
};
@group(0) @binding(2) var<uniform> uniforms: CommonUniforms;
@group(0) @binding(3) var<uniform> params: CNNLayerParams;
+@group(0) @binding(4) var original_input: texture_2d<f32>;
@vertex fn vs_main(@builtin(vertex_index) i: u32) -> @builtin(position) vec4<f32> {
var pos = array<vec2<f32>, 3>(
@@ -27,20 +30,28 @@ 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]
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_src(txt, smplr, uv, uniforms.resolution, weights_layer0);
+ result = cnn_tanh(result); // Keep in [-1,1]
}
-
- // Residual connection
- if (params.use_residual != 0) {
- let input = textureSample(txt, smplr, uv);
- result = input + result * 0.3;
+ 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]
}
+ else if (params.layer_index == 2) { // last layer
+ 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
+ }
return result;
}