-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.wgsl
46 lines (37 loc) · 807 Bytes
/
model.wgsl
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
46
struct VsIn {
@location(0) position: vec3<f32>,
};
struct VsOut {
@builtin(position) position: vec4<f32>,
@location(0) object_color: vec4<f32>,
};
struct Camera {
projection: mat4x4<f32>,
view: mat4x4<f32>,
position: vec3<f32>,
};
struct Model {
model_matrix: mat4x4<f32>,
color: vec4<f32>,
};
@group(0)
@binding(0)
var<uniform> camera: Camera;
@group(1)
@binding(0)
var<uniform> model: Model;
@vertex
fn vs_main(in: VsIn) -> VsOut {
let position = camera.projection * camera.view * model.model_matrix * vec4<f32>(in.position, 1.0);
return VsOut(
position,
model.color,
);
}
@group(0)
@binding(1)
var<uniform> light_color: vec4<f32>;
@fragment
fn fs_main(in: VsOut) -> @location(0) vec4<f32> {
return light_color * in.object_color;
}