Game Development Reference
In-Depth Information
//Assign viewport location
ViewPortLoc = Vector3.zero;
//If visible then get viewport location of point
if(IsVisible)
ViewPortLoc = Cam.WorldToViewportPoint(Point);
return IsVisible;
}
//---------------------------------------------------------
Frustum testing - occlusion
As mentioned earlier, visibility in its strictest sense is primarily a two-stage and
not a one-stage process. All visibility testing so far has consisted only of checking
for an object's presence within the frustum of a camera. Typically, this is enough,
and it should always be preferred. However, sometimes, it's really not enough,
because even among objects within the frustum, it's possible for one object to occlude
another, as nearer objects can conceal objects further away, either fully or partially.
This, in itself, is not always a problem though, because more often than not, the main
interest in determining object visibility is simply to know whether the camera is
near enough for a set of performance-intensive behaviors (such as AI behaviors) to
be enabled. The aim is not truly visibility testing, but to know whether the camera
is close enough. In these cases, it doesn't matter whether the objects are occluded; it
only matters whether they are in the frustum. Yet, occasionally, occlusion matters,
such as when displaying GUI elements or pop-up notifications as the player looks at
specific objects. In these cases, occlusion is important, because GUI elements should
not pop up for objects on the other side of a wall, for example. Sometimes, you can
even get around these situations with an inventive use of colliders, triggers, and
careful object placement, and sometimes, there's really no choice but to further filter
objects in the frustum with occlusion testing. Now, occlusion testing among objects
within the frustum is a deep subject that can, via some implementations, have a
significant performance overhead. For this reason, one of the best methods is to use
a simple Physics.LineCast method call to determine whether an imaginary line
drawn between the camera and destination object is intersected by other colliders.
This method usually works well, but its limitations should be recognized. First, it
assumes that all visible objects have colliders; any exceptions to this rule will not be
detected by the LineCast method. Second, as colliders only approximate the bounds
of a mesh and do not wrap around the mesh vertex for vertex, it's possible for the
LineCast method to fail when meshes have internal holes, as the surrounding
collider will prevent LineCast from penetrating them. Finally, meshes with
transparent materials that reveal objects behind them will always fail the LineCast
method. Consider the following code sample 5-6:
 
Search WWH ::




Custom Search