summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_conv5x5.wgsl')
-rw-r--r--workspaces/main/shaders/cnn/cnn_conv5x5.wgsl43
1 files changed, 43 insertions, 0 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
index 5136740..0f261dd 100644
--- a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
+++ b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
@@ -83,3 +83,46 @@ fn cnn_conv5x5_7to1(
return sum; // Output in [-1,1]
}
+
+// Source layer: 7→4 channels (RGBD output)
+// Normalizes [0,1] input to [-1,1] internally
+fn cnn_conv5x5_7to4_src(
+ tex: texture_2d<f32>,
+ samp: sampler,
+ uv: vec2<f32>,
+ resolution: vec2<f32>,
+ weights: array<array<f32, 8>, 100>
+) -> vec4<f32> {
+ let step = 1.0 / resolution;
+
+ let original = (textureSample(tex, samp, uv) - 0.5) * 2.0;
+ let gray = 0.2126*original.r + 0.7152*original.g + 0.0722*original.b;
+ let uv_norm = (uv - 0.5) * 2.0;
+
+ var sum = vec4<f32>(0.0);
+ var pos = 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 rgbd = (textureSample(tex, samp, uv + offset) - 0.5) * 2.0;
+
+ let inputs = array<f32, 7>(
+ rgbd.r, rgbd.g, rgbd.b, rgbd.a,
+ uv_norm.x, uv_norm.y, gray
+ );
+
+ for (var out_c = 0; out_c < 4; out_c++) {
+ let idx = pos * 4 + out_c;
+ var channel_sum = weights[idx][7];
+ for (var in_c = 0; in_c < 7; in_c++) {
+ channel_sum += weights[idx][in_c] * inputs[in_c];
+ }
+ sum[out_c] += channel_sum;
+ }
+ pos++;
+ }
+ }
+
+ return sum;
+}