Merge pull request #2738 from jsatka/fix-custom-shader-example

Fix render pass viewport in `custom_shader` example
This commit is contained in:
Héctor 2025-11-20 01:43:14 +01:00 committed by GitHub
commit 28ca3a5863
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 16 deletions

View file

@ -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,

View file

@ -357,7 +357,7 @@ impl Pipeline {
&self,
target: &wgpu::TextureView,
encoder: &mut wgpu::CommandEncoder,
viewport: Rectangle<u32>,
clip_bounds: Rectangle<u32>,
num_cubes: u32,
show_depth: bool,
) {
@ -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, &[]);
@ -404,7 +406,7 @@ impl Pipeline {
}
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,
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"),
@ -586,11 +588,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, &[]);