Game Development Reference
In-Depth Information
Runtime Implementation
In the original Ptex system, texture lookups were done by first finding which face
you are in and then finding where you are within the face. The real-time version
essentially starts with the same steps, but with an additional mapping into the
texture atlas space. This section walks through each of these steps in detail. For
trilinear filtered lookups, the basic outline is the following:
1. Select the texture level of detail (LOD) (Section 2.3.1).
2. Compute the location within atlas for each LOD level and perform a hard-
ware, bilinear lookup for each (Section 2.3.2).
3. Lerp in the shader for a final trilinear value.
For nonfiltered lookups, the sequence is easier; all that's required is to find
the location in the atlas and do a single lookup.
We will discuss the first two
steps in detail.
2.3.1 Texture LOD Selection
The first step in a trilinear filtered, packed Ptex lookup is to determine which res-
olution of face texture is desired. In conventional hardware trilinear filtering, this
is done for you automatically by the GPU. However, hardware trilinear filtering
assumes the derivative of texture space with respect to screen space is continuous
everywhere. This is not the case for a texture atlas in general, although it's often
“good enough” for conventional texture atlasing with some tweaking. However,
tiled textures like real-time Ptex often require manual texture LOD selection.
The code for this is given in Listing 2.1.
2.3.2 Packed Ptex Lookup
Once we know which resolution we want, we clamp it to the maximum resolution
available for that face (i.e., mip level 0). Table 2.1 demonstrates how to look up
the maximum resolution for a face texture without having to resort to any per-
face information. The method uses a sorted ordering according to face texture
resolution and prefix sums.
The next step is to find the location of the resolution block within the atlas.
This is possible by lookup into a table indexed by resolution.
The sorted ordering and prefix sum are used again to find the index of the
face within the block. In general, not all faces will have a representation in the
resolution block, as some face-texture base resolutions will be higher than others.
Again, Table 2.1 describes the procedure.
We can find the face texture origin within the block using the index of the
face within the resolution block. If the texture width is W and the face texture
Search Nedrilad ::

Custom Search