< Zurück | Inhalt | Weiter >

14.3.4 MIPMAP mode, filter, and multiple texture images

One of the common problems of texture mapping is that the texture images become pixilated as resampling enlarges them. The quick fix to this is to ensure that all your texture images are large enough so that they can never become overly magnified.


Imagine a cube in your scene with a texture image applied to one face. If the cube’s texture image is 64 x 64 pixels and the cube is very close to the viewer, it may end up taking up 300 x 300 pixels on the screen. A texture image that has been magnified by a factor of 5 is obviously not going to look very good—regardless of the sophistication of the sampling algorithm employed by the graphics hardware. A solution to this problem would be to assign a 256 x 256 pixel texture image to each face of the cube.


However, we are now using 16 times as much texture memory. To complicate matters, most of the time the cube is probably considerably further away from the viewer, and the graphics API will have to work hard to sample the 256 x 256 size image down to an appropriate size based on the cube’s distance.


What we need, and what MIPMAPs provide, is the ability to specify multiple texture images. The graphics API will select the most appropriate one based on the size of the surface it is trying to render. We pay the penalty of storing multiple texture images—which is incidentally very small compared to storing the largest texture image.


For example, 64 x 64 = 4096

32 x 32 = 1024


16 x 16 = 256


8 x 8 = 64


4 x 4 = 16


2 x 2 = 4


1 x 1 = 1


The cost of storing the 64 x 64 pixel image is proportional to 4096, while the cost of storing all the other images is proportional to 1365. So using MIPMAPs will improve performance for a very low memory penalty.


To use MIPMAPs you must specify all the texture images from your maximum size (which must be a power of 2, right down to the 1 x 1 image). So, if our largest texture image is 64 x 64 pixels, we require seven texture images. Usually, of course, the texture images will be increasingly low resolution images of the same feature. Texture images can be easily preprocessed using the resampling features of a bitmap editor such as PhotoShop

(Adobe) or PaintShop Pro (JASC).


In figure 14.13, the AppearanceTest example uses texture images that are different so that the texture image that was chosen by the graphics API is apparent.


image


Figure 14.13 The seven texture images used in the AppearanceTest example to illustrate Java 3D MIPMAP support—64 x 64 pixels down to 1 x 1 pixels


The individual texture images can be assigned to a Texture object as follows. Note that

Texture.MULTI_LEVEL_MIPMAP was used to activate MIPMAP support.


 

From AppearanceTest.java