diff options
Diffstat (limited to 'cnn_v3/shaders/gbuf_pack.wgsl')
| -rw-r--r-- | cnn_v3/shaders/gbuf_pack.wgsl | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/cnn_v3/shaders/gbuf_pack.wgsl b/cnn_v3/shaders/gbuf_pack.wgsl index 71d8471..777b4e5 100644 --- a/cnn_v3/shaders/gbuf_pack.wgsl +++ b/cnn_v3/shaders/gbuf_pack.wgsl @@ -1,4 +1,5 @@ // G-buffer pack compute shader for CNN v3 +#include "math/normal" // Pass 4: Pack all G-buffer channels into two rgba32uint feature textures (32 bytes/pixel) // Output feat_tex0 holds 8×f16 geometric channels; feat_tex1 holds 12×u8 context channels. @@ -44,15 +45,6 @@ fn box4(tl: vec2i) -> vec3f { return acc * (1.0 / 16.0); } -// Decode oct-normal from [0,1] storage → [-1,1] encoded xy → reconstruct z. -fn decode_oct_normal(rg: vec2f) -> vec3f { - let f = rg * 2.0 - vec2f(1.0); - var n = vec3f(f.x, f.y, 1.0 - abs(f.x) - abs(f.y)); - let t = max(-n.z, 0.0); - n.x += select(t, -t, n.x >= 0.0); - n.y += select(t, -t, n.y >= 0.0); - return normalize(n); -} @compute @workgroup_size(8, 8) fn pack_features(@builtin(global_invocation_id) id: vec3u) { @@ -73,7 +65,7 @@ fn pack_features(@builtin(global_invocation_id) id: vec3u) { // Normal: stored as oct-encoded [0,1] in RG; extract just the encoded xy for feat_tex0 let normal_enc = nm.rg; // already in [0,1] — decode to get the xy for CNN input - let n3 = decode_oct_normal(normal_enc); + let n3 = oct_decode_unorm(normal_enc); // Store oct-encoded in [-1,1] remapped back to what CNN expects (the [-1,1] oct xy) let oct_xy = normal_enc * 2.0 - vec2f(1.0); // remap [0,1] → [-1,1] @@ -94,6 +86,9 @@ fn pack_features(@builtin(global_invocation_id) id: vec3u) { let mat_id_u8 = nm.b; // mat_id already in [0,1] let shadow = textureLoad(gbuf_shadow, coord, 0).r; let transp = textureLoad(gbuf_transp, coord, 0).r; + let nor = oct_decode_unorm(nm.rg); + let diffuse = max(0.0, dot(nor, vec3f(0.408, 0.816, 0.408))); + let dif = diffuse * shadow; let prev = textureSampleLevel(prev_cnn, bilinear_sampler, uv, 0.0).rgb; // MIP 1: 2×2 box filter (half resolution context) @@ -111,12 +106,12 @@ fn pack_features(@builtin(global_invocation_id) id: vec3u) { // Texture 1: 4 u32, each = pack4x8unorm of four u8 values // [0] mat_id | prev.r | prev.g | prev.b // [1] mip1.r | mip1.g | mip1.b | mip2.r - // [2] mip2.g | mip2.b | shadow | transp - // [3] spare (0) + // [2] mip2.g | mip2.b | dif | transp — ch18=dif, ch19=transp + // [3] spare let t1 = vec4u( pack4x8unorm(vec4f(mat_id_u8, prev.r, prev.g, prev.b)), pack4x8unorm(vec4f(mip1.r, mip1.g, mip1.b, mip2.r)), - pack4x8unorm(vec4f(mip2.g, mip2.b, shadow, transp)), + pack4x8unorm(vec4f(mip2.g, mip2.b, dif, transp)), 0u ); textureStore(feat_tex1, coord, t1); |
