Graphics Reference
In-Depth Information
1
2
3
4
A
5
B
6
7
8
9
Near
Far
Figure 10.2 The nine cases in which a ray may intersect two convex objects, A and B .
desired. Instead, the test can be effectively performed on the GPU without buffer
readbacks using occlusion queries. The modified test is quite simple, performed in
two passes, with a fifty-fifty chance of early exit (with a result of nonintersection)
after the first pass.
In the first pass, object A is rendered into the depth buffer, using a depth test of
less-equal . The depth test is then changed to greater-than , depth buffer updates are
disabled, and object B is rendered with occlusion querying enabled. If the occlusion
query reports that no pixels of B are visible, B must lie fully in front of A , and the
objects cannot be in collision. Otherwise, a second pass is performed, identical to the
first, but with the roles of A and B reversed. At the start of both passes, the depth
buffer is initialized to far Z . Color buffer updates are disabled throughout the test. It
is not necessary to initialize the depth buffer on the second pass if the rendering at
the start of each pass involves only the front faces of the object and the depth test
is set to always . Similarly, the occlusion queries can be optimized by testing just the
back faces.
Figure 10.3 illustrates this occlusion query collision test. Illustration (a) shows
objects A and B , and the depth buffer initialized to far Z (as shown in gray). Drawing
(b) shows the first pass, in which object A has been rendered to the depth buffer. In
this case, a majority of the fragments of B pass the greater-than test, and thus a second
pass is performed. In the second pass, illustrated in (c), object B is first rendered into
the depth buffer. When object A is then tested, no fragments pass the greater-than
test, and the conclusion is that A and B are separated. Note that this test does not
require that objects A and B be polyhedral. They could equally well consist of, say,
curved surfaces. For correct intersection determination the objects must be convex,
however. A sample OpenGL implementation of this occlusion-based collision test is
provided in Table 10.1.
Search WWH ::




Custom Search