Search Unity

Supporting other compressed texture formats (ETC2/PVR) for WebGL

Discussion in 'Web' started by kognito1, Oct 30, 2017.

  1. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Hello,

    I know mobile is not officially supported, but since iOS (Safari) 11 and the latest Chrome for Android support webassembly we've ran a few tests and it may be feasible for us to allow some (few) mobile devices to use WebGL. A big blocker though to fully validate this is the DXT format that Unity uses for WebGL (obviously not supported on most mobile gpus resulting in decompression to uncompressed textures). We use asset bundles so it wouldn't be too hard for us to build different texture bundles for various devices, but at the moment these formats are not exposed to us under WebGL.

    Thus we were wondering if PVR (iOS) and ETC2 (Android) formats could be added as possible compressed texture formats for WebGL. Again while mobile isn't officially supported, I think you'll have more interest on those platforms sooner rather than later and the ability to use different texture formats will be essential.
     
    metaverso, Kiori and ilmario like this.
  2. shader13

    shader13

    Joined:
    Aug 31, 2012
    Posts:
    15
    Support it strongly!
     
  3. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Do you have a project that works on mobile browsers?
     
  4. shader13

    shader13

    Joined:
    Aug 31, 2012
    Posts:
    15
    Yes, we are working on it now.
    We are trying to help Unity WebGL migrate to mobile browsers and Facebook IG.
     

    Attached Files:

  5. shader13

    shader13

    Joined:
    Aug 31, 2012
    Posts:
    15
  6. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Despite the UI in Japanese I was able to play on my Galaxy Note 4 on Chrome!
    I have to say it's one of the best games I have seen so far based on Unity WebGL. I think you worked very well around the limitations of this platform, though load-time is an issue. Beautiful art style too.
     
  7. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    Last edited: Jun 11, 2018
  8. shader13

    shader13

    Joined:
    Aug 31, 2012
    Posts:
    15
    We use our technologies to optimize Unity WebGL original version (emscripten version), actually, almost all of current Unity WebGL cannot work on mobile, because there are two major issues:
    1. code size is huge (engine + game logic);
    2. resources are huge (it is caused by emscripten memory file system I think);
    Because memory usage exceeds the limitation on mobile, especially on iOS, Unity WebGL will crash, we rebuilt Unity WebGL original output by our compiler, redesigned the file system with our blocking technology based on cloud service, solved many issues in Unity output for mobile such as rendering, touch, even we modified il2cpp code to add bsd socket and multithreading support for online game, we call our system WEB-IR, I think it can help Unity WebGL move to real mobile very well. :)
    Add more:
    Texture compression format is another big issue, because it looks Unity WebGL only supports the formats for desktop browsers currently, but on mobile browser such as android chrome and iOS webkit, Unity WebGL has to decompress these textures by software, obviously, it is eating the time and memory space, it causes poorer performance and higher crash risk, whether more mobile WebGL texture formats can be supported such as pvrtc on iOS and astc/etc1 on Android?
    And This game is Samurai2, the copyright belongs to the author MadFinger or their publisher, we just use it as a Demo to experiment.;)
     
    Last edited: Jun 11, 2018
    samfoot, chriszul and ChristianKoGaMa like this.
  9. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    So I'm bumping this thread again. I don't mean to beat a dead horse here, I'm quite confident Unity is working hard on mobile! However I just wanted to say I think the time to support ETC2 in addition to DXT should be sooner rather than later.

    We're quite happy with how wasm performs on the last few versions of Android (i.e. Chrome on Android) even when decompressing our DXT textures. We seriously think we can start supporting Android in the (very) near future. As you can imagine a huge deal! Obviously I'd really like to avoid using uncompressed (decompressed dxt) textures and I also rather not develop a whole pipeline for "side-loading" (through UnityWebRequest) etc2 textures. I really think Android today is already a viable platform for Unity webgl. Maybe if iOS supported wasm it could too...
     
  10. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    No promises yet but this is on our radar...
     
    kognito1 likes this.
  11. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    So I did a little more investigation into the subject and there are just a few things that I'll note (I'm sure you know most anyways):
    • We still need PVR. :( I was hoping that we (as a community) could just get away with DXT (desktop) and ETC2 (mobile). But while the hardware obviously supports it, iOS only exposes PVR as a compressed texture format to WebGL (not even ETC1 either!). I confirmed this with my iPhone X on iOS 11.4.

    • I firmly believe we should be using ETC2 and not ETC1 for Android. I understand there might be a desire to pick ETC1 to ensure the broadest level of support. But I'd counter with on WebGL they actually both have similar market share [ETC2: https://webglstats.com/webgl2/extension/WEBGL_compressed_texture_etc ETC1: https://webglstats.com/webgl2/extension/WEBGL_compressed_texture_etc1]. And let's face it, ultra-low devices that only support ETC1 (Mali-4xx) are not running Unity WebGL anytime soon. ETC1's lack of alpha support makes it significantly harder to work with in a content pipeline (extra shaders, extra textures, etc.). In this circumstance I think the negatives far outweigh the positives for ETC1 when compared to ETC2.

    • While obviously I think the endgame should be to support DXT, PVR, and ETC2. I think adding ETC2 support should be given priority over PVR (if that's even applicable). As noted above we really like where Android is at the moment and are extremely confident we can make our currently existing product work with only minor caveats. iOS without wasm still needs some work (at the very least our current products won't work without some modification) thus I think the business opportunity there is lower (maybe you could just limit it to the latest iPads?). But in general, I'd highly recommend people to give Android wasm a look. Definitely a viable platform with just a little help from Unity imo. :D
     
  12. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    So some good news for those who are a bit adventurous!!! It turns out Unity WebGL does support PVR/ETC2 "under the hood". I compressed a texture to PVR (outside of Unity) and "sideloaded" using Texture2D.LoadRawTextureData.

    On my desktop computer:
    pvr_webgl_desktop.png
    On my iPhone X:
    pvr_webgl.png

    :D:D:D

    Some interesting opportunities have just opened up! Of course would be nice not having to sideload textures... :p;)
     
    Marco-Trivellato likes this.
  13. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
  14. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
    in the generated framework file, there is a automaticallyEnabledExtensions array. You could try to add the ETC extension in there. Let me know how that goes. ;)
     
    samfoot likes this.
  15. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    No dice, I changed the code to:

    Code (JavaScript):
    1. var automaticallyEnabledExtensions = ["WEBGL_compressed_texture_etc1", "WEBGL_compressed_texture_etc", "OES_texture_float", "OES_texture_half_float", "OES_standard_derivatives", "OES_vertex_array_object", "WEBGL_compressed_texture_s3tc", "WEBGL_depth_texture", "OES_element_index_uint", "EXT_texture_filter_anisotropic", "ANGLE_instanced_arrays", "OES_texture_float_linear", "OES_texture_half_float_linear", "WEBGL_compressed_texture_atc", "WEBKIT_WEBGL_compressed_texture_pvrtc", "WEBGL_compressed_texture_pvrtc", "EXT_color_buffer_half_float", "WEBGL_color_buffer_float", "EXT_frag_depth", "EXT_sRGB", "WEBGL_draw_buffers", "WEBGL_shared_resources", "EXT_shader_texture_lod", "EXT_color_buffer_float"];
    2. var exts = GLctx.getSupportedExtensions();
    3. if (exts && exts.length > 0)
    4. {
    5.     GLctx.getSupportedExtensions().forEach((function(ext)
    6.     {
    7.         if (automaticallyEnabledExtensions.indexOf(ext) != -1)
    8.         {
    9.             console.log("extension IS enabled " + ext);
    10.             GLctx.getExtension(ext)
    11.         }
    12.         else
    13.         {
    14.             console.log("extension NOT enabled " + ext);
    15.         }
    16.     }))
    17. }
    And it did print out:

    But still shows unsupported:

    Damn! I really thought that would do it too. I made a development build and tried to look through the code to determine how Unity checks supported texture formats (I suspect the underlining problem with ETC2 is something silly!), but I'm getting lost chasing function pointers around in the heap. :p:( I'll let you know if I make any other progress. I'll try ETC1 next (yuck no alpha) and see if I can get that working (and maybe ASTC if I'm desperate).
     
  16. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Well ETC1 and ASTC also both don't work. :( So I've only been able to get PVR working on iOS and Android. I'm wondering if I'm actually enabling those extensions "under the hood". I'll investigate a little more, but I think I'm hitting some roadblocks...
     
  17. tcvpromo

    tcvpromo

    Joined:
    Jun 7, 2017
    Posts:
    25
    Any news?)
     
  18. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    We went backwards, can't even load PVR on ios using my "trick" on newer versions of Unity. Still hoping one day...
     
    samfoot and De-Panther like this.
  19. samfoot

    samfoot

    Joined:
    Jun 14, 2017
    Posts:
    1
    Slight bump.

    Is there any progress on this being supported officially? We have a WebGL scene that we would like to work on both Desktop Web/iOS Web and Android web and we are struggling with Texture decompression on iOS. kognito1 mentioned that the workaround doesn't work on newer Unity versions, could you let me know what version it does work on?
     
    larsmoastuen likes this.
  20. shawww

    shawww

    Joined:
    Sep 30, 2014
    Posts:
    43
    Another +1 for this.
    We have a game that runs great on desktop WebVR / WebGl and crashes on Oculus Quest because of the forced DXT decompress / out of memory crash. If WebGL could support ETC2 or ASTC, we'd probably have the highest market share multiplayer VR game out there. But the DXT thing means no-go for mobile.

    And Unity -- WebGL works for mobile! Very few mobile phones I've tried don't support the builds coming out of your pipeline. But these annoying little things really kill it. Literally just fix texture compression options and we'll have a AA competitive VR game built on your platform in WebVR ;)
     
    kognito1 and De-Panther like this.
  21. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Yeah still the biggest challenge on mobile for us. :(

    The last version of Unity where Texture2D.LoadRawTextureData worked with PVR textures was 2018.2 btw.
     
    PushoN likes this.
  22. PushoN

    PushoN

    Joined:
    Jul 5, 2012
    Posts:
    16
    If you can see Safari console on iOS, you will see that PVR supported. I see that on Unity 2018.3.12f
     
  23. kognito1

    kognito1

    Joined:
    Apr 7, 2015
    Posts:
    331
    Yeah that's just printing out all the WebGL extensions the browser supports. The issue isn't the browser (Safari), but Unity not enabling (or using correctly) the extension anymore.
     
    PushoN likes this.
  24. aazzxin

    aazzxin

    Joined:
    Sep 23, 2019
    Posts:
    1
    OMG.

    Instead, we can achieve the display of ETC textures, but not PVRTC. We expanded the export of ETC / PVRTC textures and loaded the corresponding resource packs according to different platforms when loading. Well, the test result was that the ETC1 texture can be displayed normally on Android phones, but it is black with PVRTC on IOS.
     
    OceanX000 likes this.
  25. OceanX000

    OceanX000

    Joined:
    Feb 24, 2021
    Posts:
    120
    We also encountered the same problem, could you describe detail how to export and load ETC/PVRTC? Many thanks in advance.
     
  26. tanchao1778050

    tanchao1778050

    Joined:
    Sep 7, 2021
    Posts:
    1
    when use unity 2020.3.25f1, and use crunch etc2 format,but at mobile phone its display
    blurred screen,i only use sprite to test, i can support project. moblie phone support etc2 format, but why happen blurred screen,help。
     

    Attached Files: