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. Dismiss Notice

How should HD sprites be scaled/optimized?

Discussion in '2D' started by PhantomFox128, Sep 4, 2020.

  1. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    Yes, it's one of these questions again, but believe me, I wouldn't be asking if I was able to find an answer that made sense.

    Unlike what seems to be practically every other developer that's making a platformer, I am NOT using a pixel art style, nor am I releasing on mobile platforms. I'm making a game with high resolution, hand-drawn sprites (think Rayman or Shantae: Half-Genie Hero/Seven Sirens) that I plan to release for PC and possibly consoles in the future. No mobile, no pixel art.

    Now for some context: I have read, thanks to this blog post, that sprites should be made at double the resolution you're aiming for, so my amateurish mind figured that, since I want at least a 1080p resolution, I should just make all sprites at double that number. As such, most sprites I've made have been at a resolution of 2048 x 2048, with a lot being either bigger or smaller depending on what I'm doing. For example, a crouch maneuver I have is at a resolution of 1868 x 1360 (the character is smaller while crouching, so the sprite is smaller), while an attack is at a resolution of 4484 x 2048 (the attack hits roughly the length of the character in front of them, so the width is roughly doubled). Now, the reason it's like this is because I make what I call the "Main Sprite" at a 2048 x 2048 resolution and every action that's animated is derived from that sprite. This is to make sure everything is consistent so I can get smooth animation transitions. I also manually export each frame of an animation as its own image. No sprite sheets. Don't know if I shouldn't be doing that way, but I'm doing it.


    What I want to know is, assuming they're too big, how should I go about scaling sprites like this? Should I be manually scaling them via the Transform component, in the import settings, or scale them in the art program I'm using? I've had a conversation with another user who's gave me good advice on the matter, but there's still some things that aren't clear.

    The gist of it is, for HD sprites, I should keep the PPU at the default 100 (for now, my main character's PPU is 500, with everything else being more or less close to that. I've basically been using the PPU to scale things). My problem with that is, since the sprites are really big, they end up being massive, to which I was told that I simply need to zoom out the camera. Now, I sort of get the idea behind this approach, except doing it this way makes things like store-bought particle effects a lot smaller compared to the sprites. I also can't help but think that this could lead to performance problems down the line.
    The way I've been doing it (500 PPU for main character along with a Max Size of either 1024 or 512, depending on the sprite) has been working well so far. Builds tend to perform flawlessly, as far as I can tell. I'm just wondering if there's a better way that I should be doing. I've been going down this massive rabbit hole trying to find some answers to no avail. Everything is either contradictory or, as stated above, the devs asking are mobile devs using pixel art, which a whole different beast.

    If there's anyone out there that can shed at least a bit of light on this, please let me know, and thanks in advance.
     
    EvOne likes this.
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    You don't need to make each sprite at 2k/4k - you should have double/triple the max they will appear on-screen just in case you decide to rescale in the future. That gives you some room. Since most things sprites don't occupy the entire screen, they could be safely be... 256, 512.. etc. But as with all things it depends: how zoomed in do you allow it to get, etc.
    Do NOT use the transform component for the typical use case. If you want to reuse some art at a smaller/lower size, ok, but in the general case produce art at a level where you can consistently apply a single PPU across everything without too many exceptions. That will reduce the maintenance burden.

    Aside from that, note the TextureImporter settings.
    https://docs.unity3d.com/2019.1/Documentation/Manual/class-TextureImporter.html
    You can produce your sprites a higher resolution then cap the Max Size. This affects the default platform setting. You can set per-platform differences. Lets say you have a sprite that at max will occupy about 512x512 of the screen. You produced it at 1024x1024. You can set the MaxSize to be 512x512 if you want to use a lower resolution. If you later decide to change how much space a sprite occupies relative to the screen, you can loosen its MaxSize.
     
    PhantomFox128 likes this.
  3. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    Thanks for the reply! So, if I decide to go the default PPU route, would that mean I'd have to redo all my sprites or could I keep them the same size and simply adjust the Import Settings? Would this also affect the other sprites that are at different sizes?

    How would I go about this for other sprites that need to be at a different size in game? When I make sprites, I tend to use most of the canvas and, as of right now, every original sprite I make starts at a size 2048 x 2048. With that in mind, how would I scale things like enemies or bosses that aren't the same size as the player? With the way I'm doing things now, if I import them at 100 PPU, then they end up being roughly the same size as the player, which is something I don't want for most enemies.

    Lastly, what do I do about particle effects? All the effects I have are from the asset store and, by default, compared to the sprites at their original sizes, they're pretty small. Is it okay to simply scale them via the Transform component or within the particle system itself? Is there a better way to go about it?

    Or am I just not getting it and they need to be scaled down in the art program I'm using?
     
    Last edited: Sep 5, 2020
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    the only thing that matters for sprite size is the size of the original image (.png)

    Its ok to draw sprites at 2048x2048, however you dont import them to unity like that, downscale them in photoshop using bilinear mode to 1024x1024( if your game is 1080p resolution)

    PPU and scale is irrelevant for the size you draw your sprites. These 2 settings will make your sprites look bigger or smaller at no performance cost at the end of the day the cost is the size of your source image, which should be as small as possible if you want better optimization, or larger if you want better graphics at greater memory costs.

    The perceived scale differences ingame due to ppu, scale and camera zoom are all a matter of relativism, if your store bought particles are not scalable to your needs its a fault of the asset you purchased.
     
    PhantomFox128 likes this.
  5. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    You don't have control over others' assets, so use scale freely. My scale comments are about getting a consistent sizing. Scale is for if you have a plant and want to make that plant 2x as big without creating different texture for it. That's perfectly fine/intended usage.

    For example, in my workflow, I have a a template file for new artwork. This template includes a layer for which contains a sizing guide. This is just a square. If I wanted to produce an enemy that's about twice the size of the player, I size it relative to the sizing guide (which is the same size as the player!). This lets me keep it consistent at the art level. Then I apply a PPU that's appropriate when importing to Unity.
     
    PhantomFox128 likes this.
  6. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    So, if I'm understanding this right, the only thing that matters is the size of the original source image and it should be scaled down to an appropriate size in the art program? Is it okay for the PPU to not be at the same number for everything then or will that cause issues?
     
  7. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    ppu in itself has nothing to do with resolution

    the coordinate system in unity (x,y,z) is measured in units. How many pixels are in a unit? thats for you to decide

    ppu defines how many pixels should be in a unit. If you set PPU to 1, it means that one unit = 1 pixel. If you set PPU to 32, now 1 unit = 32 pixels.

    Now what happens if you change the scale in the gameobject transform: if you have an asset with 32PPU and you increase the scale to 2 it is the same as halving your ppu ( 16 pixels of your art wil occuppy 1 ingame unit)

    Now if you want the best practice, you should apply the same PPU to every asset( or use different ppus and correct it with scaling but this is just an headache for you)

    To answer your question, having different ppu will make it so that 1 pixel in one image will occupy more units than in another( this is a critical mistake for pixel art games, but since you are not doing pixel art, well, people might not even notice it)

    Lastly, use at least 16 or 32 ppu, because unity's coordinate system is made of 3 floating points if your sprites occupy too much space you will start getting rounding errors, as a rule of thumb never let your map grow larger than (99999,99999,99999) > that's 5 figures with space for 2 decimals ( floats allow 7 or 8 figures before it becomes unreliable)
     
    Last edited: Sep 5, 2020
  8. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    I'm not sure if I'm following. I think what I'm wondering about now is, is it best to use the PPU to scale everything then? When you say apply the PPU to every asset, does that literally mean everything, even things like terrain, backgrounds, enemies, etc., or can those be different from each other to get the correct size in game? Or should that be done before it gets imported?
    Could you elaborate on this? This is the first time I've heard of this sort of thing.
     
  9. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    Don't use ppu for scaling, use the same ppu in EVERY asset. ( best practice )
    you can create a preset so that everything you drag into the project gets automatically the ppu you want without needing to go mess with the settings every time

    use transform scale to change the size of objects

    a float is a 32bit variable that has a limited size which means that at larger numbers decimals will start to get rounded and you lose accuracy and things get wonky for example: 1,14242353 /2 = 0,571211765 ( ok ), but 9999999,14242353/2 = 4999999,571211765 has to many digits and it will be truncated to something like 4999999,571 as you see this generated an approximation error. This can happen if you do something silly like setting your assets at 1 PPU and then make a map that is larger than 99999 units
     
    PhantomFox128 likes this.
  10. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    So it is okay to use the transform component then? It's mentioned earlier in the thread to not use it, so I'm confused there.

    Also, how much does the size of the source image actually matter? I've put all my sprites in my project unaltered at their original sizes and adjusting the Max Size setting and using crunch compression seems to dramatically lower the overall file size on builds. Is it actually important to make the sprites smaller before they go into Unity or does it not matter in the long run?
     
    EvOne likes this.
  11. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    compression may lead to visual artifacts on your images ( again easier to spot in pixel art, maybe it wont bother you)
     
  12. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    I haven't noticed anything so far when using compression.

    At this point though my only question is, how should I scale the sprites? Looking back at the other posts, everything seems to be contradictory. Use the same PPU for everything or apply an appropriate PPU for the sprites on import? Is it okay to use the transform component or not?
     
  13. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    The confusion is that there are too many senses of the word "scale." Scale (on the transform), the scale of the digital artwork, and PPU - all these affect the overall scale.

    1. Make art at consistent scale. With consistently scaled art, you can then use the same PPU everywhere.
    2. Use the transform's scale when you want to reuse the same art at a different scale. If you have two enemies, a huge boss and a tiny minion (which for this example both use the same sprites), make art for the boss. Apply the same PPU as you do everywhere else. Because the PPU implies now the minion is far too large (boss-sized), use the scale on the transform to downsize the minion.
     
    PhantomFox128 likes this.
  14. estebanpdl

    estebanpdl

    Joined:
    Aug 5, 2020
    Posts:
    4
    I have been looking for an answer as Azerkit. I am not an artist or designer. So, looking for an answer about resolution makes things more complicated in my case.

    Following the second point here: use the scale on the transform to downsize the minion,
    Wouldn't this affect physics?

    What do you mean about Make art at consistent scale? Like using a resolution range?
     
  15. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Physics
    Yes, it will affect the physics, which is desired most of the time. A small minion should have a smaller collider than a big boss, for example.

    Art at consistent scale
    Let's say your character is 512x512. If you want another sprite that's twice as tall, use 512x1024. This allows you to use the same PPU for both.

    Most of the time, though not strictly necessary, its best to produce source art that allows you to use the same PPU everywhere. Through this consistency, this lets you make better guesses about how to size your art before you make it. "I want a boss that will ultimatley be sized about 3x the size of the player character" is easy to think about by using a common sprite (e.g. player) as a reference.
     
    estebanpdl likes this.
  16. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    go to photoshop and create a 1920x1080 canvas

    now draw a screen shot of your game in that canvas

    when you are happy with thescreenshot, export each element individualy and you will have the size your assets should have.


    If you find yourself with art that is too large, downscale it in photoshop in bilinear mode or bicubic whicherver you find feels best
     
    SteelyResolve and estebanpdl like this.
  17. estebanpdl

    estebanpdl

    Joined:
    Aug 5, 2020
    Posts:
    4
    Thanks for your answers, @Lo-renzo, and @rarac.
    I really appreciate it.
     
  18. estebanpdl

    estebanpdl

    Joined:
    Aug 5, 2020
    Posts:
    4
    Do you guys think that one possible approach would be to create the sprites with a resolution of 1024x1024, and then downscale those in photoshop to, let's say, between ~152 to ~172 height, in order to use a 100 PPU?
     
  19. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    thats almost 10x smaller, the sprites will be very pixelated that way
     
  20. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    Keep your source art large. You can scale down by using the TextureImporter (see above posts). There's no inherent advantage to 100 PPU (or any round number).