Search Unity

Basis Universal Texture Format in Unity

Discussion in 'General Graphics' started by gw1108, Jul 8, 2019.

  1. gw1108

    gw1108

    Joined:
    Jan 22, 2013
    Posts:
    6
    Fairly recently, Binomial released Basis with open source compressor and transcoder. Is it possible to use the Basis file format in Unity? Does Unity have any plans to support the Basis file format?
     
    smash-ter, briank, R0man and 3 others like this.
  2. jamal-dahbur

    jamal-dahbur

    Joined:
    Jul 24, 2014
    Posts:
    8
  3. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    We are considering whether to support it or not.
     
  4. Magdoca

    Magdoca

    Joined:
    Jun 3, 2019
    Posts:
    7
    While Unity is considering whether or not to support the Basis format, is there any way we can implement it on our own without the engine source code? I have not found any events or functions to override that would allow us to implement it but I am curious if there is anything I have overlooked.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    To implement it yourself you'd have to compress the files into the .basis format yourself external to Unity. You could then presumably implement the transcoder as a native plugin, or manually rewrite it into c#, though I'm not sure their license allows for that. You could either load the .basis files manually like you would for manually loaded .jpg files, send the bytes through the transcoder, and then create a Texture2D of the correct format & dimensions and apply the bytes returned by the transcoder.

    You could also possibly implement them as scriptable objects so you can load the .basis files into an asset package as the raw bytes, to again transcode at runtime.

    The hard part would be having them as assets you could apply as textures in the editor. That I have no idea how you would do it.
     
  6. Magdoca

    Magdoca

    Joined:
    Jun 3, 2019
    Posts:
    7
    Good suggestions bgolus. I was thinking something along the same lines and abandoned it when I was trying to consider how to link the textures to the assets in a way that is artist friendly and integrates well with other Unity features like asset bundles. I was hoping to find some events I could tap into or functions that would allow me to implement my own functions for encoding and decoding texture assets. Assuming I could do that, it would likely work with any other Unity feature since the engine would still recognize it as a texture asset.
     
  7. theteadrinker

    theteadrinker

    Joined:
    Jan 6, 2015
    Posts:
    5
    Looks like a very interesting option for any app that loads textures from the web, however, you probably would want to pack a number of textures into a larger file to reduce number of HTTP requests.

    However it would be great if Unity would support basis in an API like: Texture2D.LoadImage(byte[] data, bool markNonReadable = false);
     
  8. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    I'd really love to see the adoption of some kind of technology that minimises one or more of project size, install size, and memory usage.

    I'd imagine that since Unity is still the go-to engine for Mobile and Nintendo Switch development, the adoption of something like Basis would greatly benefit the userbase.

    https://www.khronos.org/blog/google...to-khronos-gltf-3d-transmission-open-standard

    Even moreso since Unity controls a large asset store and could support and encourage asset creators to use more optimised texture technologies.
     
  9. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    Why?
    Quality-wise Basis is somewhere around that of ETC compression, so there's no real benefit from using it for mobile users.
     
  10. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Isn't the main selling point that basis supports to expand its data to various texture formats, which allows to have the same basis file that could expand to ASTC on phones with ASTC support and to ETC on phones that don't support ASTC for example. All this with the same basis file of course.
     
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    An ETC1 texture is 4 bits per pixel. With compression maybe 3.5 bits stored? A Basis Universal can be 0.5~2 bits per pixel. The advantage is download size.

    Granted PVRTC can be 2 bits per pixel, so there’s less advantage there.
     
  12. BattleAngelAlita

    BattleAngelAlita

    Joined:
    Nov 20, 2016
    Posts:
    400
    >expand to ASTC on phones
    Astrologers announced a week of importing on scene load, loading time increase by +5000%.
     
  13. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Are you making fun of ASTC’s compression times? Because one of the other advantages of Basis is the compression/encoding times are much faster than ASTC, and the transcoding from Basis to ASTC is real-time. Part of idea behind Basis, like Crunch before it, is the time to load the image from “disc” and transcode it is less than loading the final format normally.

    Quality wise, the resulting ASTC won’t be as high quality as a texture directly encoded into that format, but hopefully will be better than ETC1. That is however the big question mark @aleksandrk was getting at.
     
  14. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    Technically, yes. But if the quality is lower, there's no point in using ASTC in the first place, you can just use ETC2 :)
    I could see potential in using it for something to unify the format for ETC2/ETC, but not ASTC.

    This is a good point :)

    I'll bring all of this into the internal discussion. Especially since they seem to have been working on a high-quality setup for lossless transcoding to ASTC.
     
  15. Lahcene

    Lahcene

    Joined:
    Jun 18, 2013
    Posts:
    55
    Other benefits are less memory usage and faster loadi times.
     
  16. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Basis currently only supports ASTC with a block size of 4x4 (8 bpp). Unity uses 6x6 (3.56 bpp) by default. This means the runtime memory size using basis would increase.
     
    Lahcene likes this.
  17. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Yeah, the “less memory usage” thing is misleading. Basis means smaller on “disk” build sizes and potentially faster initial loading times. Memory usage is the same or slightly higher.
     
  18. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    If you look at the typical Indie project, a significant number of gigabytes - the majority of the project - is taken up by texture files. Same for Store Assets. Reducing on-disk storage size would be highly beneficial.
     
    Lahcene likes this.
  19. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Are you suggesting to use basis as an alternative to e.g. PNG?
     
    Lahcene likes this.
  20. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Yeah, are we taking project folder or final built game size?

    If you really do mean project folder you're talking about source assets, and you really want to use uncompressed assets for the project, be that PNG, TGA, or PSD is irrelevant to the final built game assets. Personally I prefer TGA or PSD over PNG because it takes so long to save PNG files that now you're waiting for the PNG compress, decompress, and GPU format compress each time you update a texture instead of just the GPU compressing. PNG is bad for iteration. Basis files shouldn't be used as source assets because they're heavily compressed already, similar to a medium quality JPG (another format you don't want to use as a source format if you can help it).

    If you're talking about a built game, sure. It's basically crunch 2.0.

    Also I've never worked on a game where the textures were the largest part of either the project or build. Usually it's audio.
     
  21. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    90
    What about compressing texture arrays? Wouldn't basis be vastly superior to Unity's compression in this regard?
     
  22. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Basis supports texture arrays, and texture arrays are now (finally) a first class citizen with Unity 2020.2, so it's plausible it could be supported if they chose to add Basis support. And yes, a Basis compressed texture array would be much smaller on disk than one only compressed with the default package compression.

    But that's not really a surprise since Basis textures are vastly superior to Unity's default package compression of any texture asset, at least in terms of on disk package size. That's its whole purpose, do a better job at compressing already compressed textures than a general purpose compression algorithm would alone. Even if it didn't natively support arrays it'd still be better. Just like using Crunch to store the textures and building the array at runtime would be right now.
     
    R0man likes this.
  23. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    338
    Better texture storage (compression) for the project would save me about $100 a year in Plastic SCM hosting fees. Its definitely worth it.
     
  24. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    This isn't applied to the project's source assets, so it won't affect how large your source depot is. Unless you are storing compiled builds or asset packages in your depot as well. Generally compressed texture assets are stored locally in a temp folder, or in a cache server (which can also be local), separate from the asset folder. So unless you're creating texture assets manually in script (which you might be if you're using texture arrays pre 2020.2), or storing the local cache in your depot (which you probably shouldn't be) then this wouldn't change anything for you.

    If you're concerned with texture asset size, make sure all of your source texture assets are saved as .PNG files, or .JPG if you're okay with loosing some image quality. That'll actually be about on par with Basis in terms of disk space savings.
     
  25. slime73

    slime73

    Joined:
    May 14, 2017
    Posts:
    107
    Unity already supports Crunch texture compression, and some popular shipped Unity games have used it successfully to reduce download times / disk space usage and improve loading times compared to regular DXT texture compression + LZ file compression.

    Since Crunch is already useful, it follows that Basis is even more useful (since it supports a wider range of native formats and platforms).
     
    Last edited: Jul 15, 2020
  26. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    90
    Adding to that, Basis would help device dependent compression with WebGL. As it currently stands, Unity has no solution for device specific GPU compression formats in WebGL.
     
    DerrickBarra likes this.
  27. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    Right now @atteneder has been writing a plugin to support .ktx, .ktx2 and .basis files. Check out KtxUnity, our team is already using it along with various GLTF loading plugins like GLTFUtility and Piglet for our WebGL support.

    @florianpenzkofer @aleksandrk : Any update on where Unity stands on making support for .basis officially supported? It definitely makes sense for platforms like WebGL that desperately need the reduce transmission file size and VRAM benefits of .basis.
     
    tteneder likes this.
  28. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    We have been looking at Basis on and off in the web team. As of yet we do not yet have an active development task going into integrating it, but the task is on the board. Though thanks for posting the question, I'll poke a few people in the team to see what they think about the timing. This may be something for us to revisit soon.
     
    gtk2k and DerrickBarra like this.
  29. PlyTim

    PlyTim

    Joined:
    Mar 23, 2018
    Posts:
    4
    Any updates on this ? For unity on webgl, this would be a massive boost in loading times and performance. I really think this should be a top prio for the webgl team
     
    kuribara_unity likes this.
  30. mabulous

    mabulous

    Joined:
    Jan 4, 2013
    Posts:
    198
    Bump, any update on this? Basis seems to be also interesting for compressed video textures
     
  31. HRDev

    HRDev

    Joined:
    Jun 4, 2018
    Posts:
    58
    Any news about Basis Universal support on Unity?

    In this thread the comments highlighted the size and performance benefits. Unity team members questioned the advantage of Basis over using ETC2 as the quality of Basis was lower than ETC2. But now Basis supports two modes: a high quality mode which is internally based off the UASTC compressed texture format, and the original lower quality mode which is based off a subset of ETC1 called "ETC1S". UASTC is for extremely high quality (similar to BC7 quality) textures, and ETC1S is for very small files. In practice, using Basis we will all be happy and we will have all the advantages.
    Another very important advantage that we will have if Unity implements Basis is that it is a solution to provide compressed textures suitable for use on either desktop or mobile devices without building separate texture assets for each platform. This will allow Unity to become more popular as a tool for creating 3D content for the Web.

    Please prioritize Basis Universal support on Unity!
     
  32. LordMortis

    LordMortis

    Joined:
    Jan 25, 2014
    Posts:
    27
    I'm still super confused why this isn't integrated. As far as I can tell: Integrating basis allows us to have _one_ set of intermediate textures, that allows, at runtime, very fast transcoding into the native format for the on-device GPU. On android, even today - our customers have a lot of devices that still don't support ASTC, so we're stuck on ETC2.
     
    blueivy likes this.
  33. Bwacky

    Bwacky

    Joined:
    Nov 2, 2016
    Posts:
    205
    Any updates on Basis support or nothing yet? Been a while since it landed on the task board :)