Skip to content

Commit 28ca3a5

Browse files
authored
Merge pull request #2738 from jsatka/fix-custom-shader-example
Fix render pass viewport in `custom_shader` example
2 parents 5195a59 + 56bb4ce commit 28ca3a5

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

examples/custom_shader/src/scene/camera.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ pub const OPENGL_TO_WGPU_MATRIX: glam::Mat4 = mat4(
3333

3434
impl Camera {
3535
pub fn build_view_proj_matrix(&self, bounds: Rectangle) -> glam::Mat4 {
36-
//TODO looks distorted without padding; base on surface texture size instead?
37-
let aspect_ratio = bounds.width / (bounds.height + 150.0);
38-
36+
let aspect_ratio = bounds.width / bounds.height;
3937
let view = glam::Mat4::look_at_rh(self.eye, self.target, self.up);
4038
let proj = glam::Mat4::perspective_rh(
4139
self.fov_y,

examples/custom_shader/src/scene/pipeline.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl Pipeline {
357357
&self,
358358
target: &wgpu::TextureView,
359359
encoder: &mut wgpu::CommandEncoder,
360-
viewport: Rectangle<u32>,
360+
clip_bounds: Rectangle<u32>,
361361
num_cubes: u32,
362362
show_depth: bool,
363363
) {
@@ -390,11 +390,13 @@ impl Pipeline {
390390
occlusion_query_set: None,
391391
});
392392

393-
pass.set_scissor_rect(
394-
viewport.x,
395-
viewport.y,
396-
viewport.width,
397-
viewport.height,
393+
pass.set_viewport(
394+
clip_bounds.x as f32,
395+
clip_bounds.y as f32,
396+
clip_bounds.width as f32,
397+
clip_bounds.height as f32,
398+
0.0,
399+
1.0,
398400
);
399401
pass.set_pipeline(&self.pipeline);
400402
pass.set_bind_group(0, &self.uniform_bind_group, &[]);
@@ -404,7 +406,7 @@ impl Pipeline {
404406
}
405407

406408
if show_depth {
407-
self.depth_pipeline.render(encoder, target, viewport);
409+
self.depth_pipeline.render(encoder, target, clip_bounds);
408410
}
409411
}
410412
}
@@ -562,7 +564,7 @@ impl DepthPipeline {
562564
&self,
563565
encoder: &mut wgpu::CommandEncoder,
564566
target: &wgpu::TextureView,
565-
viewport: Rectangle<u32>,
567+
clip_bounds: Rectangle<u32>,
566568
) {
567569
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
568570
label: Some("cubes.pipeline.depth_pass"),
@@ -586,11 +588,13 @@ impl DepthPipeline {
586588
occlusion_query_set: None,
587589
});
588590

589-
pass.set_scissor_rect(
590-
viewport.x,
591-
viewport.y,
592-
viewport.width,
593-
viewport.height,
591+
pass.set_viewport(
592+
clip_bounds.x as f32,
593+
clip_bounds.y as f32,
594+
clip_bounds.width as f32,
595+
clip_bounds.height as f32,
596+
0.0,
597+
1.0,
594598
);
595599
pass.set_pipeline(&self.pipeline);
596600
pass.set_bind_group(0, &self.bind_group, &[]);

0 commit comments

Comments
 (0)