Search Unity

How can I manually generate texture mip maps?

Discussion in 'General Graphics' started by Snubber, Apr 7, 2021.

  1. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
    Hello! I am creating a game with block build (like Minecraft) I have all of the block textures combined into one texture for performance reasons. But automatically generating mip maps blends the textures together. Is there a way to manually generate mip maps?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,338
    There is. You can write a custom script to create a
    Texture2D
    asset with and generate the mip maps manually. But it won't really fix the problem. The problem isn't so much that they're blending together, that'll happen eventually no matter how you generate the mip maps once the mip resolution is less than the number of tiles. The issue is is by default Unity will always create a texture with the maximum possible mip levels. When you're using an atlas you'll want to limit the mip level to something larger.

    To create a Texture2D with a limited number of mip maps, you have to create it from script anyway.
    https://forum.unity.com/threads/limiting-the-amount-of-mipmap-levels.650011/
     
  3. Snubber

    Snubber

    Joined:
    Jan 20, 2020
    Posts:
    65
    I have discovered in Unity 2020 you can import a texture atlas as a texture2darray which fixes the mip map generation issue!
     
  4. AljoshaD

    AljoshaD

    Unity Technologies

    Joined:
    May 27, 2019
    Posts:
    229
    Using a Texture2DArray is a great solution if your textures have the same size, 2K for example. Each slice is mipmapped separately and the textures cannot "bleed" into each other on higher mips.

    With a regular texture atlas, the more padding added between textures, the more mipmaps you can have with bleeding.

    On creating custom mips, you can import a dds file that contains mipmaps. Unity keeps those mipmaps.
     
  5. Rangaros

    Rangaros

    Joined:
    Apr 2, 2021
    Posts:
    4
    Texture2DArray doesn't support mipmap streaming though. So it is going to increase your memory amount
     
    zwcloud likes this.