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
40
41
42
43
44
45
-- Resource group block test: same binding shape as explicit @group attrs,
-- but grouped by workflow bucket.
struct VertexOutput
@builtin(position) position: vec4
uv: vec2
end
struct FragmentOutput
color: vec4
end
struct Camera
view_proj: mat4
position: vec3
end
struct Lighting
direction: vec3
color: vec3
intensity: float
end
group frame = 0
uniform camera: Camera
uniform lighting: Lighting
end
group material = 1
texture diffuse_tex: sampler2D
texture normal_tex: sampler2D
end
@entry(fragment)
function fs_main(input: VertexOutput) -> FragmentOutput
let diffuse = sample(diffuse_tex, input.uv)
let normal_sample = sample(normal_tex, input.uv)
let n = normalize(normal_sample.xyz * 2.0 - vec3(1.0, 1.0, 1.0))
let l = normalize(lighting.direction)
let ndotl = max(dot(n, l), 0.0)
let lit = diffuse.rgb * lighting.color * ndotl * lighting.intensity
return FragmentOutput {
color = vec4(lit, diffuse.a),
}
end