Game Development Reference
In-Depth Information
Being seen
There are many occasions during gameplay when questions of object visibility
arise, some actual and some hypothetical. Concerning the actual occasion, there
are several questions we could ask, including whether object X is visible to camera
Y right now, whether object X is visible to any camera right now, or when does
object X become visible or nonvisible to a specific camera or to any camera. With
regard to hypotheticals, we would ask whether object X would be visible if camera
Y were moved to position Z. In the actual occasion case, we're concerned with the
real visibility of objects for the current frame, based on the positions of all cameras,
and concerning hypotheticals, we're concerned with what would be the case if a
camera were moved to a specific position. Both these cases are important for games.
Knowing whether objects (such as enemy characters) are really visible to the camera
is important to define behavior and AI. This is because when objects are not visible,
there are many behaviors and calculations we could suspend to save the processing
workload. Further, knowing whether an object would become visible if the camera
were moved is helpful because it lets us anticipate which objects, if any, will enter
visibility for the next frame so that we can prepare them ahead of time. Now, before
moving on to consider how these questions can be answered in script, it's worth
considering the visibility in its narrowest sense.
In terms of visibility, there are two main concepts: frustum and occlusion. Each
perspective camera has a viewing frustum, as we saw earlier; this frustum is a
trapezoidal volume extended outwards from the camera lens and contains a region
defined by field of view and clipping plane distance properties. The frustum, in
essence, mathematically defines the horizons of a camera—the region of a scene that
the camera can potentially observe right now. The word, potentially, is significant,
because even when an active and visible object is within the camera frustum, it
doesn't necessarily mean that it's visible to the camera. This is because objects within
the frustum can occlude others also inside the frustum; that is, nearer objects can
obscure or conceal objects behind them either fully or partially. For this reason, true
visibility tests involve at least two processes: first, determining whether an object
is in the frustum, and second, determining whether it is occluded or not. Only if an
object passes both tests can it be classified as visible to the camera, and even then,
only on the assumption that an object is not concealed or rendered invisible by
custom shaders or other postprocess effects. In short, there are many reasons why
true visibility testing is an intricate process, but here, I'll take the two-stage test as
good enough for most purposes.
 
Search WWH ::




Custom Search