Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
88 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

  Contents

 Introduction
 Mip-Map Factory
 Rendering Pipeline
 Direct3D
 Implementation


 Printable version

 


Mip-Map Factory

Say you have a detailed texture of size 128 x 128. If you down-sample it by a factor of 2 simply by taking the average of every 2 x 2 texel area, you end up with the same texture at 64 x 64, just with less detail. But you won't need the detail because you will only view it from further away. This becomes our level one mip-map (the original texture is refered to as level zero). If you repeat the process on your newly generated texture, then you get level two, and so on. Generally you stop at a smallest of a 2 x 2 texture (after that, you just have a single solid colour).



Mip-maps generated by averaging 2 x 2 texel areas.

Below is some sample code for generating the image data for the mip-maps.

/* example C code for generating mip-maps (recursive function) */ /* NOTE: this is untested (and un-optimal ;) */ void MakeMipMaps( Texture *parentTexture) { int width = parentTexture->width / 2; int height = parentTexture->height / 2; Texture *newTexture; int u, v; int texel; /* we want to stop recursing after 2 x 2 map */ if (width < 2) return; if (height < 2) return; newTexture = CreateTexture( width, height); /* find the new texture values */ for (u = 0; u < width; u++) for (v = 0; v < height; v++) { /* sum up 2 x 2 texel area */ /* for simplicity of example, this doesn't seperate the RGB channels like it should */ texel = GetTexel( parentTexture, u * 2 , v * 2 ) + GetTexel( parentTexture, u * 2 + 1, v * 2 ) + GetTexel( parentTexture, u * 2 , v * 2 + 1) + GetTexel( parentTexture, u * 2 + 1, v * 2 + 1); /* take the average */ texel /= 4; PutTexel( newTexture, u, v, texel); } /* make a link to the mip map */ parentTexture->mipMap = newTexture; /* recurse until we are done */ MakeMipMaps( newTexture); }



Next : The Rendering Pipeline