Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix render pass viewport in custom_shader example #2738

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/custom_shader/src/scene/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ pub const OPENGL_TO_WGPU_MATRIX: glam::Mat4 = mat4(

impl Camera {
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 + 150.0);

let aspect_ratio = bounds.width / (bounds.height);
let view = glam::Mat4::look_at_rh(self.eye, self.target, self.up);
let proj = glam::Mat4::perspective_rh(
self.fov_y,
Expand Down
30 changes: 17 additions & 13 deletions examples/custom_shader/src/scene/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl Pipeline {
&self,
target: &wgpu::TextureView,
encoder: &mut wgpu::CommandEncoder,
viewport: Rectangle<u32>,
clip_bounds: Rectangle<u32>,
num_cubes: u32,
show_depth: bool,
) {
Expand Down Expand Up @@ -390,11 +390,13 @@ impl Pipeline {
occlusion_query_set: None,
});

pass.set_scissor_rect(
viewport.x,
viewport.y,
viewport.width,
viewport.height,
pass.set_viewport(
clip_bounds.x as f32,
clip_bounds.y as f32,
clip_bounds.width as f32,
clip_bounds.height as f32,
0.0,
1.0,
);
pass.set_pipeline(&self.pipeline);
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
Expand All @@ -404,7 +406,7 @@ impl Pipeline {
}

if show_depth {
self.depth_pipeline.render(encoder, target, viewport);
self.depth_pipeline.render(encoder, target, clip_bounds);
}
}
}
Expand Down Expand Up @@ -562,7 +564,7 @@ impl DepthPipeline {
&self,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
viewport: Rectangle<u32>,
clip_bounds: Rectangle<u32>,
) {
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("cubes.pipeline.depth_pass"),
Expand All @@ -585,11 +587,13 @@ impl DepthPipeline {
occlusion_query_set: None,
});

pass.set_scissor_rect(
viewport.x,
viewport.y,
viewport.width,
viewport.height,
pass.set_viewport(
clip_bounds.x as f32,
clip_bounds.y as f32,
clip_bounds.width as f32,
clip_bounds.height as f32,
0.0,
1.0,
);
pass.set_pipeline(&self.pipeline);
pass.set_bind_group(0, &self.bind_group, &[]);
Expand Down