From f99109e315f704c64d1deb4d5a0c5424d20924d2 Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 22 Mar 2026 20:18:37 +0100 Subject: fix(cnn_v3): deferred render — diffuse only, drop broken shadow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cnn_v3/shaders/gbuf_deferred.wgsl | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cnn_v3/shaders/gbuf_deferred.wgsl b/cnn_v3/shaders/gbuf_deferred.wgsl index 959ab60..fffe5b9 100644 --- a/cnn_v3/shaders/gbuf_deferred.wgsl +++ b/cnn_v3/shaders/gbuf_deferred.wgsl @@ -1,6 +1,8 @@ -// G-buffer deferred render — albedo * shadow -// Reads feat_tex0 (rgba32uint, f16 geometric) and feat_tex1 (rgba32uint, u8 context). -// Unpacks albedo and shadow and outputs albedo * shadow. +// G-buffer deferred render — albedo * diffuse +// Reads feat_tex0 (rgba32uint, f16 geometric). +// Outputs albedo * (ambient + diffuse). + +#include "math/normal" @group(0) @binding(0) var feat_tex0: texture_2d; @group(0) @binding(1) var feat_tex1: texture_2d; @@ -10,6 +12,9 @@ struct GBufDeferredUniforms { resolution: vec2f, } +const KEY_LIGHT: vec3f = vec3f(0.408, 0.816, 0.408); // normalize(1,2,1) +const AMBIENT: f32 = 0.15; + @vertex fn vs_main(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f { let x = f32((vid & 1u) << 2u) - 1.0; @@ -23,17 +28,17 @@ fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f { // feat_tex0 layout: // [0] pack2x16float(albedo.r, albedo.g) - // [1] pack2x16float(albedo.b, normal.x) - let t0 = textureLoad(feat_tex0, coord, 0); - let rg = unpack2x16float(t0.x); - let bx = unpack2x16float(t0.y); + // [1] pack2x16float(albedo.b, normal.x) oct [-1,1] + // [2] pack2x16float(normal.y, depth) oct [-1,1] + let t0 = textureLoad(feat_tex0, coord, 0); + let rg = unpack2x16float(t0.x); + let bx = unpack2x16float(t0.y); + let ny_d = unpack2x16float(t0.z); let albedo = vec3f(rg.x, rg.y, bx.x); - // feat_tex1 layout: - // [2] pack4x8unorm(mip2.g, mip2.b, shadow, transp) - let t1 = textureLoad(feat_tex1, coord, 0); - let ctx2 = unpack4x8unorm(t1.z); - let shadow = ctx2.z; // shadow is the third byte + // Decode oct-normal (stored in [-1,1] — use oct_decode directly) + let normal = oct_decode(vec2f(bx.y, ny_d.x)); + let diffuse = max(0.0, dot(normal, KEY_LIGHT)); - return vec4f(albedo * shadow, 1.0); + return vec4f(albedo * (AMBIENT + diffuse), 1.0); } -- cgit v1.2.3