Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mipmaps Lecture 16 Mon, Oct 1, 2007.

Similar presentations


Presentation on theme: "Mipmaps Lecture 16 Mon, Oct 1, 2007."— Presentation transcript:

1 Mipmaps Lecture 16 Mon, Oct 1, 2007

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 enough to the camera and oriented just right that each texel matches exactly one pixel.

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

4 Discrete Sampling Using the nearest texel, the pixels will be colored alternately black and white. texels pixels

5 Discrete Sampling What if the texels were ever so slightly smaller than the pixels?. texels pixels

6 Discrete Sampling What if the texels were ever so slightly smaller than the pixels?. texels pixels

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

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

9 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?

10 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.

11 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.

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

13 Level 0 Mipmap – 64  64 One texel

14 Level 1 Mipmap – 32  32 One texel

15 Levels 2 – 6 Mipmaps One texel 16 x 16 8 x 8 4 x 4 2 x 2 1 x 1

16 Level 0 Mipmap – 64  64 One texel

17 Level 0 Mipmap – 64  64 One texel

18 Level 1 Mipmap – 32  32 One texel

19 Level 2 – 6 Mipmaps One texel 16 x 16 8 x 8 4 x 4 2 x 2 1 x 1

20 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);

21 Mipmap Example Read Run

22 Close-up of Level 0

23 Close-up of Level 1

24 Close-up of Level 2

25 Close-up of Level 3

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

27 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.

28 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?

29 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.

30 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.

31 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 =

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

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

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

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

36 Trilinear Interpolation
Plus 1 between levels = 7.

37 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

38 Mipmap Example Read Run code

39 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);

40 Generated Mipmaps Read Run


Download ppt "Mipmaps Lecture 16 Mon, Oct 1, 2007."

Similar presentations


Ads by Google