Search Unity

Depth RenderTexture not working on WebGL with Unity <= 2019.4

Discussion in 'Web' started by stephero, Nov 30, 2020.

  1. stephero

    stephero

    Joined:
    Feb 8, 2016
    Posts:
    123
    Hi guys,

    I have a very simple scene (no coding involved) using the builtin render pipeline with a Camera outputting to a depth RenderTexture (left), and this same RenderTexture displayed over a simple cube using an Unlit material (right).
    Screenshot_25.png

    It works fine in the editor and on standalone PC:
    depth_editor.png

    But the issue is when exporting to WebGL:
    When using Unity 2019 or lower (I tried with the latest Unity 2019.4.15f1), the depth is all black:
    depth_webgl_2019.png

    If I open the exact same project with Unity 2020 or higher (I tried with Unity 2020.1.0f1) and export it to WebGL, it works fine:
    depth_webgl_2020.png

    You can find the attached project in the thread.

    I couldn't find any mention of this kind of issue. Am I doing something wrong, or do you know if there is any workaround?
    Thanks
     

    Attached Files:

    Last edited: Dec 1, 2020
  2. stephero

    stephero

    Joined:
    Feb 8, 2016
    Posts:
    123
    Note that I also tried to force the depth texture mode of the camera capturing the RT, without success
    Code (CSharp):
    1. var cam = GetComponent<Camera>();
    2. cam.depthTextureMode = DepthTextureMode.Depth;