Debian Codegraph @

examples/prism-wgsl.html

raw symbols SCIP
1 <h2>Full example</h2>
2 <pre><code>// Vertex shader
3 struct CameraUniform {
4 view_proj: mat4x4&lt;f32&gt;;
5 };
6 [[group(1), binding(0)]]
7 var&lt;uniform&gt; camera: CameraUniform;
8
9 struct InstanceInput {
10 [[location(5)]] model_matrix_0: vec4&lt;f32&gt;;
11 [[location(6)]] model_matrix_1: vec4&lt;f32&gt;;
12 [[location(7)]] model_matrix_2: vec4&lt;f32&gt;;
13 [[location(8)]] model_matrix_3: vec4&lt;f32&gt;;
14 };
15
16 struct VertexInput {
17 [[location(0)]] position: vec3&lt;f32&gt;;
18 [[location(1)]] tex_coords: vec2&lt;f32&gt;;
19 };
20
21 struct VertexOutput {
22 [[builtin(position)]] clip_position: vec4&lt;f32&gt;;
23 [[location(0)]] tex_coords: vec2&lt;f32&gt;;
24 };
25
26 @vertex
27 [[stage(vertex)]]
28 fn vs_main(
29 model: VertexInput,
30 instance: InstanceInput,
31 ) -&gt; VertexOutput {
32 let model_matrix = mat4x4&lt;f32&gt;(
33 instance.model_matrix_0,
34 instance.model_matrix_1,
35 instance.model_matrix_2,
36 instance.model_matrix_3,
37 );
38
39 bool mybool1 = true;
40 bool mybool2 = false;
41
42 var out: VertexOutput;
43 out.tex_coords = model.tex_coords;
44 out.clip_position = camera.view_proj * model_matrix * vec4&lt;f32&gt;(model.position, 1.0);
45 return out;
46 }
47
48 // Fragment shader
49
50 [[group(0), binding(0)]]
51 var t_diffuse: texture_2d&lt;f32&gt;;
52 [[group(0), binding(1)]]
53 var s_diffuse: sampler;
54
55 @fragment
56 [[stage(fragment)]]
57 fn fs_main(in: VertexOutput) -&gt; [[location(0)]] vec4&lt;f32&gt; {
58 return textureSample(t_diffuse, s_diffuse, in.tex_coords);
59 }
60 </code></pre>