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
-- Test: Specialization constants across all backends
@spec(0) const NUM_LIGHTS: int = 4
@spec(1) const BRIGHTNESS: float = 1.0
@spec(2) const USE_GAMMA: bool = true
struct Uniforms
base_color: vec3
ambient: float
end
@varying
struct VertexOutput
@builtin(position) position: vec4
end
@group(0) @binding(0) uniform uniforms: Uniforms
@entry(vertex)
function vs_main(@location(0) position: vec3) -> VertexOutput
return VertexOutput {
position = vec4(position, 1.0),
}
end
@entry(fragment)
function fs_main(@location(0) frag_coord: vec4) -> (color: vec4)
let color = uniforms.base_color * uniforms.ambient
-- Use spec constants in computation
let i = 0
while i < NUM_LIGHTS do
color = color + vec3(0.1, 0.1, 0.1)
i = i + 1
end
color = color * BRIGHTNESS
return _fs_main_Output { color = vec4(color, 1.0) }
end