Game Development Reference
In-Depth Information
Note
Depth values in the z-buffer are actually not linear, but the general idea is still true.
Another related problem when using the z-buffer is so-called z-fighting . Figure 10-10 illustrates
the problem.
Figure 10-10. Z-fighting in action
The two rectangles in Figure 10-10 are coplanar ; that is, they are embedded in the same plane.
Since they overlap, they also share some pixels, which should have the same depth values.
However, due to limited floating-point precision, the GPU might not arrive at the same depth
values for pixels that overlap. Which pixel passes the depth test is then a sort of lottery. This
can usually be resolved by pushing one of the two coplanar objects away from the other object
by a small amount. The value of this offset is dependent on a few factors, so it's usually best to
experiment. To summarize:
ï?®
Do not use values that are too small or too large for your near and far
clipping plane distances.
ï?®
Avoid coplanar objects by offsetting them a little.
Defining 3D Meshes
So far, we've only used a couple of triangles as placeholders for objects in our worlds. What
about more complex objects?
We already talked about how the GPU is just a big, mean triangle-rendering machine. All our 3D
objects, therefore, have to be composed of triangles as well. In the previous chapters, we used
two triangles to represent a flat rectangle. The principles we used there, like vertex positioning,
colors, texturing, and vertex indexing, are exactly the same in 3D. Our triangles are just not
limited to lie in the x-y plane anymore; we can freely specify each vertex's position in 3D space.
How do you go about creating such soups of triangles that make up a 3D object? We can
do that programmatically, as we've done for the rectangles of our sprites. We could also use
 
Search WWH ::




Custom Search