![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
3D to 2DGoing from 3D to 2D requires that we partition 3D space in a way that a 2D version can be easily produced. This means that we need to decide where the viewer, or camera, is situated, and how much of the scene the viewer should see. These settings are represented by a viewing frustum. We can think of the viewing frustum as the base of a pyramid. The viewer is located as the very top of the pyramid and looks toward the center of the pyramids base. As the size of the pyramid base increases, more of the scene is visible, but the objects appear smaller. As the size of the pyramid base decreases, the objects in the scene appear larger, but fewer objects fit into the scene. The size of the pyramid base is determined by the viewers angle, or field-of-view (FOV) setting. Figure 2.21 shows a scene from two different angles. The image on the left shows a representation of the viewing frustum. The arrow indicates the direction from which the scene is viewed. The right side of the figure shows the image that results from the frustum configuration.
Using different viewing frustum settings is similar to changing the lens on your camera. Using a telephoto lens lets you see objects in the distance, but you cant take a picture of your family without standing 400 feet away. On the other hand, you can use a wide-angle lens for close-up shots, but it isnt very useful for bird-watching (unless the bird you are watching is in a cage). Hidden Surface Removal TechniquesAn important issue in 3D graphics is determining which objects are visible and which are hidden by other objects. Rendering a scene without concern for which surfaces are closer to the viewer than others results in confused final images. Algorithms that solve this problem are called hidden surface removal techniques. There are many hidden surface removal techniques, each with its own merits. The technique employed by Direct3D is called Z-buffering. Z-bufferingZ-buffering uses a memory buffer to keep track of which surfaces are closest to the viewer. The Z values stored in the buffer do not necessarily correspond to the Z axis; instead they represent how far surfaces are from the viewer. As the image is drawn, Z values are compared with Z values in the Z-buffer. If the value in the buffer indicates that the surface being drawn is closer to the viewer than any existing surfaces, then the new surface is drawn over the old surface. If the new surface is farther away than an existing surface, then the surface is not drawn. Rendering performance can be optimized by sorting the surface in front-to-back order. This improves performance because objects in the front of the scene are drawn first and hidden surfaces dont have to be drawn at all. Luckily for us, Direct3D Retained Mode performs Z-buffering (including the sorting optimization) without any intervention from the programmer. Z-buffering: Pros And Cons Z-buffering is regarded as one of the simplest and fastest hidden surface removal techniques. It is also accurate to the pixel (yes, some algorithms are not) and handles complex scenes efficiently. The major drawback of Z-buffering is the amount of memory a Z-buffer requires. Z-buffers must be at least as large as the output image and can have bit depths of 32 bits. As an example, a program running in a 800 × 600 mode with a 16-bit Z-buffer requires almost a megabyte of memory for the Z-buffer alone. Rendering MethodsOnce a scene has been modeled in three dimensions and converted to two dimensions it is ready for rendering. This final step produces the image that will be visible on your screen and is called rendering or shading. A number of different rendering techniques exist; lets go over some of the more common techniques. WireframeA wireframe rendering doesnt look realistic at all and doesnt require all the steps weve discussed. Wireframe modes draw only the edges of the faces in the scene, representing them with straight lines. Figure 2.22 is a mesh rendered in wireframe mode.
UnlitUnlit rendering gets its name from the fact that it doesnt take light sources into consideration. Faces are drawn using the assigned face colors and textures without consideration of light values or face orientation. Unlit scenes can be rendered quickly but objects tend to appear as silhouettes. Figure 2.23 show an unlit object.
FlatFlat shading provides output more realistic than wireframe or unlit output. Flat shading takes light sources into consideration at the face level. A normal is calculated for each face and used to calculate lighting attributes for the entire face. Flat shading requires more computational power than wireframe or unlit modes. Figure 2.24 shows a scene rendered with a flat shading mode. Notice how each face is easily discernible.
GouraudGouraud shading is similar to flat shading except normals are calculated for each vertex instead of each face. The faces are then shaded by averaging light intensities over the face. This tends to round the appearance of meshes, and individual faces become indistinct. Gouraud shading provides realistic output, but can make objects look vague and loosely defined. Because vertex normals are used and face intensities are averaged, Gouraud shading is more computationally demanding than flat shading. Gouraud shading was used to produce Figure 2.25.
PhongPhong shading is an improvement over Gouraud shading. Like Gouraud, Phong shading uses vertex normals, but instead of averaging to calculate facial values, normals are calculated across the entire face. This extra work provides a precise, predictable appearance. As you might imagine, Phong shading is slower than Gouraud shading. No figure is supplied because, at the time of this writing, Direct3D doesnt support Phong shading.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |