Debian Codegraph @

third_party/rust/wgpu-hal/examples/halmark/shader.wgsl

raw
1 struct Globals {
2 mvp: mat4x4<f32>,
3 size: vec2<f32>,
4 _pad0: u32,
5 _pad1: u32,
6 };
7
8 struct Locals {
9 position: vec2<f32>,
10 velocity: vec2<f32>,
11 color: u32,
12 _pad0: u32,
13 _pad1: u32,
14 _pad2: u32,
15 };
16
17 @group(0)
18 @binding(0)
19 var<uniform> globals: Globals;
20
21 @group(1)
22 @binding(0)
23 var<uniform> locals: Locals;
24
25 struct VertexOutput {
26 @builtin(position) position: vec4<f32>,
27 @location(0) tex_coords: vec2<f32>,
28 @location(1) color: vec4<f32>,
29 };
30
31 @vertex
32 fn vs_main(@builtin(vertex_index) vi: u32) -> VertexOutput {
33 let tc = vec2<f32>(f32(vi & 1u), 0.5 * f32(vi & 2u));
34 let offset = vec2<f32>(tc.x * globals.size.x, tc.y * globals.size.y);
35 let pos = globals.mvp * vec4<f32>(locals.position + offset, 0.0, 1.0);
36 let color = vec4<f32>((vec4<u32>(locals.color) >> vec4<u32>(0u, 8u, 16u, 24u)) & vec4<u32>(255u)) / 255.0;
37 return VertexOutput(pos, tc, color);
38 }
39
40 @group(0)
41 @binding(1)
42 var tex: texture_2d<f32>;
43 @group(0)
44 @binding(2)
45 var sam: sampler;
46
47 @fragment
48 fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
49 return vertex.color * textureSampleLevel(tex, sam, vertex.tex_coords, 0.0);
50 }