Search code examples
google-chromeunity-game-enginewebglunity-webglwebassembly

Chrome webgl rendering / flashing issue


I try to get a unity => webgl export working on google chrome browser.

It works fine on firefox but on Chrome the background is not transparent and seems dirty, sometimes it even flickers super fast (very dangerous for people suffering from epilepsy)

This is the code that should do the transparent background:

  var LibraryGLClear = {
      glClear: function(mask)
      {
          if (mask == 0x00004000)
          {
              var v = GLctx.getParameter(GLctx.COLOR_WRITEMASK);
              if (!v[0] && !v[1] && !v[2] && v[3])
                  // We are trying to clear alpha only -- skip.
                  return;
          }
          GLctx.clear(mask);
      }
  };

  mergeInto(LibraryManager.library, LibraryGLClear);

the code was taken from here: https://answers.unity.com/questions/1069255/embed-webgl-in-webpage-with-transparent-background.html

With Transparency Code: https://youtu.be/qpTq73ZL5_c (do not watch if fast changing images can trigger epilepsy for you)

I thought it was caused by the transparency code. Unfortunately, it is not the root cause because I bundled it without the transparent code and got a similar issue:

Without: https://youtu.be/271mZsizvps

Is there maybe a special setting in Unity I could play with? Do you have the same issue?

Please help, thank you!


Solution

  • Ok I solved it here: https://forum.unity.com/threads/webgl-with-transparency-on-the-cavas.327425/

    I think basically what I did wrong, is to not set the background colour on the camera to 0,0,0,0.

    Unfortunately, that is written nowhere, so I added it in that post. Hope it helps someone.