diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-10 21:22:44 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-10 21:22:44 +0100 |
| commit | c6b70419010164539a8f41ad9d8ad70bd5b6ea4b (patch) | |
| tree | 0f0b0e42ad4a721ad8bbd5f8f73dfbc8d7db31a8 /workspaces | |
| parent | b25132133590e39967ebd0f3205123ee6628674b (diff) | |
fix: Correct UV coordinate computation to match PyTorch linspace
Critical mismatch: shader used pixel-center coordinates while PyTorch
uses pixel-corner coordinates, causing 0.5-pixel offset.
PyTorch: linspace(0, 1, H) → [0, 1/(H-1), ..., 1]
Shader: (p.xy - 0.5) / (resolution - 1.0) to match
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces')
| -rw-r--r-- | workspaces/main/shaders/cnn/cnn_layer.wgsl | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/workspaces/main/shaders/cnn/cnn_layer.wgsl b/workspaces/main/shaders/cnn/cnn_layer.wgsl index 8eccb26..d33a301 100644 --- a/workspaces/main/shaders/cnn/cnn_layer.wgsl +++ b/workspaces/main/shaders/cnn/cnn_layer.wgsl @@ -29,7 +29,8 @@ struct CNNLayerParams { } @fragment fn fs_main(@builtin(position) p: vec4<f32>) -> @location(0) vec4<f32> { - let uv = p.xy / uniforms.resolution; + // Match PyTorch linspace: pixel_idx / (size - 1), not pixel_center / size + let uv = (p.xy - 0.5) / (uniforms.resolution - 1.0); let original_raw = textureSample(original_input, smplr, uv); let original = (original_raw - 0.5) * 2.0; // Normalize to [-1,1] let gray = dot(original.rgb, vec3<f32>(0.2126, 0.7152, 0.0722)); |
