Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Custom Texture Max Size

Discussion in 'Editor & General Support' started by hammerfistus, Jun 10, 2020.

  1. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    Hey there!
    I'm trying to figure if there's any way to have some custom texture max size (besides the default ones) in each texture.

    Just to be a little more clear, I want to put more different sizes on this menu.
    upload_2020-6-9_21-38-22.png

    --------------------------

    What I'm trying to achiev is having my let's say 500x500 texture be resized to 80x80 (selectable in the menu).

    I know that I can duplicate it via code and the new one can have that size. But it would help a lot to just have a few more max sizes there.

    Is that possible?
    Is there any other suggestion that doesn't involve having duplicated of that same texture?

    If there's any asset in the store that already does that, I would love to buy it <3
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,931
    Do not do that. Unity, and still for some degree the entire graphics pipeline are optimized to texture sizes in the power of 2. In theory it is possible to set texture size which is custom, but it is a very (very!) bad idea.
     
  3. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    I NEED it, even if it is a bad idea.
    The game need some custom size between 32 and 64 and 64 to 128. Because it'll all be pixelated.
    So now I don't have a middle term between it.

    I already have some games in steam that have a lot of non-po2 sprites on it. Even knowing that it isn't the ideal, sometimes it just have to be.
    I do always try to at least make it po4. At least in Unity it reduces the memory size a lot, pretty close to po2 ones.
    Not sure of other things besides memory tho.

    Could you please let me know a way to have those custom sizes?


    Really thank you for at least trying to make me go to the best way, I really do appreciate it ♥
     
  4. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    You could pad your textures with transparent pixels to bring them up to the next power-of-2 size.
     
  5. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    That's a good idea! I'll look into doing that! Thank you!
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Can you give an example of how a 50x50 sprite renders correctly in your context, while a 64x64 version of the same sprite would not? I'm just curious if the "need" you mentioned in your previous post was highly technical or aesthetic, or whether you just started out with one 50x50 piece of art, and painted yourself into a corner by basing everything off of that? It seems that depending on the screen resolution, any image might get scaled one way or the other, so I'm not sure how 50x50 is required, where 64x64 would not be satisfactory.
     
  7. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    Sure!
    upload_2020-6-10_14-55-31.png

    From left to right:
    1. original size (360x380 - 133.6kb)
    2. 128x128 max size (121x128 - 60.5kb)
    3. 64x64 max size (61x64 - 15.3kb)
    *Those KB is in unity's texture screen

    The 128 is not pixelated enough, and 64 is way too pixelated. So we need something between that.

    We can do that via photoshop or something like that, but since unity's way is just too easy to change between them (which is really good for us since we'r still in the early development and a lot of tests are being done) and work so well, just having another step between those 2 sizes would solve our problem.

    In the end I could add more empty pixels like Moonjump said, just to make the final texture po2. But for now and to achieve the desired graphic, we kinda need something to re-scale the texture easily.

    If you have any suggestion, I would really appreciate it. And please let me know if we'r doing something way too wrong xD


    -Edit: I've posted the body cuz it's easier to see the difference. The face have the same problem where 32 is way too pixelated and 64 is not enough.
     

    Attached Files:

    Last edited: Jun 10, 2020
  8. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,931
    Maybe it is a dumb question, but aren't you tricked by the texture-preview zoom? I mean if you look at the same image in the same area with different resolutions you will see different pixelizations.
     
  9. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    I don't think so? Or I didn't understand the question... That screen example is the in-game one, so the result we want is something between 2 and 3.

    - Edit: I do use texture preview to have a first look into my textures memory sizes. Which until now always shows the same number as it shows on Memory Profiler, so I think it's safe to have a base on that?
     
    Last edited: Jun 11, 2020
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,931
    Don't mind me then. I somehow put your images into Unity's texture preview window.
     
  11. hammerfistus

    hammerfistus

    Joined:
    Apr 25, 2016
    Posts:
    6
    Any thoughts on how I can solve it?
     
  12. dvdarias

    dvdarias

    Joined:
    Sep 24, 2014
    Posts:
    12
    I agree with @Lurking-Ninja, you should avoid non-power-of-2 sizes in the images. Having said this, setting the "max size" to an arbitrary size makes absolute sense when your sprites will be packed on a power-of-2 atlas by Unity.
     
  13. chaugo

    chaugo

    Joined:
    Feb 24, 2021
    Posts:
    1
    I'm also interested on a solution to what @hammerfistus asked.

    My UI images goes in power-of-2 atlases at the end. So its is not a problem to have not power-of-2 for each individual image.

    On the other hand, I use "max size" to reduce the size of some images to optimize atlas size. I could reduce the images beforehand, but using "max size" the original size of the image is stored when I want to set it to its "native Size".

    So for me it would be great to have middle term sizes between those default values.
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,786
    I've discovered that we can set arbitrary max sizes through editor scripting (by changing the TextureImporter's maxTextureSize). Wish I knew this sooner because I was also dealing with Sprite Atlases and Max Sizes of powers of 2 were insufficient for me. Now I can write a simple editor script to set arbitrary max sizes.

    Tested on 5.6.2f1, 2019.4.26f1 to 2020.3.0f1. Worked well in build, as well! The following line must also be included to support non-sprite Textures:
    textureImporter.npotScale = TextureImporterNPOTScale.None;


    P.S. Created an editor script for it: https://gist.github.com/yasirkula/dc9ec65016714fbb3747b1de6719d9b7

    Tip.png
     
    Last edited: Mar 13, 2022