summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_conv3x3.wgsl')
-rw-r--r--workspaces/main/shaders/cnn/cnn_conv3x3.wgsl26
1 files changed, 26 insertions, 0 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
new file mode 100644
index 0000000..06ca73a
--- /dev/null
+++ b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl
@@ -0,0 +1,26 @@
+// 3x3 convolution with weight indexing
+// Samples 9 pixels, applies mat4 weights per sample
+
+fn cnn_conv3x3(
+ tex: texture_2d<f32>,
+ samp: sampler,
+ uv: vec2<f32>,
+ resolution: vec2<f32>,
+ weights: array<mat4x4<f32>, 9>,
+ bias: vec4<f32>
+) -> vec4<f32> {
+ let step = 1.0 / resolution;
+ var sum = bias;
+ var idx = 0;
+
+ for (var dy = -1; dy <= 1; dy++) {
+ for (var dx = -1; dx <= 1; dx++) {
+ let offset = vec2<f32>(f32(dx), f32(dy)) * step;
+ let sample = textureSample(tex, samp, uv + offset);
+ sum += weights[idx] * sample;
+ idx++;
+ }
+ }
+
+ return sum;
+}