Search Unity

PNG vs JPG

Discussion in 'iOS and tvOS' started by Adrenaline-Crew, Feb 20, 2012.

  1. Adrenaline-Crew

    Adrenaline-Crew

    Joined:
    Dec 14, 2010
    Posts:
    400
    I am aware that PNG files seem to be bigger then JPG when you import into the project, my question however lies within what the process is that in turn takes these to the .mat file. If I use a JPG compressed to 200kbs which is same picture under PNG at 1.3megs is the .mat file going to be larger or does it compress it all down to the same size file?

    Thanks!
     
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    Uncompressed(the form they take once loaded in game as a texture) they will be identical in size.

    In a little more detail about the two formats.
    JPEG is a lossy format (loses data), and so will contain less information once uncompressed again, meaning it can have artifacts. However it is really good for compressing photos and other high detail images, due to the algorithm it uses and can consistently compress to small sizes regardless of content. For the most part, it's not a huge deal that it's lossy, but it should be known.
    PNG is a lossless format (doesn't lose data), and so it will be identical to the original. However due to how it compresses (called Deflate, and basically compresses identical consecutive pixels to a pixel and a count, similar to how zip files compress), it's best at cartoony images, or images with minimal gradients. The more colours and more gradients the less it will be able to compress. Also because .zip and .png compress the same way, putting a .png into a .zip results in minimal compression, and can sometimes make the zip larger than the original file.
     
    Suduckgames likes this.
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The format of the source images is irrelevant, what matters is the settings in Unity. You generally have a choice between RGBA32 uncompressed, 16-bit uncompressed, and hardware compression such as DXT or PVRTC. There's usually no point using JPG since it's lossy and won't be used in the project anyway. i.e., uncompressed is uncompressed regardless of what the image was originally.

    --Eric
     
    Suduckgames likes this.
  4. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,107
    The .mat file does not contain the texture so it's size shouldn't differ based on your texture size.
    When importing textures, Unity imports them into a number of possible formats (which you have control over in the import settings). This is what defines the texture's size in your app - not the source. So it's always best to use pngs over jpgs, as the source size does not affect the imported image's size.
    Edit: oops, had this thread open for a while before responding, and others already responded :)
     
    Hedzerjan likes this.