Skip to content

Commit

Permalink
occlusion culling multiple camera fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Feb 12, 2024
1 parent 27c8489 commit a9bb68e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
1 change: 1 addition & 0 deletions Editor/CameraComponentWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void CameraPreview::RenderPreview()
renderpath.camera = camera;
scale_local.y = scale_local.x * renderpath.camera->height / renderpath.camera->width;
renderpath.setSceneUpdateEnabled(false); // we just view our scene with this that's updated by the main rernderpath
renderpath.setOcclusionCullingEnabled(false); // occlusion culling only works for one camera
renderpath.PreUpdate();
renderpath.Update(0);
renderpath.PostUpdate();
Expand Down
19 changes: 14 additions & 5 deletions WickedEngine/wiRenderPath3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ namespace wi
visibility_main.scene = scene;
visibility_main.camera = camera;
visibility_main.flags = wi::renderer::Visibility::ALLOW_EVERYTHING;
if (!getOcclusionCullingEnabled())
{
visibility_main.flags &= ~wi::renderer::Visibility::ALLOW_OCCLUSION_CULLING;
}
wi::renderer::UpdateVisibility(visibility_main);

if (visibility_main.planar_reflection_visible)
Expand Down Expand Up @@ -803,7 +807,7 @@ namespace wi
wi::renderer::DRAWSCENE_TESSELLATION |
wi::renderer::DRAWSCENE_OCCLUSIONCULLING |
wi::renderer::DRAWSCENE_MAINCAMERA
;
;

// Main camera depth prepass + occlusion culling:
cmd = device->BeginCommandList();
Expand All @@ -819,7 +823,10 @@ namespace wi
cmd
);

wi::renderer::OcclusionCulling_Reset(visibility_main, cmd); // must be outside renderpass!
if (getOcclusionCullingEnabled())
{
wi::renderer::OcclusionCulling_Reset(visibility_main, cmd); // must be outside renderpass!
}

wi::renderer::RefreshImpostors(*scene, cmd);

Expand Down Expand Up @@ -886,7 +893,10 @@ namespace wi

device->RenderPassEnd(cmd);

wi::renderer::OcclusionCulling_Resolve(visibility_main, cmd); // must be outside renderpass!
if (getOcclusionCullingEnabled())
{
wi::renderer::OcclusionCulling_Resolve(visibility_main, cmd); // must be outside renderpass!
}

});

Expand Down Expand Up @@ -1871,9 +1881,8 @@ namespace wi
RENDERPASS_MAIN,
cmd,
wi::renderer::DRAWSCENE_TRANSPARENT |
wi::renderer::DRAWSCENE_OCCLUSIONCULLING |
wi::renderer::DRAWSCENE_HAIRPARTICLE |
wi::renderer::DRAWSCENE_TESSELLATION |
wi::renderer::DRAWSCENE_OCCLUSIONCULLING |
wi::renderer::DRAWSCENE_OCEAN |
wi::renderer::DRAWSCENE_MAINCAMERA
);
Expand Down
16 changes: 13 additions & 3 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3084,8 +3084,13 @@ void UpdateVisibility(Visibility& vis)

const ObjectComponent& object = vis.scene->objects[args.jobIndex];
Scene::OcclusionResult& occlusion_result = vis.scene->occlusion_results_objects[args.jobIndex];
bool occluded = false;
if (vis.flags & Visibility::ALLOW_OCCLUSION_CULLING)
{
occluded = occlusion_result.IsOccluded();
}

if ((vis.flags & Visibility::ALLOW_REQUEST_REFLECTION) && object.IsRequestPlanarReflection() && !occlusion_result.IsOccluded())
if ((vis.flags & Visibility::ALLOW_REQUEST_REFLECTION) && object.IsRequestPlanarReflection() && !occluded)
{
// Planar reflection priority request:
float dist = wi::math::DistanceEstimated(vis.camera->Eye, object.center);
Expand Down Expand Up @@ -4650,7 +4655,12 @@ void UpdateRenderDataAsync(
// Compute water simulation:
if (vis.scene->weather.IsOceanEnabled())
{
if (!GetOcclusionCullingEnabled() || !vis.scene->ocean.IsOccluded())
bool occluded = false;
if (vis.flags & Visibility::ALLOW_OCCLUSION_CULLING)
{
occluded = vis.scene->ocean.IsOccluded();
}
if (!occluded)
{
auto range = wi::profiler::BeginRangeGPU("Ocean - Simulate", cmd);
vis.scene->ocean.UpdateDisplacementMap(vis.scene->weather.oceanParameters, cmd);
Expand Down Expand Up @@ -6020,7 +6030,7 @@ void DrawScene(
const bool transparent = flags & DRAWSCENE_TRANSPARENT;
const bool hairparticle = flags & DRAWSCENE_HAIRPARTICLE;
const bool impostor = flags & DRAWSCENE_IMPOSTOR;
const bool occlusion = (flags & DRAWSCENE_OCCLUSIONCULLING) && GetOcclusionCullingEnabled();
const bool occlusion = (flags & DRAWSCENE_OCCLUSIONCULLING) && (vis.flags & Visibility::ALLOW_OCCLUSION_CULLING) && GetOcclusionCullingEnabled();
const bool ocean = flags & DRAWSCENE_OCEAN;
const bool skip_planar_reflection_objects = flags & DRAWSCENE_SKIP_PLANAR_REFLECTION_OBJECTS;
const bool foreground_only = flags & DRAWSCENE_FOREGROUND_ONLY;
Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 71;
// minor bug fixes, alterations, refactors, updates
const int revision = 374;
const int revision = 375;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit a9bb68e

Please sign in to comment.