FAST 2D/3D Texture Coordinate Evaluation

Kenny Hoff
7/15/97


In order to be as efficient as possible, we will use the normals calculated previously in screen space. For the 2D textures coordinates, we will simply assume that we have a flat 2D texture mapped onto the circular silhouette of sphere, so we can simply use the normalized x and y coordinates of the normal as the texture coords. For the 3D case, all three components will be used.

We are given the following:

We would like to make them fit in the range: So for the x and y components we need to scale the range by 0.5 and translate by 0.5; the z components remain the same.

However, because of the fixed-point formats required on both ends, we have some additional difficulties:

Our range of values is as follows now: The conversion proceeds as follows:
  TextureX = (NormalX * 24 * 0.5) + (216 * 0.5)
           = (NormalX * 24 * 2-1) + 215
           = (NormalX * 23) + 215
           = (NormalX << 3) + 215

  TextureY = (NormalY << 3) + 215

  TextureZ = NormalZ * 24
           = NormalZ << 4
Where NormalX and NormalY representing the range [-1,1] and NormalZ representing the range [0,1] in 4.12 fixed-point format:
  4.12 NormalX and NormalY = NormalX * 4096
                           = NormalX * 212

              4.12 NormalZ = NormalZ * 212

So the normal components are converted in texture coords by a simple scaling (accomplished through a left shift) and translation (except in the case of z). The bit-shifts are fairly straightforward, but it is important to note two options for the translation (addition of 215). Given the 16-bit normal x and y components after the scaling phase, the addition of 215 can be accomplished by one of the following methods: