1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
// 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.
@group(0) @binding(0) var feat_tex0: texture_2d<u32>;
@group(0) @binding(1) var feat_tex1: texture_2d<u32>;
@group(0) @binding(2) var<uniform> uniforms: GBufDeferredUniforms;
struct GBufDeferredUniforms {
resolution: vec2f,
}
@vertex
fn vs_main(@builtin(vertex_index) vid: u32) -> @builtin(position) vec4f {
let x = f32((vid & 1u) << 2u) - 1.0;
let y = f32((vid & 2u) << 1u) - 1.0;
return vec4f(x, y, 0.0, 1.0);
}
@fragment
fn fs_main(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let coord = vec2i(pos.xy);
// 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);
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
return vec4f(albedo * shadow, 1.0);
}
|