Fix fog scene depth comparison
This commit is contained in:
parent
3676f8fef5
commit
c0f41045da
3 changed files with 13 additions and 20 deletions
|
@ -118,11 +118,11 @@ impl CameraUniform {
|
|||
proj: cgmath::Matrix4::identity().into(),
|
||||
inv_view_proj: cgmath::Matrix4::identity().into(),
|
||||
position: [0.0; 4],
|
||||
planes: [NEAR_PLANE, FAR_PLANE, 0.0, 0.0],
|
||||
planes: [NEAR_PLANE, FAR_PLANE, 1.0, 1.0],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, camera: &Camera) {
|
||||
pub fn update(&mut self, camera: &Camera, config: &wgpu::SurfaceConfiguration) {
|
||||
let view = camera.get_view_matrix();
|
||||
let proj = camera.projection.get_matrix();
|
||||
self.view = view.into();
|
||||
|
@ -130,6 +130,7 @@ impl CameraUniform {
|
|||
let inv_view_proj = (proj * view).invert().unwrap();
|
||||
self.inv_view_proj = inv_view_proj.into();
|
||||
self.position = camera.position.to_homogeneous().into();
|
||||
self.planes = [NEAR_PLANE, FAR_PLANE, config.width as f32, config.height as f32];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ pub struct State {
|
|||
fog_instances: Vec<Instance>,
|
||||
fog_instance_buffer: wgpu::Buffer,
|
||||
geometry_depth_texture: Texture,
|
||||
light_depth_texture: Texture,
|
||||
geom_model: Model,
|
||||
fog_model: Model,
|
||||
light_model: Model,
|
||||
|
@ -118,7 +117,7 @@ impl State {
|
|||
);
|
||||
|
||||
let mut camera_uniform = CameraUniform::new();
|
||||
camera_uniform.update(&camera);
|
||||
camera_uniform.update(&camera, &config);
|
||||
|
||||
let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||
label: Some("Camera Buffer"),
|
||||
|
@ -500,7 +499,6 @@ impl State {
|
|||
fog_instances,
|
||||
fog_instance_buffer,
|
||||
geometry_depth_texture,
|
||||
light_depth_texture,
|
||||
geom_model,
|
||||
fog_model,
|
||||
light_model,
|
||||
|
@ -575,7 +573,7 @@ impl State {
|
|||
// Update camera
|
||||
self.camera.update(dt, &self.camera_controller);
|
||||
self.camera_controller.reset(false);
|
||||
self.camera_uniform.update(&self.camera);
|
||||
self.camera_uniform.update(&self.camera, &self.config);
|
||||
self.queue.write_buffer(
|
||||
&self.camera_buffer,
|
||||
0,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue