|
This sample application uses the new asynchronous
visibility query mechanism introduced in DirectX 9
to determine how bright to make a light flare (if it
is to be drawn at all). The blocking object (simple
alpha tested maple leaves) is drawn first into the
frame buffer. A small sphere representing the
light source is then drawn twice.
The first time the light source geometry drawn, it
is drawn with Z-Writes OFF and Z-Test set to ALWAYS. This
draw call is bracketed with a visibility query so that
the maximum number of pixels potentially visible for
the light source this frame can be determined.
The second time the light source is drawn, it is drawn
with Z-Writes turned back ON and Z-Test set back to
LEQUAL. This draw call is bracketed with a second
visibility query so that the actual number of pixels
visible for the light source this frame can be determined.
The application then spins waiting for the results
of the visibility queries to return. Ordinarily,
an application would do useful work here or simply
move on to the next frame, using some array or ring-buffer
of queries to check for the results in subsequent frames
(assuming that stale query data is OK, as it likely
is for a simple light flare).
Once the two visibility queries have returned, the
percentage of light source pixels actually visible
in the scene is used to determine the brightness of
the light flare which is drawn over the scene with
no Z-test and additive blending. |