Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

What is the purpose of the mip maps? And how they work?

Discussion in 'General Graphics' started by Deleted User, Aug 26, 2017.

  1. Deleted User

    Deleted User

    Guest

    I can't find so much on the web and I can't understand its purpose. I have seen on Wikipedia that it is like... You put a texture, and the engine will enlarge it adding scaled copies of the image at half size. And ok.
    But how they work? Does the enging resize the UV maps, shifting them on the mip maps? And what about the seams?
    And the main question is... What is their purpose? I can imagine that they're used for objects that are far away and that don't need of HD textures, but since the textures are still loaded fully (I think) because the mip maps are created on it, what is the advantage? And are there other usages?
    Last question, optional: I have read that they prevent those bad effects with black close lines on the surfaces when you see them almost in parallel. Why?

    Thanks to all in advance. :)
     
  2. eXonius

    eXonius

    Joined:
    Feb 2, 2016
    Posts:
    207
    I don't think you need to worry about the UV maps they should indeed be scaled according to the mip maps.

    As I've understood there are two purposes of a mipmap:

    1. It can be faster because the GPU don't need to fetch as much data from the GPU memory to show a smaller mip map (less pixels to loop over).

    2. It can look better at a distance because it will choose to show the texture of a resolution that's close to the actual resolution it will be displayed in.

    If you're unsure about if to create mip maps, just test how your game looks with and without mip maps enabled.
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    UV maps are a 2d position relative to the texture's bounds. The dimensions or aspect ratio of the texture have no affect on the UVs. A UV position of 0.5, 0.5 is the middle of the texture if it's 2048x2048, or 4x4, or 1280x96.

    As for mip maps, imagine you have a 256x256 texture with a lot of details in it. Now imaging it's being displayed on screen at only 64x64 pixels. That's 1/4th the original resolution. With out mip maps the GPU is basically going to render 1 out of every 16 pixels from the original texture as one on screen pixel covers an area of 4x4 pixels. This results in a lot of aliasing as many of the details from the original texture are simply missed. Mip maps handle this case by having a version of the texture that's already 64x64 with each pixel color being an average of those 4x4 pixel areas from the original larger texture.

    Here's an example of a worst case scenario. This is a very high contrast brick texture.
    brick 256.png

    And here's a simulation of what that texture looks like scaled down to 64x64.
    brick 64 nearest.png
    In real use it'll rarely be this perfect, here's what it looks like at 69x69 pixels.
    brick 69 nearest.png
    You can see several of the small details are simply missing, or seem to fade in and out over the texture.

    This is what the same scaled down image would look like with mip maps.
    brick 64 bilinear.png
    As you can see all the lines are still apparent, or at least they contribute somewhat to the image. Even if it's not perfectly scaled down it still looks mostly right.
    brick 69 bilinear.png
     
    iSinner, danidina330, diegoop and 9 others like this.
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Hmm ... not really. If anything mip maps will cause this problem more than prevent it. UV seams are kind of the Achilles heel of mip maps. However if you're getting black lines it's because you're leaving the area of the texture the UVs don't cover black. You should choose a color that's closer to the average of the rest of the texture, or use something like XNormal's photoshop filters to dilate the texture's edges.
     
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Also Mip map kicks in when image are seen as a grazing angle, and you can put arbitrary image in the mipmap level, which can lead to interesting effects or controlling the visual at far distance. For example mario sunshine on gamecube use some of those effect to make their ocean effect at no cost.
     
  6. Deleted User

    Deleted User

    Guest

    Oh, many thanks! Ok, bgolus you really opened my eyes about them. :)

    Cool about seams, thanks.
    About vertical black lines, maybe I have explained it wrongly, I was referring to this sentence:"The main purpose of this technique is to maintain texture definition on surfaces further from the camera and to avoid unslightly moiré patterns which can appear on surfaces, especially as they approach an angle parallel to the axis of the camera." that I've found here https://developer.valvesoftware.com/wiki/MIP_Mapping

    neoshaman, can you give me a visual example of what you're meaning about Mario Sunshine's ocean? Just to understand it better.
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    That's exactly what the 69x69 examples are actually showing. One has a strong moiré pattern, the other does not.

    https://www.gamedev.net/forums/topic/614608-specular-highlights-on-water/#entry4881841
    Mip maps are in their most basic sense just multiple textures the GPU automatically blends between over distance. There's no technical reason they have to be of the same texture for each mip level. In the past it was really common for game engines to have a "mip map view" so you could visualize the resolution of the mip maps being used. These all worked by just coloring each mip level a different color.
     
  8. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    On top of bgolus forum's, here is the same thing in video format :D
     
  9. Deleted User

    Deleted User

    Guest

    Really many many many thanks, now I understood all (at least, at this basic level) and I couldn't expected anything better than these so complete answers. Thanks again guys! ;)