runmat_plot/gpu/shaders/vertex/
triangle.rs1pub const SHADER: &str = r#"// Triangle vertex shader for surfaces and filled plots
2
3struct Uniforms {
4 view_proj: mat4x4<f32>,
5 model: mat4x4<f32>,
6 normal_matrix: mat3x4<f32>,
7}
8
9@group(0) @binding(0)
10var<uniform> uniforms: Uniforms;
11
12struct VertexInput {
13 @location(0) position: vec3<f32>,
14 @location(1) color: vec4<f32>,
15 @location(2) normal: vec3<f32>,
16 @location(3) tex_coords: vec2<f32>,
17}
18
19struct VertexOutput {
20 @builtin(position) clip_position: vec4<f32>,
21 @location(0) color: vec4<f32>,
22 @location(1) world_position: vec3<f32>,
23 @location(2) normal: vec3<f32>,
24 @location(3) tex_coords: vec2<f32>,
25}
26
27@vertex
28fn vs_main(input: VertexInput) -> VertexOutput {
29 var out: VertexOutput;
30
31 let world_position = uniforms.model * vec4<f32>(input.position, 1.0);
32 out.clip_position = uniforms.view_proj * world_position;
33 out.world_position = world_position.xyz;
34 out.color = input.color;
35 // normal_matrix is mat3x4 for alignment (see Rust side). In WGSL, mat3x4 * vec3 -> vec4.
36 out.normal = normalize((uniforms.normal_matrix * input.normal).xyz);
37 out.tex_coords = input.tex_coords;
38
39 return out;
40}
41
42@fragment
43fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
44 // Flat colors for 2D plotting (no lighting)
45 return input.color;
46}
47"#;