mrdoob/three.js — pull request #3388 by wivlaro (2013-04-27 09:32:23+00:00)
Title: Occlusion culling

An implementation of occlusion culling in three.js more or less as per mrdoob/three.js#3355 It is good for scenes where there are lots of objects in the frustum many of which occlude each other.

This branch also contains a bug-fix for painterSortStable failing to sort properly (on chrome at least) when there are non-visible (namely frustum-culled) objects in the scene (with z undefined).

Usage:
* Give WebGLRenderer the occlusionCulling = true parameter to enable.
* Optional parameters:
* occlusionBufferWidth and occlusionBufferHeight (default 256 x 256) specify the resolution of the occlusion buffer that Z values are written to
* occlusionBufferMaxFill (default 1, valid range > 0 and <= 1) - when this proportion of the occlusion buffer is filled, don't do any more filling.
* On the Mesh objects to be occluders, set occluder = true
* On the Mesh objects to be occludable, set occludable to one of:
* THREE.AABBOccludable - points at the corner object's geometry's AABB are tested for visibility. Probably good for small, details objects.
* THREE.VertexOccludable - points at the corner object's geometry's AABB are tested for visibility. Probably good for small, low-detail or irregular objects.
* THREE.FillOccludable - all pixels inside all triangles are tested for visibility (slowest)
* THREE.EdgeOccludable - (NOT DONE YET) run along all the edges of the geometry testing for visibility. Probably good for large objects (also, may be generally best solution)

If you create another HTML Canvas element and set window.threejsOcclusionOverlayCanvas to the DOM Element, the occluder will draw a psychedelic debug view of the occlusion buffer. This is good positioned over the top of the 3D canvas to get an idea of what's going on.

I think this could be quite a useful addition for people