Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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.