Search Unity

Official Changes in WebGL1's NPOT texture handling

Discussion in 'Web' started by jonaskhalil, Apr 14, 2021.

  1. jonaskhalil

    jonaskhalil

    Unity Technologies

    Joined:
    Apr 6, 2019
    Posts:
    33
    Hi, we're looking into doing some major internal code cleanup, of which only the OpenGLES 2.0-based WebGL1 may notice some changing behavior. With the limited scope of these changes, we believe that this cleanup should be fine. Still, we wanted to hear with you guys before following through on this.

    We have a lot of complexity for handling NPOT (non-power-of-two size) Textures, rescaling or padding them (after potentially having to decompress them) if the graphics device does not actually support NPOT Textures. As this nowadays only applies to WebGL1, we decided to try and remove this code complexity such that we no longer let all devices pay the price for WebGL1 missing this capability. This means no more upscaling your Textures behind your back before uploading. This means no more surprises due to your width and height on GPU not matching your actual Texture's width and height. And this means no more uploading two Textures (a variant that's scaled to a POT and a variant that's padded to a POT) for a single asset, even though it's extremely rare to need both of them simultaneously.

    If you currently compare WebGL1 with WebGL2, you already see some arbitrary behavior: NPOT Textures without mips suddenly don't do texture mirroring or repeating, NPOT Textures with mipmap generation do have mirroring and repeating enabled but have been rescaled, while NPOT Sprites still remain (by design) pixel-perfect. We would keep it simple by just applying this one rule: "if a NPOT Texture is used on a device that does not support this, then mipmapping will be disabled (and consequently texture wrapping is limited to 'clamp')". Will you see changes? If you kept the default import settings, probably not: Textures are, by default, scaled to the nearest power of two upon import, and Sprites are, by default, imported with mip generation disabled. If you explicitly disabled texture rescaling on import, well it didn't even make a difference as we rescaled it anyway on WebGL1 (except for Sprite-related code), so just rescale on import again (no added cost, now you're just setting it to rescale explicitly). Have a look here (link) for an overview of how behavior changes. In short: Textures behave more consistently and predictably, with no more surprises such as "Textures no longer wrapping around when disabling mipmapping". The main drawback is that imported Sprites can no longer have mipmaps on WebGL1 if they are NPOT; workarounds in case of changed behavior will be described (workarounds that may also depend on what functionality could still be exposed or added before we release these changes).

    We feel that the many benefits for all other devices that do support NPOT Textures (including WebGL2), as well as the benefits for WebGL1 itself (regarding consistency and avoiding unanticipated internal uploading behavior) largely outweigh the niche cases in which you'll have to do some workarounds specifically for WebGL1. Still, we want to make sure we're not underestimating the need for particular use-cases. Are NPOT Textures more common than we anticipated? Are there many cases where you really need a properly mipmapped (NPOT) Sprite? Does it often occur that you want a NPOT Texture without having it rescaled? Or are we rather overestimating all of this? Are NPOT Textures already something rare in WebGL1 projects due to the graphics devices not supporting them, and do devs already pay attention to have properly dimensioned Textures in their projects? Or is it generally acceptable to potentially have texture aliasing/resampling artifacts on these platforms? ... Let us know if you think there are concerns with this cleanup we're considering! Any concerns or worries? Reliefs? ...
     
  2. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    I know I am not directly answering the question but can we look at just -finally- depreciating WebGL 1 completely now that Webkit will support WebGL (2.0) by default?

    Just cut it off for 2021.x and be done with it? Feeling like it's dragging precious, and very limited, dev time away from you all.

    Just my 2cents.
     
    JoNax97 likes this.
  3. DerrickBarra

    DerrickBarra

    Joined:
    Nov 19, 2013
    Posts:
    210
    As soon as WebGL 2.0 is fully supported by iOS (which is basically keeping WebGL1 on life support), I agree that dropping WebGL 1.0 support would be best.

    Personally, our team forces all textures to the power of two anyways. But having the option to use npot textures is a nice to have in my opinion.
     
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Its not going to be suported by all devices, its not even out yet its a safari TP, and we dont know if it will be on safari for ios yet and when. Even when it is, cutting off WebGL 1 completely would remove support for MANY devices (its only certain newer OS that can update to it), thats not a good solution for all.
     
    De-Panther and DerrickBarra like this.
  5. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    Apparently there are still some desktop computers that can't use WebGL2 (some onboard only graphic cards desktops), so support for WebGL1 is needed.

    I think a change like that is OK, as long as it is very well documented, both on the documentation/manual, and in the editor.
    In the editor, in case where WebGL1 or both are selected it should be mentioned in:
    - Player settings, if there are NPOT textures in the project, add warning below the Graphics API options.
    - Image Asset Inspector, if texture is NPOT.
    - Material Inspector, under selected NPOT textures.
    - (*not sure if needed) Renderer components Inspector, if NPOT texture is rendered.
     
  6. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    To be clear, what I am proposing is to drop future support of WebGL 1.0 now. Ergo, in the 2021.x branch or even 2020.x branch.

    Those will still get WebGL 1.0 as long as LTS is supported (so quite a while). Otherwise, any new features, any new improvements or compatibility with future SRP features (URP mainly) should be for WebGL 2.0 only.

    Otherwise, we're looking at WebGL 1.0 being supported still for 2022, even 2023. As for Webkit getting 2.0, it's almost a fait-accomplie, just a question of waiting for the stable release.

    And for iOS, I would much rather they focus their mobile implementation for 2.0 as they'll need to sqweeze as much performance / size optimisations as possible. Let's be honest, WebGL 1.0 on mobile is a pretty darn terrible idea anyhow. WebGL 2.0 is already pushing it. Better not have it at all on iOS than have a bad implementation with terrible performance. IMHO.
     
  7. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    But WebGL1 support is not only an issue of iOS or Safari...
     
    MadeFromPolygons likes this.
  8. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    No, indeed. But I am having trouble finding a reliable source of significant WebGL 1.0 usage... The latest and biggest hurdle that we know of was browser adoption. Next version of Webkit will close that argument (more than happy to backtrack if ever it doesn't support WebGL 2.0).

    Next up is mobile but, like I said, Unity doesn't officially support Mobile WebGL. So that work is on-going and I argue it shouldn't support 1.0 at all anyhow.

    Finally, there's hardware support issues. In that case, I can't find any significant requirements or significant usage of WebGL 1.0 and believe that keeping it supported in a -feature frozen- state under a LTS release cycle should be more than enough to cover whatever cases there are.
     
  9. jukka_j

    jukka_j

    Unity Technologies

    Joined:
    May 4, 2018
    Posts:
    953
    Hopefully Safari adds support for WebGL 2 soon so that we can get a better visibility for what dropping WebGL 1 would be like.

    Regarding the conversation about WebGL 2 not being supported on non-Safari devices (mobile and desktop): this is something that we have discussed in the past with Google. Both Unity and Google naturally have their own web analytics dashboards, and curiously we see two different demographics with two different % capability numbers for WebGL 2 support. In the end it has been a bit vague which one to trust more. Chrome is known to be weak with WebGL 2 on mobile Adreno 300 level of devices, but apart from that, WebGL 2 is expected to have good support.

    It would be great if you have Unity based WebGL sites that you host with active users, to track what the actual WebGL 2 support % rates are on your sites, cross-referenced by user agent. In the non-Safari crowd with modern PCs and mobiles, we expect that should be well above 90%, with the occassional known insecure GL drivers in the mix dropping the % by a few points.
     
  10. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    @jukka_j, don't know if you can reach out to @TheRoccoB but as the founder of simmer.io he probably has a bunch of stats he could share.
     
    DrViJ and MadeFromPolygons like this.