Skip to content

Commit

Permalink
switch to enable/disable occlusion culling
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Aug 27, 2024
1 parent dbe704c commit 353a7e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
47 changes: 27 additions & 20 deletions fyrox-impl/src/renderer/gbuffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

use crate::renderer::debug_renderer::DebugRenderer;
use crate::renderer::visibility::OcclusionTester;
use crate::renderer::QualitySettings;
use crate::{
core::{
algebra::{Matrix4, Vector2},
Expand Down Expand Up @@ -95,7 +96,7 @@ pub(crate) struct GBufferRenderContext<'a, 'b> {
pub normal_dummy: Rc<RefCell<GpuTexture>>,
pub black_dummy: Rc<RefCell<GpuTexture>>,
pub volume_dummy: Rc<RefCell<GpuTexture>>,
pub use_parallax_mapping: bool,
pub quality_settings: &'a QualitySettings,
pub graph: &'b Graph,
pub matrix_storage: &'a mut MatrixStorageCache,
#[allow(dead_code)]
Expand Down Expand Up @@ -299,7 +300,7 @@ impl GBuffer {
bundle_storage,
texture_cache,
shader_cache,
use_parallax_mapping,
quality_settings,
white_dummy,
normal_dummy,
black_dummy,
Expand All @@ -312,23 +313,27 @@ impl GBuffer {

let initial_view_projection = camera.view_projection_matrix();

let mut objects = FxHashSet::default();
for bundle in bundle_storage.bundles.iter() {
for instance in bundle.instances.iter() {
objects.insert(instance.node_handle);
let visibility = if quality_settings.use_occlusion_culling {
let mut objects = FxHashSet::default();
for bundle in bundle_storage.bundles.iter() {
for instance in bundle.instances.iter() {
objects.insert(instance.node_handle);
}
}
}
let objects = objects.into_iter().collect::<Vec<_>>();
let visibility = self.occlusion_tester.check(
camera.global_position(),
&initial_view_projection,
state,
&self.framebuffer,
graph,
&objects,
None,
unit_quad,
)?;
let objects = objects.into_iter().collect::<Vec<_>>();
self.occlusion_tester.check(
camera.global_position(),
&initial_view_projection,
state,
&self.framebuffer,
graph,
&objects,
None,
unit_quad,
)?
} else {
Default::default()
};

let viewport = Rect::new(0, 0, self.width, self.height);
self.framebuffer.clear(
Expand Down Expand Up @@ -374,7 +379,9 @@ impl GBuffer {
};

for instance in bundle.instances.iter() {
if !visibility.get(&instance.node_handle).map_or(true, |v| *v) {
if quality_settings.use_occlusion_culling
&& !visibility.get(&instance.node_handle).map_or(true, |v| *v)
{
continue;
}

Expand All @@ -401,7 +408,7 @@ impl GBuffer {
camera_up_vector: &camera_up,
camera_side_vector: &camera_side,
z_near: camera.projection().z_near(),
use_pom: use_parallax_mapping,
use_pom: quality_settings.use_parallax_mapping,
light_position: &Default::default(),
blend_shapes_storage: blend_shapes_storage.as_ref(),
blend_shapes_weights: &instance.blend_shapes_weights,
Expand Down
11 changes: 10 additions & 1 deletion fyrox-impl/src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ pub struct QualitySettings {

/// Whether to use bloom effect.
pub use_bloom: bool,

/// Whether to use occlusion culling technique or not. Warning: this is experimental feature
/// that wasn't properly tested yet!
#[serde(default)]
pub use_occlusion_culling: bool,
}

impl Default for QualitySettings {
Expand Down Expand Up @@ -290,6 +295,7 @@ impl QualitySettings {

use_bloom: true,

use_occlusion_culling: false,
use_parallax_mapping: true,

csm_settings: Default::default(),
Expand Down Expand Up @@ -323,6 +329,7 @@ impl QualitySettings {

use_bloom: true,

use_occlusion_culling: false,
use_parallax_mapping: true,

csm_settings: CsmSettings {
Expand Down Expand Up @@ -361,6 +368,7 @@ impl QualitySettings {

use_bloom: true,

use_occlusion_culling: false,
use_parallax_mapping: false,

csm_settings: CsmSettings {
Expand Down Expand Up @@ -399,6 +407,7 @@ impl QualitySettings {

use_bloom: false,

use_occlusion_culling: false,
use_parallax_mapping: false,

csm_settings: CsmSettings {
Expand Down Expand Up @@ -1661,7 +1670,7 @@ impl Renderer {
bundle_storage: &bundle_storage,
texture_cache: &mut self.texture_cache,
shader_cache: &mut self.shader_cache,
use_parallax_mapping: self.quality_settings.use_parallax_mapping,
quality_settings: &self.quality_settings,
normal_dummy: self.normal_dummy.clone(),
white_dummy: self.white_dummy.clone(),
black_dummy: self.black_dummy.clone(),
Expand Down

0 comments on commit 353a7e7

Please sign in to comment.