Occlusion culling

Skipping objects that are inside the camera view but fully hidden behind walls, terrain, or other geometry.

don't render objects behind wallsskip things the camera cannot actually seehide rooms behind closed doorswhy is the game drawing stuff behind buildingsstop drawing whatever the wall is coveringis it still rendering if you cannot see itocculsion cullingonly draw the visible rooms

See it

Live demo coming soon

What it is

Occlusion culling skips an object when nearer scene geometry completely hides it. Frustum culling removes things outside the camera; occlusion culling handles the harder case of objects that are inside the view but behind a wall, hill, or building. Done well, it prevents their draw calls and shading work from reaching the GPU.

It pays off in dense scenes with strong blockers: rooms and corridors, city streets, or terrain with large structures. Engines use several approaches, including portal systems, precomputed visible sets of the kind Quake shipped in 1996, hierarchical depth buffers, and hardware occlusion queries. WebGL2 exposes queries through ANY_SAMPLES_PASSED_CONSERVATIVE.

Gotcha: asking whether every tiny object is visible can cost more than drawing it. GPU query results also arrive later; waiting for one in the same frame stalls the CPU and GPU. Test coarse groups or expensive objects, read results in a later frame, and tolerate a conservative false positive rather than letting visible geometry pop in late.

Ask AI for it

Add conservative occlusion culling to this WebGL2 city scene. Draw large occluders first, then issue bounding-box queries with gl.ANY_SAMPLES_PASSED_CONSERVATIVE while colorMask and depthMask are false. Read QUERY_RESULT_AVAILABLE on the following frame, keep objects visible until a result says otherwise, and query only groups whose normal draw cost is higher than the query overhead.

You might have meant

frustum cullingdepth buffer z bufferdraw calloverdrawcamera projection matrix