3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Texture mapping 215<br />
Perspective correctness<br />
Texture coordinates are specified at<br />
each vertex of a given triangle, and<br />
these coordinates are interpolated<br />
using an extended Bresenham's line<br />
algorithm. If these texture coordinates<br />
are linearly interpolated across the<br />
screen, the result is affine texture<br />
mapping. This is a fast calculation, but<br />
there can be a noticeable discontinuity<br />
between adjacent triangles when these<br />
triangles are at an angle to the plane of<br />
the screen (see figure at right – textures (the checker boxes) appear bent).<br />
Because affine texture mapping does not take into account the depth information about a<br />
polygon's vertices, where the polygon is not perpendicular to the viewer it produces a<br />
noticeable defect.<br />
Perspective correct texturing accounts for the vertices' positions in <strong>3D</strong> space, rather than simply interpolating a 2D<br />
triangle. This achieves the correct visual effect, but it is slower to calculate. Instead of interpolating the texture<br />
coordinates directly, the coordinates are divided by their depth (relative to the viewer), and the reciprocal of the<br />
depth value is also interpolated and used to recover the perspective-correct coordinate. This correction makes it so<br />
that in parts of the polygon that are closer to the viewer the difference from pixel to pixel between texture<br />
coordinates is smaller (stretching the texture wider), and in parts that are farther away this difference is larger<br />
(compressing the texture).<br />
Affine texture mapping directly interpolates a texture coordinate between two endpoints and :<br />
where<br />
Perspective correct mapping interpolates after dividing by depth , then uses its interpolated reciprocal to<br />
recover the correct coordinate:<br />
All modern <strong>3D</strong> <strong>graphics</strong> hardware implements perspective correct texturing.<br />
Classic texture mappers generally did only simple mapping with at<br />
most one lighting effect, and the perspective correctness was about 16<br />
times more expensive. To achieve two goals - faster arithmetic results,<br />
and keeping the arithmetic mill busy at all times - every triangle is<br />
further subdivided into groups of about 16 pixels. For perspective<br />
texture mapping without hardware support, a triangle is broken down<br />
into smaller triangles for rendering, which improves details in<br />
non-architectural applications. Software renderers generally preferred<br />
screen subdivision because it has less overhead. Additionally they try<br />
to do linear interpolation along a line of pixels to simplify the set-up<br />
(compared to 2d affine interpolation) and thus again the overhead (also<br />
affine texture-mapping does not fit into the low number of registers of<br />
Doom renders vertical spans (walls) with affine<br />
texture mapping.<br />
the x86 CPU; the 68000 or any RISC is much more suited). For instance, Doom restricted the world to vertical walls<br />
and horizontal floors/ceilings. This meant the walls would be a