Skip to content

Commit

Permalink
fixed frame desync in occlusion culling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Aug 31, 2024
1 parent 7991265 commit 43f0f74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
9 changes: 4 additions & 5 deletions fyrox-impl/src/renderer/gbuffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,16 @@ impl GBuffer {
}
}

self.occlusion_tester.upload_data(
self.occlusion_tester.try_run_visibility_test(
state,
graph,
None,
unit_quad,
objects.iter(),
&self.framebuffer,
camera.global_position(),
initial_view_projection,
);

self.occlusion_tester
.run_visibility_test(state, graph, None, unit_quad)?;
)?;
}

let inv_view_proj = initial_view_projection.try_inverse().unwrap_or_default();
Expand Down
26 changes: 19 additions & 7 deletions fyrox-impl/src/renderer/visibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ impl OcclusionTester {
Ok(())
}

pub fn upload_data<'a>(
fn upload_data<'a>(
&mut self,
state: &PipelineState,
graph: &Graph,
Expand Down Expand Up @@ -793,22 +793,34 @@ impl OcclusionTester {
self.observer_position = observer_position;
}

pub fn run_visibility_test(
pub fn try_run_visibility_test<'a>(
&mut self,
state: &PipelineState,
graph: &Graph,
debug_renderer: Option<&mut DebugRenderer>,
unit_quad: &GeometryBuffer,
objects_to_test: impl Iterator<Item = &'a Handle<Node>>,
prev_framebuffer: &FrameBuffer,
observer_position: Vector3<f32>,
view_projection: Matrix4<f32>,
) -> Result<(), FrameworkError> {
if self.objects_to_test.is_empty()
|| self
.visibility_buffer_optimizer
.pixel_buffer
.is_request_running()
if self
.visibility_buffer_optimizer
.pixel_buffer
.is_request_running()
{
return Ok(());
}

self.upload_data(
state,
graph,
objects_to_test,
prev_framebuffer,
observer_position,
view_projection,
);

let w = self.frame_size.x as i32;
let h = self.frame_size.y as i32;
let viewport = Rect::new(0, 0, w, h);
Expand Down

0 comments on commit 43f0f74

Please sign in to comment.