Fix render pass viewport in custom_shader example
This commit is contained in:
parent
5195a59e20
commit
56bb4ce721
2 changed files with 18 additions and 16 deletions
|
|
@ -33,9 +33,7 @@ pub const OPENGL_TO_WGPU_MATRIX: glam::Mat4 = mat4(
|
||||||
|
|
||||||
impl Camera {
|
impl Camera {
|
||||||
pub fn build_view_proj_matrix(&self, bounds: Rectangle) -> glam::Mat4 {
|
pub fn build_view_proj_matrix(&self, bounds: Rectangle) -> glam::Mat4 {
|
||||||
//TODO looks distorted without padding; base on surface texture size instead?
|
let aspect_ratio = bounds.width / bounds.height;
|
||||||
let aspect_ratio = bounds.width / (bounds.height + 150.0);
|
|
||||||
|
|
||||||
let view = glam::Mat4::look_at_rh(self.eye, self.target, self.up);
|
let view = glam::Mat4::look_at_rh(self.eye, self.target, self.up);
|
||||||
let proj = glam::Mat4::perspective_rh(
|
let proj = glam::Mat4::perspective_rh(
|
||||||
self.fov_y,
|
self.fov_y,
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,7 @@ impl Pipeline {
|
||||||
&self,
|
&self,
|
||||||
target: &wgpu::TextureView,
|
target: &wgpu::TextureView,
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
viewport: Rectangle<u32>,
|
clip_bounds: Rectangle<u32>,
|
||||||
num_cubes: u32,
|
num_cubes: u32,
|
||||||
show_depth: bool,
|
show_depth: bool,
|
||||||
) {
|
) {
|
||||||
|
|
@ -390,11 +390,13 @@ impl Pipeline {
|
||||||
occlusion_query_set: None,
|
occlusion_query_set: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
pass.set_scissor_rect(
|
pass.set_viewport(
|
||||||
viewport.x,
|
clip_bounds.x as f32,
|
||||||
viewport.y,
|
clip_bounds.y as f32,
|
||||||
viewport.width,
|
clip_bounds.width as f32,
|
||||||
viewport.height,
|
clip_bounds.height as f32,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
);
|
);
|
||||||
pass.set_pipeline(&self.pipeline);
|
pass.set_pipeline(&self.pipeline);
|
||||||
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
|
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
|
||||||
|
|
@ -404,7 +406,7 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
if show_depth {
|
if show_depth {
|
||||||
self.depth_pipeline.render(encoder, target, viewport);
|
self.depth_pipeline.render(encoder, target, clip_bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -562,7 +564,7 @@ impl DepthPipeline {
|
||||||
&self,
|
&self,
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
target: &wgpu::TextureView,
|
target: &wgpu::TextureView,
|
||||||
viewport: Rectangle<u32>,
|
clip_bounds: Rectangle<u32>,
|
||||||
) {
|
) {
|
||||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: Some("cubes.pipeline.depth_pass"),
|
label: Some("cubes.pipeline.depth_pass"),
|
||||||
|
|
@ -586,11 +588,13 @@ impl DepthPipeline {
|
||||||
occlusion_query_set: None,
|
occlusion_query_set: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
pass.set_scissor_rect(
|
pass.set_viewport(
|
||||||
viewport.x,
|
clip_bounds.x as f32,
|
||||||
viewport.y,
|
clip_bounds.y as f32,
|
||||||
viewport.width,
|
clip_bounds.width as f32,
|
||||||
viewport.height,
|
clip_bounds.height as f32,
|
||||||
|
0.0,
|
||||||
|
1.0,
|
||||||
);
|
);
|
||||||
pass.set_pipeline(&self.pipeline);
|
pass.set_pipeline(&self.pipeline);
|
||||||
pass.set_bind_group(0, &self.bind_group, &[]);
|
pass.set_bind_group(0, &self.bind_group, &[]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue