Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dds ,jpeg or png

Discussion in 'General Graphics' started by tawdry, Nov 24, 2015.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi
    Running into some memory issues with my png textures thought maybe using a different format could help.Just noticed that dds files are much smaller than png would this remain the case when converted by unity in the build or will it be the same as the png file(size diff 6mb png to 2mb dds).My other option is to use jpeg as it has no alpha channel but will this look worse with the standard shader which has some relience on a alpha channel I seem to remember reading?
     
  2. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    You should consider use GPU compress texture format.
    => use PVR on ios
    => use ETC on android
    => use DXT on desktop
     
    theANMATOR2b likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Unless you're loading them at run time directly, the file format of your source files has nothing to do with the file size of the format used by the game. All of the image formats real time graphics use scale linearly with the resolution unlike JPEG and PNG which scale based on image content and resolution.

    If your game is taking up too much space you'll want to look at reducing the resolution of your textures either by scaling the source files or clamping the max size in the editor. Also removing the alpha from any textures that don't need it will reduce the file size in half in many cases. For the standard shader the metalness texture stores the glossiness in the alpha, and the alpha of the diffuse texture might used if you've set it to something other than opaque. None of the other textures in the standard shader textures need an alpha.
     
  4. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hi
    So bgolus what you are saying is use jpeg when I don't need alpha and us png for the specularity/metalness spot?

    Steven called he wants his name back. I do compress the textures already that 6 mb is 22mb uncompressed.
     
  5. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Do not use jpeg.
     
  6. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Oh boy but Its the only image I know that does not have alpha. What is so wrong with Jpeg anyway?
     
  7. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,631
    Well, then you don't know many image formats :)

    Jpeg does lossy compression, that's what's wrong with it.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I use the full layered PSD or occasionally TGA files myself. The PSD files can be a few hundred megabytes at times for a 2048x2048 texture.

    The file the game uses in the end is just over two and a half megabytes. It would be 2 1/2 megs even if the source was a 2048x2048 JPEG compressed down to 190kb because 2.6 megs is how big a 2048x2048 DXT1 texture is.

    However that DXT1 that used the heavily compressed JPEG for its source file is going to look like sh*t, where as the one that came from the PSD, TGA, or PNG will all look the same since they're all loseless formats.

    As @AcidArrow said, don't use JPEG. I don't even like using PNG since most graphics programs don't handle the alpha channel nicely. They have a (usually good) assumption that any part of the texture that is 100% transparent can have the color information deleted to save space. This is good for the web, but bad when 100% transparent is supposed to mean the surface is really rough with a colorful specular color that your graphics program just erased.

    So, to reiterate. The file format of the source doesn't matter for the size of the game's textures. If they're using too much space you probably need to reduce the size of the textures (by reducing the resolution, removing alpha or mipmapping where not needed, etc) or think about removing some of them from the game and find creative ways to reuse textures. If your PNG file is completely opaque, Unity is smart enough to know not to compress it as a DXT5 (which is twice the size of DXT1), you you can also force it to compress as DXT1 or some other format with out alpha for mobile devices.

    Edit: I personally really like PSD files because they're one of the only file formats that let you be explicit in how it handles alpha. You can add it as a fourth color channel that doesn't interact with the RGB colors at all, or just have it as layer transparency for simplicity. TGA is my second choice because usually alpha is handled only as another channel and not as the layer alpha. PNG is a huge pain, this is coming from someone who used it as another engine's only accepted image format for 2 years. There was a lot of special case handling and fighting Photoshop.
     
    Last edited: Nov 24, 2015
    theANMATOR2b likes this.
  9. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Hmm I just ran a test to see if there is any difference but I think the profiler is high on something . I put in 50 meshes and placed 50 dds textures(2mb) same material and then swapped out the dds for the png(6mb) the textures the profiler said were in scene was 1547!!! but the texture mb's were roughly the same 60-62mb sometimes the png was more other times the dds. Also said i had only 37 meshes but 43 materials.So yea not exactly reliable.
     
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The DDS file format is a container that can hold a lot of the texture formats Unity uses internally. Your 2 meg DDS is likely the same DXT1 as Unity is turning your PNG files into, though if it's actually 2 megs and not ~2.6 megs they probably don't have mipmaps which the Unity generated ones will have.

    That said if you're using DDS files and decide to get your project running on a mobile device either Unity will error as the textures are already compressed in an internal format, or you'll be loosing quality as DXT1 is a lossy format.

    If you select your texture in the editor you can see exactly which format and what size it is in the inspector tab at the bottom. If the texture isn't being displayed there you may need to drag up the bar at the bottom of that panel.
     
    Last edited: Nov 24, 2015
    theANMATOR2b likes this.
  11. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Just tried a jpeg on the same test it was 71 mb how on earth the jpeg is more than those other 2 jeez so confused
     
  12. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    I can see what size it is 6 mb for the png 2 for the dds but yea no mipmaps imported with it wish the profiler was even a bit accurate how can it be so wildly off.
     
  13. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Will stick with png i guess to be safe just wish didn't have the extra alpha channel is there some image file i can use that is lossless with no alpha?
     
  14. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    6mb for the PNG file itself on disk, or 6mb for a DXT5 2048x2048 w/ mips in the inspector?
     
  15. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Btw, I recommended TGA specifically because you can save it as 24 bit or 32 bit (with and with out alpha).
     
  16. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    6mb in the inspector 2048 compressed not sure on the mipmaps are they generated automatically when imported i didn't change any settings
     
  17. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Ok i will test out TGA thx
     
  18. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I'd recommend PNG for the same reason. But also because it offers better compression and has the option to use 16 bits per channel. I would definitely not recommend using DDS in Unity.
     
  19. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    @bgolus & @jvo3dc
    Awesome information on preferred file formats - and the 'whys' to which are better and which are not.

    This thread should really be a sticky for Unity beginners and could be a great addition to the Unity documentation.

    @bgolus - have you ever considered writing documentation? ;)
     
  20. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    @jvo3dc What graphics program do you use to handle PNG? Photoshop doesn't have an option to disable transparency optimization or loading alpha as a separate channel with it's default PNG handling, so you have to use SuperPNG. However there's no way to tell Photoshop to use SuperPNG exclusively anymore as Photoshop no longer lets you disable the existing PNG format handler. Gimp has better support for saving PNG, but opening a PNG will, like Photoshop, always open it as a single layer and delete the color information in the alpha. Photoshop's default PNG also won't save alpha if it's a fourth channel, only if it's part of the layer, which makes it difficult to edit directly (though you can do it as a layer mask rather than layer alpha).

    For 16 bit I just use TIFF. PNG's compression is actually another reason I don't use it. If you have large files the time to save the file can be quite long and, again, the source file size is irrelevant to the final product and harddrive space is cheap. Most likely you have a source PSD or Gimp file somewhere already so you're already paying the storage cost.

    @theANMATOR2b I'm a tech artist by trade, so it's frequently part of my day job.
     
    theANMATOR2b likes this.
  21. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    So if i do a texture exactly 2048x2 and import it so no need for downsizing to 2048 will a 4096 texture be better or worse because when imported it will get downsized to 2048. Which is the better approach a exact size for unity's preferred max size or a larger size that unity will downsize?
     
  22. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    2048x2 is a more unique case. Most of the real time compression formats are block compression that work on 4x4 or sometimes larger blocks of pixels. If the resolution on one dimension is smaller than that (or not a multiple of the block size) it can't be compressed without rescaling. A 2048x2 texture will get treated as an uncompressed texture. A 4096x4 texture can be compressed with DXTC though, but it can't have mipmaps. A 4096x4 DXT1 texture will be slightly smaller than a 2048x2 RGB, but insignificantly so, and the 4096x4 will still have compression artifacts the 2048x2 won't.

    As for your actual question, importing a 2048x2 texture or a 4096x4 texture that gets scaled down by Unity should have identical results. Neither is necessarily "preferred" though having the full resolution version of the texture might be useful if there are visual differences in using the two sizes and want to enable the full resolution with certain quality settings.
     
  23. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    2048x2 is my shorthand for 2048x2048:D.
     
  24. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    The above statement stands. Importing a 2048x2048 vs a 4096x4096 that's downscaled to 2048x2048 in Unity should be identical.

    Btw, the proper shorthand is 2048^2.
     
  25. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,356
    Awesome thx
     
  26. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Well, you are absolutely right about that. Specially in photoshop it can be slow to save to PNG. But that's only the write situation. The read situation is (potentially) better. It's very easy/fast to decompress PNG. So it doesn't only save space, but also read time and/or network transmission.

    Deleting the color information is annoying indeed. I usually just start the alpha at 1 instead of 0. On the other side, if you render to TGA from max, the colors will be premultiplied with the alpha, which I also find very annoying.

    I'd say TIF/TGA/PNG are all good. Just a matter of preference and specific needs. Just stay clear of JPG/DDS. They are not the optimal choice.
     
  27. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You can turn that off btw.