1
0
Fork 0
wgpu-rs/res/shaders/main.wgsl

49 lines
1.2 KiB
WebGPU Shading Language
Raw Normal View History

2022-06-12 22:18:35 +02:00
struct InstanceInput {
[[location(5)]] model_matrix_0: vec4<f32>;
[[location(6)]] model_matrix_1: vec4<f32>;
[[location(7)]] model_matrix_2: vec4<f32>;
[[location(8)]] model_matrix_3: vec4<f32>;
};
2022-06-12 21:47:11 +02:00
struct CameraUniform {
view_proj: mat4x4<f32>;
};
[[group(1), binding(0)]]
var<uniform> camera: CameraUniform;
2022-06-09 22:49:49 +02:00
struct VertexInput {
[[location(0)]] position: vec3<f32>;
2022-06-09 23:16:19 +02:00
[[location(1)]] tex_coords: vec2<f32>;
2022-06-09 22:49:49 +02:00
};
2022-06-09 13:38:07 +02:00
struct VertexOutput {
[[builtin(position)]] clip_position: vec4<f32>;
2022-06-09 23:16:19 +02:00
[[location(0)]] tex_coords: vec2<f32>;
2022-06-09 13:38:07 +02:00
};
[[stage(vertex)]]
fn vs_main(
2022-06-09 22:49:49 +02:00
model: VertexInput,
2022-06-12 22:18:35 +02:00
instance: InstanceInput,
2022-06-09 13:38:07 +02:00
) -> VertexOutput {
2022-06-12 22:18:35 +02:00
let model_matrix = mat4x4<f32>(
instance.model_matrix_0,
instance.model_matrix_1,
instance.model_matrix_2,
instance.model_matrix_3,
);
2022-06-09 13:38:07 +02:00
var out: VertexOutput;
2022-06-09 23:16:19 +02:00
out.tex_coords = model.tex_coords;
2022-06-12 22:18:35 +02:00
out.clip_position = camera.view_proj * model_matrix * vec4<f32>(model.position, 1.0);
2022-06-09 13:38:07 +02:00
return out;
}
2022-06-09 23:16:19 +02:00
[[group(0), binding(0)]]
var t_diffuse: texture_2d<f32>;
[[group(0), binding(1)]]
var s_diffuse: sampler;
2022-06-09 13:38:07 +02:00
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -> [[location(0)]] vec4<f32> {
2022-06-09 23:16:19 +02:00
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
2022-06-09 22:49:49 +02:00
}