summaryrefslogtreecommitdiff
path: root/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-13 16:48:02 +0100
committerskal <pascal.massimino@gmail.com>2026-02-13 16:48:02 +0100
commitced248b0a8973db6d11b79e8290e2f5bb17ffcaa (patch)
tree938899c02408895124fb8e9751dbd36b50d4a0ba /workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl
parent3eed58f0cd602298681a2313946ba2a5824d6c6e (diff)
CNN v2: Add mip-level support to runtime effect
Binary format v2 includes mip_level in header (20 bytes, was 16). Effect reads mip_level and passes to static features shader via uniform. Shader samples from correct mip texture based on mip_level. Changes: - export_cnn_v2_weights.py: Header v2 with mip_level field - cnn_v2_effect.h: Add StaticFeatureParams, mip_level member, params buffer - cnn_v2_effect.cc: Read mip_level from weights, create/bind params buffer, update per-frame - cnn_v2_static.wgsl: Accept params uniform, sample from selected mip level Binary format v2: - Header: 20 bytes (magic, version=2, num_layers, total_weights, mip_level) - Backward compatible: v1 weights load with mip_level=0 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl')
-rw-r--r--workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl25
1 files changed, 20 insertions, 5 deletions
diff --git a/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl b/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl
index 7a9e6de..f71fad2 100644
--- a/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl
+++ b/workspaces/main/shaders/cnn_v2/cnn_v2_static.wgsl
@@ -1,13 +1,19 @@
// CNN v2 Static Features Compute Shader
// Generates 8D parametric features: [p0, p1, p2, p3, uv.x, uv.y, sin10_x, bias]
-// p0-p3: Parametric features (currently RGBD from mip0, could be mip1/2, gradients, etc.)
+// p0-p3: Parametric features from specified mip level (0=mip0, 1=mip1, 2=mip2, 3=mip3)
// Note: Input image RGBD (mip0) fed separately to Layer 0
+struct StaticFeatureParams {
+ mip_level: u32,
+ padding: vec3<u32>,
+}
+
@group(0) @binding(0) var input_tex: texture_2d<f32>;
@group(0) @binding(1) var input_tex_mip1: texture_2d<f32>;
@group(0) @binding(2) var input_tex_mip2: texture_2d<f32>;
@group(0) @binding(3) var depth_tex: texture_2d<f32>;
@group(0) @binding(4) var output_tex: texture_storage_2d<rgba32uint, write>;
+@group(0) @binding(5) var<uniform> params: StaticFeatureParams;
@compute @workgroup_size(8, 8)
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
@@ -18,10 +24,19 @@ fn main(@builtin(global_invocation_id) id: vec3<u32>) {
return;
}
- // Parametric features (p0-p3)
- // TODO: Experiment with mip1 grayscale, Sobel gradients, etc.
- // For now, use RGBD from mip 0 (same as input, but could differ)
- let rgba = textureLoad(input_tex, coord, 0);
+ // Parametric features (p0-p3) - sample from specified mip level
+ var rgba: vec4<f32>;
+ if (params.mip_level == 0u) {
+ rgba = textureLoad(input_tex, coord, 0);
+ } else if (params.mip_level == 1u) {
+ rgba = textureLoad(input_tex_mip1, coord, 0);
+ } else if (params.mip_level == 2u) {
+ rgba = textureLoad(input_tex_mip2, coord, 0);
+ } else {
+ // Mip 3 or higher: use mip 2 as fallback
+ rgba = textureLoad(input_tex_mip2, coord, 0);
+ }
+
let p0 = rgba.r;
let p1 = rgba.g;
let p2 = rgba.b;