Skip to content

Commit

Permalink
Rename model_matrix to mvp_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
erenoku committed Feb 12, 2023
1 parent e8b08a7 commit eb2ad39
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions crates/fj-viewer/src/graphics/navigation_cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use super::model::{self, load_model, DrawModel, Model};
pub struct NavigationCubeRenderer {
cube_model: Model,
render_pipeline: wgpu::RenderPipeline,
model_matrix_bind_group: wgpu::BindGroup,
model_matrix_buffer: wgpu::Buffer,
mvp_matrix_bind_group: wgpu::BindGroup,
mvp_matrix_buffer: wgpu::Buffer,
}

const SCALE_FACTOR: f64 = 0.13;
Expand Down Expand Up @@ -48,17 +48,17 @@ impl NavigationCubeRenderer {
label: Some("texture_bind_group_layout"),
});

let model_matrix =
Self::get_model_matrix(Transform::identity(), aspect_ratio);
let mvp_matrix =
Self::get_mvp_matrix(Transform::identity(), aspect_ratio);

let model_matrix_buffer =
let mvp_matrix_buffer =
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("Model Matrix Buffer"),
contents: bytemuck::cast_slice(&[model_matrix]),
contents: bytemuck::cast_slice(&[mvp_matrix]),
usage: wgpu::BufferUsages::UNIFORM
| wgpu::BufferUsages::COPY_DST,
});
let model_matrix_bind_group_layout =
let mvp_matrix_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
Expand All @@ -70,16 +70,16 @@ impl NavigationCubeRenderer {
},
count: None,
}],
label: Some("model_matrix_group_layout"),
label: Some("mvp_matrix_group_layout"),
});
let model_matrix_bind_group =
let mvp_matrix_bind_group =
device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &model_matrix_bind_group_layout,
layout: &mvp_matrix_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
binding: 0,
resource: model_matrix_buffer.as_entire_binding(),
resource: mvp_matrix_buffer.as_entire_binding(),
}],
label: Some("model_matrix_bind_group"),
label: Some("mvp_matrix_bind_group"),
});

let shader =
Expand All @@ -95,7 +95,7 @@ impl NavigationCubeRenderer {
label: Some("Render Pipeline Layout"),
bind_group_layouts: &[
&texture_bind_group_layout,
&model_matrix_bind_group_layout,
&mvp_matrix_bind_group_layout,
],
push_constant_ranges: &[],
});
Expand Down Expand Up @@ -150,8 +150,8 @@ impl NavigationCubeRenderer {
Self {
cube_model,
render_pipeline,
model_matrix_bind_group,
model_matrix_buffer,
mvp_matrix_bind_group,
mvp_matrix_buffer,
}
}

Expand All @@ -163,11 +163,11 @@ impl NavigationCubeRenderer {
aspect_ratio: f64,
rotation: Transform,
) {
let model_matrix = Self::get_model_matrix(rotation, aspect_ratio);
let mvp_matrix = Self::get_mvp_matrix(rotation, aspect_ratio);
queue.write_buffer(
&self.model_matrix_buffer,
&self.mvp_matrix_buffer,
0,
bytemuck::cast_slice(&[model_matrix]),
bytemuck::cast_slice(&[mvp_matrix]),
);

let mut render_pass =
Expand All @@ -184,11 +184,11 @@ impl NavigationCubeRenderer {
depth_stencil_attachment: None,
});
render_pass.set_pipeline(&self.render_pipeline);
render_pass.set_bind_group(1, &self.model_matrix_bind_group, &[]);
render_pass.set_bind_group(1, &self.mvp_matrix_bind_group, &[]);
render_pass.draw_model(&self.cube_model);
}

fn get_model_matrix(rotation: Transform, aspect_ratio: f64) -> [f32; 16] {
fn get_mvp_matrix(rotation: Transform, aspect_ratio: f64) -> [f32; 16] {
let scale = Transform::scale(SCALE_FACTOR);
let world_translation = Transform::translation([0.0, 0.0, -1.0]);

Expand Down
4 changes: 2 additions & 2 deletions crates/fj-viewer/src/graphics/navigation_cube.wgsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vertex shader

@group(1) @binding(0)
var<uniform> model_matrix: mat4x4<f32>;
var<uniform> mvp_matrix: mat4x4<f32>;

struct VertexInput {
@location(0) position: vec3<f32>,
Expand All @@ -19,7 +19,7 @@ fn vertex(
) -> VertexOutput {
var out: VertexOutput;
out.tex_coords = model.tex_coords;
out.clip_position = model_matrix * vec4<f32>(model.position, 1.0);
out.clip_position = mvp_matrix * vec4<f32>(model.position, 1.0);
return out;
}

Expand Down

0 comments on commit eb2ad39

Please sign in to comment.