Search Unity

Better Visibility Testing using Raycasting and Projection to Screen Space

Discussion in 'Scripting' started by jefft, Mar 14, 2012.

  1. jefft

    jefft

    Joined:
    Feb 20, 2012
    Posts:
    23
    I've been toying with ways to perform visibility testing. A simple view frustrum test doesn't count occluders, and raycasting can be very hit and miss (literally, depends whether you cast the ray at the right spot). I don't have Pro, so any technique using Umbra is probably out.

    My current theory is a recursive approach as follows (if testing visibility of object A):
    1. Project the bounding box of A onto a coarse grid in screen space.
    2. Convert the centre co-ordinates from screen space to a vector from the camera and raycast in this direction.
    3. If we hit A, break out. It is visible.
    4. Project the bounding box of occluder O onto the coarse grid in screen space.
    5. If all grid cells of A are fully covered by occluders, break out. It is not visible.
    6. Pick another area of the grid that has low coverage (how? area x coverage?)
    7. Go back to step 2.

    Obviously we need to end the recursion at some depth. Also subdividing the grid may be required.

    I think this approach would be quite efficient if either there are no occluders or a few large occluders cover A. Transparent objects with colliders might be a problem, possibly another layer could be used for that.

    Any thoughts on workability or efficiency of this approach?