Graphics Reference
In-Depth Information
additional pixels. The idea is that we only want to light pixels where the scene geometry
intersects with our light bounding meshes. This means that we want to reject pixels where
the light is occluded by scene geometry, as well as pixels where the light is "floating in air."
When rendering back-face geometry, we can reject the first case by setting the depth test to
D3D11_COMPARISON_LESS_EQUAL as our depth comparison mode. For rendering front-face
geometry, we can reject the second case by using D3D11_COMPARISON_GREATER_EQUAL.
Since we must use either front-face or back-face culling, we can't reject both cases simul-
taneously in a single pass. As such, it can be advantageous to use a heuristic to estimate
which culling/depth testing mode would result in more pixels being culled.
Stenci! Test
The stencil buffer lets us store a unique 8-bit integer value per pixel, which we can use in
simple logical tests that determine whether or not a pixel should be culled. With a deferred
renderer, we can use the stencil buffer to store a mask that indicates which geometry needs
to be lit, and thus avoid shading pixels that don't require lighting. This can result in large
savings if a significant portion of the screen contains a skybox 10 or background geometry,
or if there is a lot of scene geometry with materials that don't require dynamic lighting.
To implement this, we simply set the stencil comparison function to D3D11_
COMPARISON_ALWAYS for lit geometry while filling the g-buffer, which causes the reference
value to be written to the stencil buffer for each pixel rasterized. For the reference value,
we use some known value that is different than what the stencil buffer was cleared to.
Then when rendering the lights, we use the same reference value and set the test to D3D11_
COMPARISON_EQUAL. This causes only pixels with the correct stencil value to be written,
and any others to be culled. Since most modern graphics hardware features Hi-Z units that
can perform Z-culling and stencil culling before the pixel shader is executed, the stencil test
can effectively prevent pixels from being shaded at all.
This concept can also be extended to implement light masking. Light masking allows
certain lights to only affect certain scene geometry. For example, a set of lights could be
used to only light a player character, and not the level geometry. Or if a light is in a room,
it can be made to only affect the walls of that room, without relying on shadowing or at-
tenuation to keep it from "bleeding through" into adjacent rooms. Since a stencil buffer
has eight bits that can be tested independently, the logical way to implement light masks
is to have each bit represent a light group that a light or object in the scene can belong to.
Essentially, a light will only affect geometry that belongs to the same group. So in the case
of adjacent rooms, each room would have a unique light group that the lights and geometry
1 0
A skybox is a cube of geometry rendered with the camera at the center of the cube. A cube texture is typically
applied to it, giving the appearance of geometry very far from the viewer. Since it represents objects that are
very far away, it would not receive lighting of this sort and can hence be eliminated.
Search WWH ::




Custom Search