Instancing

This commit is contained in:
Werner
2021-11-03 19:16:23 -03:00
parent 20e0028e10
commit a0392e676b
3 changed files with 135 additions and 3 deletions

View File

@ -1,5 +1,12 @@
// Vertex shader
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>;
};
[[block]]
struct CameraUniform {
view_proj: mat4x4<f32>;
@ -21,10 +28,19 @@ struct VertexOutput {
[[stage(vertex)]]
fn main(
model: VertexInput,
instance: InstanceInput,
) -> VertexOutput {
let model_matrix = mat4x4<f32>(
instance.model_matrix_0,
instance.model_matrix_1,
instance.model_matrix_2,
instance.model_matrix_3,
);
var out: VertexOutput;
out.tex_coords = model.tex_coords;
out.clip_position = camera.view_proj * vec4<f32>(model.position, 1.0); // 3.
out.clip_position = camera.view_proj * model_matrix * vec4<f32>(model.position, 1.0);
return out;
}