Search Unity

Bug Webgl Video Player Performance Issue With Linear Rendering

Discussion in 'Web' started by unity_1D4395716672639296FF, Mar 23, 2023.

  1. unity_1D4395716672639296FF

    unity_1D4395716672639296FF

    Joined:
    Sep 24, 2021
    Posts:
    2
    I've been having this performance issue for quite a while and with many different unity versions
    (2022.1.12 to 2022.1.24 and 2022.2.0 to 2022.2.11).

    In the built in pipeline, when building for webgl using the linear color space, having even a single Video Player playing in the scene, drops the frame rate to 30 or less. The gamma color space does not have the same issue. Also the mp4 format seems to have a higher impact than webm.

    A unity version that seems to work fine is 2021.3.8 but I cannot fall back to that version.

    To reproduce, change the color space to linear in the player settings and simply create a plane with a video player component on it and provide it with a video url.

    I have submitted a ticket already but if anyone knows a work around or a fix it would be much appreciated.
     
  2. easypeet

    easypeet

    Joined:
    Sep 25, 2017
    Posts:
    3
    Struggling with the same issue. Using Unity version 2021.3.21.
     
  3. JMoschos

    JMoschos

    Joined:
    Mar 31, 2021
    Posts:
    1
    I found a workaround but it is not the best. The issue seems to be related to SRGB texture creation in the build's js function JS_Video_UpdateToTexture (browser side). If you go to the unity editor's installation folder C:\Program Files\Unity\Hub\Editor\<editor version>\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\lib\Video.js you can locate that function and replace the following lines:
    Code (JavaScript):
    1. var internalFormat = adjustToLinearspace ? (hasSRGBATextures ? GLctx.SRGB8_ALPHA8 : GLctx.SRGB8) : GLctx.RGBA;
    2. var format = adjustToLinearspace ? (hasSRGBATextures ? GLctx.RGBA : GLctx.RGB) : GLctx.RGBA;
    with:
    Code (JavaScript):
    1. var internalFormat = GLctx.RGBA;
    2. var format = GLctx.RGBA;
    Then the video player will render to a non-SRGB texture which will result in your video's colors showing a bit washed out. To fix this issue have your target material for the video use a shader that does GammaToLinearSpace color conversion for the video's target texture property.

    Note: if you do not want to replace those lines in the editor's installation files then you need to find them inside your build's files and replace them there.