Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Is it possible to turn on Mip Maps for a sprite?

Discussion in '2D' started by holyfuzz, Dec 23, 2013.

  1. holyfuzz

    holyfuzz

    Joined:
    Nov 16, 2010
    Posts:
    21
    Hey all,

    I'm wondering whether it's possible to use mipmapping in conjunction with the new Unity sprites. If I set a texture's 'Texture Type' to Advanced, then the editor will allow me to both turn on 'Sprite Mode' and turn on 'Generate Mip Maps'. Unfortunately, the 'Generate Mip Maps' option has no effect if I use the sprite in conjunction with a Sprite Renderer -- whereas if I render the texture the "old" way (by using a simple quad + Mesh Renderer), then the mipmapping works fine.

    Any advice on how to make this work? Is it just not supported right now?

    (FYI, I am *not* packing these sprites into atlases, which can cause problems with mipmapping anyway.)

    Thanks!
     
  2. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    No mip maps for sprites unless you use quad + mesh method. It's a 3D thing really.
     
  3. holyfuzz

    holyfuzz

    Joined:
    Nov 16, 2010
    Posts:
    21
    Thanks for the reply... that's pretty odd though. Not sure how I'm supposed to be able to scale down sprites and have them still look okay without mipmaps. I guess I'll stick with quads for now.
     
  4. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    You're not supposed to be able to do this with true 2d but you can always create difference sized versions of your sprites. If you absolutely need mipmaps then use pseudo-2d by way of 3d quads, you can't go wrong there.
     
  5. eezSZI

    eezSZI

    Joined:
    Nov 16, 2012
    Posts:
    121
    I think a lot of devs using unity for 2D have utilized mipmaps, whether it's technically meant for it or not. It's very helpful when you use non-retina size textures on a retina device for example. We will often have an atlas that shows poor scaling quality depending on the device we are testing (iPad1, iPad3, phone) and set the atlas to include mipmaps to improve. It just makes them softer on different screen sizes. Also improves in game scaling as holyfuzz stated.

    Scaling a sprite that has mipmaps is the same idea as a 3D terrain having mipmaps. The most optimized version is used depending on the distance (or size) it is on the screen.

    I think it would be a great feature to add to the overridable packerpolicy so that the atlas can have mipmaps enabled. It's just something that makes switching from a 3rd party 2D system to Unity's easier. I'm more comfortable using Unity's system in terms of support (or risk of losing support) in the future.
     
  6. holyfuzz

    holyfuzz

    Joined:
    Nov 16, 2010
    Posts:
    21
    Yeah, I'm not sure why unitylover says "You're not supposed to be able to do this with true 2d", unless by that he means "you're not supposed to use modern graphics hardware for 2D games". Mipmapping has nothing to do with 3D rendering -- it's just picking the most appropriate texture depending on the size of a polygon. (In fact, it actually works best when polygons are perfectly flat to the screen, as in 2D.)

    I've used (and have written) a lot of 2D tools/engines outside of Unity, and they all support mipmapping, because it's just such a basic requirement if you want to do any runtime sprite scaling. Unity should support it as well.

    Getting it to work with atlases is definitely trickier though... If you aren't careful about aligning your sprites to power-of-2 boundaries on the atlas, then you can get bleed between sprites in the mipmaps.
     
    Last edited: Jan 24, 2014
  7. unitylover

    unitylover

    Joined:
    Jul 6, 2013
    Posts:
    346
    All I meant was that mipmapping is something that originated as a 3D technique, not that it shouldn't be used. Since this post was written, I've noticed there is now a setting to enable mipmaps for Sprites if you import them as "Advanced" so please disregard my earlier comments.
     
  8. eezSZI

    eezSZI

    Joined:
    Nov 16, 2012
    Posts:
    121
    True, that's where padding comes in.
     
  9. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Just confirming that mipmaps do indeed work with Sprites, but you must switch to Advanced import mode to enable mipmaps.

    Sprite atlas mipmaps will be coming in a future release of Unity, I'm sure.
     
  10. holyfuzz

    holyfuzz

    Joined:
    Nov 16, 2010
    Posts:
    21
    Yep, confirmed working in Unity 4.3.3. Simply upgrading from 4.3.1 to 4.3.3 fixed it for me. So thanks for that fix!
     
  11. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    Has Sprite atlas mipmaps already been implemented (as said by @TomasJ)? If not, does anyone know what version of Unity will it be on?
     
  12. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
  13. zee_ola05

    zee_ola05

    Joined:
    Feb 2, 2014
    Posts:
    166
    thank you so much!
     
  14. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    I'm using a custom sprite packing policy and setting generateMipMaps to true and mipmaps are generated. I am now trying to solve the issue of bleeding sprites into others.

    1.) paddingPower. I'm setting this which introduces (2^(paddingPower+2)) black or transparent pixels between the sprites however this then means that the edge pixels gain a percentage of black or transparent. I had hoped that it would round the position of the sprite to a multiple of 2^(paddingPower+2) that would then at least ensure that the left bottom most edges would maintain their colour, the right and top most edges could then be maintained by ensuring the problem sprite(s) were a multiple of say 4 in dimension.

    2.) I'm really looking for a proper solution of extruding (copying) the edges of the sprite by the padding amount. I had hoped that was what the extrude edges option was in the advanced texture settings, but I can't work out what that actually does.

    3.) Ideally there would be a way to modify the created texture after packing, so in the sprite packer after the pack job completed a callback to allow us to modify it (extrude pixels etc) would allow custom solutions.
     
  15. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    1) You're right, it doesn't fill in the borders in this case. I'll put it on our TODO list.
    2) The extrude edges option in texture settings enlarges the generated tight mesh by the given amount in case you need that texture space for something.
    3) That's totally doable, but we would like to know the exact use cases. If it's only border fill, we better just implement it natively.

    Edit: we're talking about problems with linear filtering of lower mip levels, correct?
     
    Last edited: Sep 10, 2014
  16. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    516
    Sorry to bump this thread, but could you please expose the Anisotropic settings on the atlas texture too? I was trying to to use the sprite atlas system to save some time by putting the faces of a 3D die on an Atlas. However, the face sprites would be viewed at such extreme angles that the mipmap would look bad. I'm not seeing any option in the AtlasSetting to be able to enable this, and I don't want to enable it for all of the atlases in my project, just for the atlas. I really wish that the atlas was a fully accessible asset in my project so I could enable texture settings via inspector.
     
  17. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Already in 4.6.
    As for accessible asset - due to the automatic on-demand nature of our atlases, that's not easy to implement right now. Maybe in the future.
     
  18. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    Yes I was talking about how the lower mip maps are created and start to include pixels from neighbouring atlases.
    Thanks so much for the reply. I hadn't noticed it sorry. But yeah the latest betas now have border fill which makes me really happy! So for my use case I don't need option 3 above as you've implemented it hurray and thank you.
     
    TomasJ likes this.
  19. PaulioGo

    PaulioGo

    Joined:
    Dec 13, 2014
    Posts:
    1
    Hi everyone. With the Generate Mip Maps option exposed, I thought it would be a good idea to use. The thing is, even though I see a new atlas being generated, with blurrier images, the resolution stays the same. So without generate mip maps its 1024x1024 looking nice, with generate mip maps its 1024x1024 with the sprites taking just as much space on the atlas, but looking low res. Seems weird. Is this a bug?
     
  20. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    Where do you see that resolution stays the same? In Sprite Editor and Sprite Packer windows we make the texture look like the original so that you could manipulate sprite shapes.
     
  21. andsee

    andsee

    Joined:
    Mar 20, 2012
    Posts:
    88
    I suspect that this is because the atlas texture has the default mipMapBias, which on last inspection resulted in things being slightly lower res than necessary, I have it on my todo list to check this and write something that finds all atlas textures in the scene and sets their mipMapBias. I wonder if that could be done in a custom packing policy...
     
  22. Crzed

    Crzed

    Joined:
    Oct 19, 2013
    Posts:
    23
    So it's been a few years... Any word on sprite atlasing working with mipmapping correctly?
     
  23. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    I use mipmapping on my sprites because I have a smaller 'radar/scanner' and it looks reasonable. If the sprite is in any way scaled down even by a tiny fraction it will kick in the next lower resolution mipmap. For the most part my main sprite looks perfectly ok and doesn't appear to be pulling from a lower mipmap level, so I would say this seems to work properly.
     
  24. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    855
    but when I use mipmap on sprites I can see changing!!! also change filter mode caused to change in sprites!