summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-10 10:27:44 +0100
committerskal <pascal.massimino@gmail.com>2026-02-10 10:27:44 +0100
commit96a349b9874c6cdaac525ba062a0f4f90c9bc3ed (patch)
treea4eb24fdb417393cbe5a0dc84bf5063cffc94daf /workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
parent75af266889b61b5722d842a1a1eb23f79bc06a85 (diff)
feat: Add coordinate-aware CNN layer 0 for position-dependent stylization
- Implement CoordConv2d custom layer accepting (x,y) patch center - Split layer 0 weights: rgba_weights (9x mat4x4) + coord_weights (mat2x4) - Add *_with_coord() functions to 3x3/5x5/7x7 convolution shaders - Update training script to generate coordinate grid and export split weights - Regenerate placeholder weights with new format Size impact: +32B coord weights + ~100B shader code = +132B total All 36 tests passing (100%) handoff(Claude): CNN coordinate awareness implemented, ready for training Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_conv5x5.wgsl')
-rw-r--r--workspaces/main/shaders/cnn/cnn_conv5x5.wgsl27
1 files changed, 27 insertions, 0 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
index 3d4a03a..bd9abfa 100644
--- a/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
+++ b/workspaces/main/shaders/cnn/cnn_conv5x5.wgsl
@@ -24,3 +24,30 @@ fn cnn_conv5x5(
return sum;
}
+
+fn cnn_conv5x5_with_coord(
+ tex: texture_2d<f32>,
+ samp: sampler,
+ uv: vec2<f32>,
+ resolution: vec2<f32>,
+ rgba_weights: array<mat4x4<f32>, 25>,
+ coord_weights: mat2x4<f32>,
+ bias: vec4<f32>
+) -> vec4<f32> {
+ let step = 1.0 / resolution;
+ var sum = bias;
+
+ sum += coord_weights * uv;
+
+ var idx = 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 rgba = textureSample(tex, samp, uv + offset);
+ sum += rgba_weights[idx] * rgba;
+ idx++;
+ }
+ }
+
+ return sum;
+}