Skip to content

Occlusion culling in the G-buffer pass (Hi-Z, two phase, GPU) - #255

Merged
BenjaFriend merged 2 commits into
mainfrom
feature/occlusion-culling
Nov 17, 2026
Merged

BenjaFriend merged 2 commits into
mainfrom
feature/occlusion-culling

Conversation

@BenjaFriend

Copy link
Copy Markdown
Member

Closes #252.

What

Meshes that other meshes hide are no longer drawn in the G-buffer pass.

  1. Compute phase 0: slots in view that were visible last frame get a draw (Draw1).
  2. First render pass draws Draw1.
  3. A depth pyramid (farthest depth per texel) is built from that depth.
  4. Compute phase 1 tests every slot in view against the pyramid, with this frame's camera and blended world matrices. Slots that are not hidden and not yet drawn get Draw2.
  5. A second render pass (load ops, same frame buffer) draws Draw2.

No popping, no reprojection. Details: Docs/occlusion-culling.md.

Also

  • --occlusion-culling on|off, [Engine] OcclusionCulling, GPU Options checkbox and an Occluded count (value of the previous frame).
  • Turns itself off if the compute shaders do not load or the device cannot sample the depth format / store R32F.
  • CPU twin of the test (OcclusionTest.h) with a randomized "never hides a visible mesh" test in GraphicsTests.
  • Render passes sharing the offscreen frame buffer have broader, matching subpass dependencies (the validation layer requires them to match).

Verified

  • ctest: 689/689 pass.
  • Offscreen on llvmpipe with validation layers: 0 errors. Screenshots with occlusion on and off are pixel-identical (1920x1080 and 1001x563). At the default view 655 of 799 in-view meshes were hidden.
  • Ran interactively in a window on the lighting test level.

Not verified

  • A live swap chain resize and a moving-camera recording (not possible offscreen).

🤖 Generated with Claude Code

https://claude.ai/code/session_017NN37QrCqnwEJe9CqoCjqA

BenjaFriend and others added 2 commits November 17, 2026 10:42
Meshes that other meshes hide are no longer drawn. Phase 0 draws what was
visible last frame, a depth pyramid is built from that depth, phase 1 tests
every mesh in view against it and a second render pass draws the rest. The
pyramid uses this frame's camera, so nothing pops. Adds the
--occlusion-culling run setting, a GPU Options checkbox and an Occluded
count, a CPU twin of the test (OcclusionTest.h) with a randomized
no-visible-mesh-hidden test, and Docs/occlusion-culling.md.

Closes #252

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37QrCqnwEJe9CqoCjqA
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@BenjaFriend
BenjaFriend merged commit 07c22cf into main Nov 17, 2026
14 checks passed
@BenjaFriend
BenjaFriend deleted the feature/occlusion-culling branch November 17, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Occlusion culling: do not draw meshes that other meshes hide (G-buffer pass)

1 participant