diff options
Diffstat (limited to 'workspaces/main/shaders/cnn/cnn_conv3x3.wgsl')
| -rw-r--r-- | workspaces/main/shaders/cnn/cnn_conv3x3.wgsl | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl index df58b4d..b895504 100644 --- a/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl +++ b/workspaces/main/shaders/cnn/cnn_conv3x3.wgsl @@ -53,6 +53,8 @@ fn cnn_conv3x3_with_coord( } // Inner layers: 7→4 channels (RGBD output) +// Assumes 'tex' and 'original' are already normalized to [-1,1] +// UV coordinates remain in [0,1] and are normalized internally // weights: array<array<f32, 8>, 36> (9 positions × 4 channels, each with 7 weights + bias) fn cnn_conv3x3_7to4( tex: texture_2d<f32>, @@ -64,9 +66,8 @@ fn cnn_conv3x3_7to4( ) -> vec4<f32> { let step = 1.0 / resolution; - // Compute grayscale from original and normalize to [-1,1] - let gray_01 = 0.2126*original.r + 0.7152*original.g + 0.0722*original.b; - let gray = (gray_01 - 0.5) * 2.0; + // Compute grayscale from original (already in [-1,1]) + let gray = 0.2126*original.r + 0.7152*original.g + 0.0722*original.b; // Normalize UV to [-1,1] let uv_norm = (uv - 0.5) * 2.0; @@ -77,10 +78,7 @@ fn cnn_conv3x3_7to4( for (var dy = -1; dy <= 1; dy++) { for (var dx = -1; dx <= 1; dx++) { let offset = vec2<f32>(f32(dx), f32(dy)) * step; - let rgbd_01 = textureSample(tex, samp, uv + offset); - - // Normalize RGBD to [-1,1] - let rgbd = (rgbd_01 - 0.5) * 2.0; + let rgbd = textureSample(tex, samp, uv + offset); // Already in [-1,1] // 7-channel input: [R,G,B,D, uv.x, uv.y, gray] all in [-1,1] let inputs = array<f32, 7>( @@ -106,6 +104,8 @@ fn cnn_conv3x3_7to4( } // Final layer: 7→1 channel (scalar output) +// Assumes 'tex' and 'original' are already normalized to [-1,1] +// UV coordinates remain in [0,1] and are normalized internally // weights: array<array<f32, 8>, 9> (9 positions, each with 7 weights + bias) fn cnn_conv3x3_7to1( tex: texture_2d<f32>, @@ -117,9 +117,8 @@ fn cnn_conv3x3_7to1( ) -> f32 { let step = 1.0 / resolution; - // Normalize grayscale to [-1,1] - let gray_01 = 0.2126*original.r + 0.7152*original.g + 0.0722*original.b; - let gray = (gray_01 - 0.5) * 2.0; + // Compute grayscale from original (already in [-1,1]) + let gray = 0.2126*original.r + 0.7152*original.g + 0.0722*original.b; // Normalize UV to [-1,1] let uv_norm = (uv - 0.5) * 2.0; @@ -130,10 +129,7 @@ fn cnn_conv3x3_7to1( for (var dy = -1; dy <= 1; dy++) { for (var dx = -1; dx <= 1; dx++) { let offset = vec2<f32>(f32(dx), f32(dy)) * step; - let rgbd_01 = textureSample(tex, samp, uv + offset); - - // Normalize RGBD to [-1,1] - let rgbd = (rgbd_01 - 0.5) * 2.0; + let rgbd = textureSample(tex, samp, uv + offset); // Already in [-1,1] // 7-channel input all in [-1,1] sum += weights[pos][0] * rgbd.r; |
