Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mipmaps Lecture 13 Wed, Oct 12, 2005.

Similar presentations


Presentation on theme: "Mipmaps Lecture 13 Wed, Oct 12, 2005."— Presentation transcript:

1 Mipmaps Lecture 13 Wed, Oct 12, 2005

2 Discrete Sampling A mipmap is intended to solve a problem created by discrete sampling. Suppose we are drawing a 2-dimensional black and white checkerboard pattern. Suppose that when the surface is close to the camera, each square occupies exactly 4  4 pixels.

3 Discrete Sampling Consider one row of pixels and texels, where the pixels and texels are approximately the same size. texels pixels

4 Discrete Sampling Using the nearest texel, the pixels will be colored alternately black and white, with an occasional break in the pattern. texels pixels

5 Discrete Sampling Now suppose the surface moves a little further away so that nearly 2 texels cover one pixel. texels pixels

6 Discrete Sampling Using the nearest texel, there will be long stretches of black and white pixels. texels pixels

7 Discrete Sampling What will happen when the texels are exactly half the width of a pixel? What will happen when the texels are exactly one third the width of a pixel? Exactly one fourth?

8 Mipmaps To solve this problem, we may construct a mipmap.
mip = multum in parvo = “many things in a small place.” Rather than use the nearest texels or the average of the four texels that happen to be nearest to the pixel, we can create smaller and smaller copies of the entire texture.

9 Mipmaps If the original texture is 64  64, then we should create copies at the scales of 32  32, 16  16, 8  8, 4  4, 2  2, and 1  1. If the original texture is 64  16, then we should create copies at the scales of 32  8, 16  4, 8  2, 4  1, 2  1, and 1  1.

10 Mipmap Levels The original texture is level 0.
The next level is level 1. And so on.

11 Level 0 Mipmap – 64  64 One pixel

12 Level 1 Mipmap – 32  32 One pixel

13 Levels 2 – 6 Mipmaps One pixel 16 x 16 8 x 8 4 x 4 2 x 2 1 x 1

14 Level 0 Mipmap – 64  64 One pixel

15 Level 1 Mipmap – 32  32 One pixel

16 Level 2 – 6 Mipmaps One pixel 16 x 16 8 x 8 4 x 4 2 x 2 1 x 1

17 Programming Mipmaps Mipmaps are implemented using the same function glTexImage2D() that we used to set the original texture. The second parameter is the level. glTexImage2D(GL_TEXTURE_2D, 0, …, 64, 64, …, image); glTexImage2D(GL_TEXTURE_2D, 1, …, 32, 32, …, image1); glTexImage2D(GL_TEXTURE_2D, 2, …, 16, 16, …, image2); : glTexImage2D(GL_TEXTURE_2D, 6, …, 1, 1, …, image6);

18 Mipmap Example Read Run

19 Close-up of Level 0

20 Close-up of Level 1

21 Close-up of Level 2

22 Close-up of Level 3

23 Close-up of Levels 4, 5, and 6

24 Using Mipmaps When using mipmaps, we have two separate choices.
Whether to use the nearest texel in a mipmap or to interpolate among the 4 nearest texels. Whether to use the nearest mipmap or to interpolate between the nearest two mipmaps.

25 Using Mipmaps Thus, the choices are Which is the most “expensive”?
Nearest texel, nearest mipmap Nearest texel, interpolate mipmaps Interpolate texels, nearest mipmap Interpolate texels, interpolate mipmaps Which is the most “expensive”? Which gives the best results?

26 Interpolating Between Mipmaps
Assume that a single color has been selected from each of the nearest two mipmaps (from either the nearest texel or an average of texels). Compute the scale factor r between the level 0 (original) mipmap and the polygon. Then compute  = log2 r.

27 Interpolating Between Mipmaps
The value of  tells us which mipmap to use. If  = 0, use level 0. If  = 1, use level 1. If  = 2, use level 2, etc. What if  = 1.5? Then we interpolate between level 1 and level 2. Different scale factors may be used for different regions of a single polygon.

28 Example Suppose  = 1.3 and the level 1 mipmap color is yellow (1, 1, 0) and the level 2 mipmap color is cyan (0, 1, 1). Then the interpolated color is 0.7(1, 1, 0) + 0.3(0, 1, 1) = (0.7, 1.0, 0.3). 0.7 + 0.3 =

29 Trilinear Interpolation
If we interpolate bilinearly within mipmaps and then interpolate those values between mipmaps, we get trilinear interpolation.

30 Trilinear Interpolation
How many individual interpolations are required to perform trilinear interpolation?

31 Trilinear Interpolation
4 from “left to right” (s direction).

32 Trilinear Interpolation
Plus 2 more from “front to back” (t direction).

33 Trilinear Interpolation
Plus 1 between levels = 7.

34 Interpolating Mipmaps
Use the glTexParameter*() function to set the method of applying mipmap filters. glTexParameteri(GL_TEXTURE_2D, filter, method); The third parameter is GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR

35 Mipmap Example Read Run code

36 Generated Mipmaps OpenGL is capable of generating the mipmaps, given the original texture. This is very handy when the original texture is read from a bitmap file. Use the function gluBuild2DMipmaps(). gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_UNSIGNED_BYTE, image data);

37 Generated Mipmaps Read Run


Download ppt "Mipmaps Lecture 13 Wed, Oct 12, 2005."

Similar presentations


Ads by Google