Table of Contents Glide Programming Guide



Download 6.22 Mb.
Page44/106
Date03.02.2023
Size6.22 Mb.
#60547
1   ...   40   41   42   43   44   45   46   47   ...   106
GLIDEPGM

4Fixed Point z Buffering


When 16-bit linear z buffering is enabled, z values for each pixel are linearly interpolated across a polygon’s face. Since observer space z values are not linear in screen space, the Voodoo Graphics hardware must instead interpolate 1/z values, which are linear in screen space. When linear z buffering is enabled, the Voodoo Graphics hardware interpolates a high precision fixed point 1/z value (provided by the application), but stores only the 16-bit integer portion of the 1/z value. This can lead to some precision problems, and thus an application’s objects and database must be constructed and scaled carefully to minimize z aliasing. Linear z buffering is enabled by calling grDepthBufferMode() with the constant GR_DEPTHBUFFER_ZBUFFER.
If z buffering is enabled, Glide expects 1/z values to be passed in the ooz element of the GrVertex structure used by the various grDraw functions. The ooz values take the form (d + f/z); the values of scalars d and f should be chosen so that ooz is in the range [0..65535] in order to use the full range of the z buffer.
Example Depth Buffering.1 Configuring a z buffer.
The following code sequence configures Glide for z buffering:
grDepthBufferMode( GR_DEPTHBUFFER_ZBUFFER );
grDepthBufferFunction( GR_CMPFNC_GREATER ); // 1/Z decreases as Z increases!
grDepthMask( FXTRUE );
grBufferClear(0, 0, 0);

5Floating Point w Buffering


The Voodoo Graphics hardware can also derive a depth value from the 1/w factor computed for texture mapping and fog. Such an approach has many advantages over linear z buffering, including much greater dynamic range and less aliasing and accuracy artifacts. The Voodoo Graphics hardware uses a proprietary 16-bit floating point format for w buffering, however, an application typically does not need to manipulate this data directly, except when an application must read data directly from the depth buffer and then convert this depth value to an application dependent format. Floating point w buffering is enabled by calling grDepthBufferMode() with the constant GR_DEPTHBUFFER_WBUFFER.
The value stored in the depth buffer when w buffering is enabled is actually not the 1/w value used during texture mapping, but an approximation of the reciprocal of 1/w, in effect recovering w from 1/w during the depth buffering phase. This should be transparent to an application unless the application needs to read depth information back from the depth buffer.
Example Depth Buffering.2 Configuring a w buffer.
The following code sequence configures Glide for w buffering. The depth buffer is initially cleared to a value representing the farthest point, so that all objects in the scene will be closer to the viewer than empty space is.
grDepthBufferMode( GR_DEPTHBUFFER_WBUFFER );
grDepthBufferFunction( GR_CMP_LESS ); // larger W values are farther away
grDepthMask( FXTRUE );
grBufferClear(0, 0, GR_WDEPTHVALUE_FARTHEST);



Download 6.22 Mb.

Share with your friends:
1   ...   40   41   42   43   44   45   46   47   ...   106




The database is protected by copyright ©ininet.org 2024
send message

    Main page