Skip to content

Commit

Permalink
minor rework: distance -> contribution culling, plus actually enable
Browse files Browse the repository at this point in the history
  • Loading branch information
crocdialer committed Oct 17, 2024
1 parent a9ea9ec commit 045059f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
5 changes: 2 additions & 3 deletions include/vierkant/SceneRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SceneRenderer
uint32_t num_draws = 0;
uint32_t num_frustum_culled = 0;
uint32_t num_occlusion_culled = 0;
uint32_t num_distance_culled = 0;
uint32_t num_contribution_culled = 0;
vierkant::ImagePtr object_ids;
object_id_by_index_fn_t object_by_index_fn;
std::vector<semaphore_submit_info_t> semaphore_infos;
Expand All @@ -51,8 +51,7 @@ class SceneRenderer
* @param normalized_size width/height of selection-area, can provide {0, 0} for points
* @return an array containing a list of selected and unique draw-ids
*/
virtual std::vector<uint16_t> pick(const glm::vec2 &normalized_coord,
const glm::vec2 &normalized_size) = 0;
virtual std::vector<uint16_t> pick(const glm::vec2 &normalized_coord, const glm::vec2 &normalized_size) = 0;

virtual ~SceneRenderer() = default;
};
Expand Down
4 changes: 2 additions & 2 deletions include/vierkant/gpu_culling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct gpu_cull_params_t
uint32_t num_draws = 0;

uint32_t occlusion_cull = true;
uint32_t distance_cull = false;
uint32_t contribution_cull = true;
uint32_t frustum_cull = true;
uint32_t lod_enabled = true;

Expand Down Expand Up @@ -59,7 +59,7 @@ struct draw_cull_result_t
uint32_t draw_count = 0;
uint32_t num_frustum_culled = 0;
uint32_t num_occlusion_culled = 0;
uint32_t num_distance_culled = 0;
uint32_t num_contribution_culled = 0;
uint32_t num_triangles = 0;
uint32_t num_meshlets = 0;
};
Expand Down
20 changes: 13 additions & 7 deletions shaders/pbr/indirect_cull.comp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct draw_cull_result_t
uint num_draws;
uint num_frustum_culled;
uint num_occlusion_culled;
uint num_distance_culled;
uint num_contribution_culled;
uint num_triangles;
uint num_meshlets;
};
Expand Down Expand Up @@ -50,7 +50,7 @@ struct draw_cull_data_t

bool frustum_cull;
bool occlusion_cull;
bool distance_cull;
bool contribution_cull;
bool backface_cull;
bool lod_enabled;

Expand Down Expand Up @@ -114,6 +114,9 @@ void main()
vec4 aabb;
bool sphere_visible = project_sphere(center, radius, cull_data.znear, cull_data.P00, cull_data.P11, aabb);

// object bound's area in NDC
vec2 screen_area = aabb.zw - aabb.xy;//vec2(aabb.z - aabb.x, aabb.w - aabb.y);

if(cull_data.frustum_cull)
{
// the left/top/right/bottom plane culling utilizes frustum symmetry to cull against two planes at the same time
Expand All @@ -122,17 +125,20 @@ void main()
if(!visible){ atomicAdd(cull_data.draw_result.v.num_frustum_culled, 1); }
}

if(visible && cull_data.distance_cull)
if(visible && cull_data.contribution_cull && sphere_visible)
{
visible = visible && (-center.z - radius) <= cull_data.zfar;
if(!visible){ atomicAdd(cull_data.draw_result.v.num_distance_culled, 1); }
// contribution cull (based on screen-area threshold, ~1 px)
const float size_thresh = 1.0 / cull_data.pyramid_size.x;
visible = visible && max(screen_area.x, screen_area.y) >= size_thresh;

if(!visible){ atomicAdd(cull_data.draw_result.v.num_contribution_culled, 1); }
}

if(visible && cull_data.occlusion_cull && sphere_visible)
{
// get cracking with depth-pyramid
float width = (aabb.z - aabb.x) * cull_data.pyramid_size.x;
float height = (aabb.w - aabb.y) * cull_data.pyramid_size.y;
float width = screen_area.x * cull_data.pyramid_size.x;
float height = screen_area.y * cull_data.pyramid_size.y;

float level = floor(log2(max(width, height)));

Expand Down
2 changes: 1 addition & 1 deletion src/PBRDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ SceneRenderer::render_result_t PBRDeferred::render_scene(Rasterizer &renderer, c
ret.num_draws = frame_context.cull_result.drawables.size();
ret.num_frustum_culled = frame_context.stats.draw_cull_result.num_frustum_culled;
ret.num_occlusion_culled = frame_context.stats.draw_cull_result.num_occlusion_culled;
ret.num_distance_culled = frame_context.stats.draw_cull_result.num_distance_culled;
ret.num_contribution_culled = frame_context.stats.draw_cull_result.num_contribution_culled;
ret.object_ids = frame_context.internal_images.object_ids;

vierkant::semaphore_submit_info_t semaphore_submit_info = {};
Expand Down
4 changes: 2 additions & 2 deletions src/gpu_culling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct alignas(16) draw_cull_data_t

VkBool32 frustum_cull = false;
VkBool32 occlusion_cull = false;
VkBool32 distance_cull = false;
VkBool32 contribution_cull = false;
VkBool32 backface_cull = false;
VkBool32 lod_enabled = false;

Expand Down Expand Up @@ -219,7 +219,7 @@ draw_cull_result_t gpu_cull(const vierkant::gpu_cull_context_ptr &context, const
draw_cull_data.num_draws = params.num_draws;
draw_cull_data.pyramid_size = {params.depth_pyramid->width(), params.depth_pyramid->height()};
draw_cull_data.occlusion_cull = params.occlusion_cull;
draw_cull_data.distance_cull = params.distance_cull;
draw_cull_data.contribution_cull = params.contribution_cull;
draw_cull_data.frustum_cull = params.frustum_cull;
draw_cull_data.lod_enabled = params.lod_enabled;

Expand Down
17 changes: 9 additions & 8 deletions src/imgui/imgui_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ void draw_scene_renderer_ui_intern(const PBRDeferredPtr &pbr_renderer)
ImGui::BulletText("num_triangles: %d", draw_result.num_triangles);
ImGui::BulletText("num_meshlets: %d", draw_result.num_meshlets);
ImGui::BulletText("num_frustum_culled: %d", draw_result.num_frustum_culled);
ImGui::BulletText("num_contribution_culled: %d", draw_result.num_contribution_culled);
ImGui::BulletText("num_occlusion_culled: %d", draw_result.num_occlusion_culled);

// drawcall/culling plots
Expand Down Expand Up @@ -613,7 +614,7 @@ void draw_scene_ui(const ScenePtr &scene, CameraPtr &camera, std::set<vierkant::
ImGui::PopID();
ImGui::SameLine();

if(ImGui::TreeNode((void *) ((uint64_t)cam->id()), "%s", cam->name.c_str()))
if(ImGui::TreeNode((void *) ((uint64_t) cam->id()), "%s", cam->name.c_str()))
{
vierkant::gui::draw_camera_param_ui(cam->perspective_params);
ImGui::Spacing();
Expand Down Expand Up @@ -987,14 +988,14 @@ void draw_object_ui(const Object3DPtr &object)
if(ImGui::TreeNodeEx(&phys_cmp, ImGuiTreeNodeFlags_DefaultOpen, "mass: %.2f", phys_cmp.mass))
{
bool change = false;
// ImGui::Text("shape-id: %lu", phys_cmp.shape_id.value());
// ImGui::Text("shape-id: %lu", phys_cmp.shape_id.value());
change |= ImGui::InputFloat("mass", &phys_cmp.mass);
change |=ImGui::InputFloat("friction", &phys_cmp.friction);
change |=ImGui::InputFloat("restitution", &phys_cmp.restitution);
change |=ImGui::InputFloat("linear_damping", &phys_cmp.linear_damping);
change |=ImGui::InputFloat("angular_damping", &phys_cmp.angular_damping);
change |=ImGui::Checkbox("kinematic", &phys_cmp.kinematic);
change |=ImGui::Checkbox("sensor", &phys_cmp.sensor);
change |= ImGui::InputFloat("friction", &phys_cmp.friction);
change |= ImGui::InputFloat("restitution", &phys_cmp.restitution);
change |= ImGui::InputFloat("linear_damping", &phys_cmp.linear_damping);
change |= ImGui::InputFloat("angular_damping", &phys_cmp.angular_damping);
change |= ImGui::Checkbox("kinematic", &phys_cmp.kinematic);
change |= ImGui::Checkbox("sensor", &phys_cmp.sensor);
phys_cmp.need_update |= change;
ImGui::TreePop();
}
Expand Down

0 comments on commit 045059f

Please sign in to comment.