Search Unity

Bug Issues reading from depth texture in WebGL - not enabled?

Discussion in 'General Graphics' started by Brian-Kehrer, Jan 14, 2022.

  1. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    First the setup - working in editor, desktop builds - but not webgl builds. Unity 2021.2.6f1
    Code (CSharp):
    1. deferredBuffer = new RenderTexture(bufferWidth, bufferHeight, 0, RenderTextureFormat.Default);
    2. deferredBufferDepth = new RenderTexture(bufferWidth, bufferHeight, 24, RenderTextureFormat.Depth);
    3. deferredPass.mainTexture = deferredBuffer;
    4. deferredPass.SetTexture("_Depth",deferredBufferDepth);
    5. camera.SetTargetBuffers(deferredBuffer.colorBuffer, deferredBufferDepth.depthBuffer);
    And I'm sampling it in a full screen quad (RawImage attached to a UICanvas).
    return tex2D(_Depth, i.uv).r;

    In builds I see only a pure white screen. Is there some config to enable depth textures in WebGL?
     
    Last edited: Jan 14, 2022
  2. Brian-Kehrer

    Brian-Kehrer

    Joined:
    Nov 7, 2006
    Posts:
    411
    User-error. 2D Camera wasn't being cleared, causing render issues in the build.