How to detect and work around depth texture bug

Hi there, is there any way to read pixels from the depth texture?

We’re having problem with some Macs not showing shader effects correctly that use the depth texture as input. According to this link it’s a known issue:
https://github.com/playcanvas/engine/issues/4266

So we have a fallback solution ready, but how do we detect if the problem is present? Everything appears correct from code, but the depth buffer is just white. So we’re planning on simply doing a pixel read from the depth texture to check if it’s all white.

Thanks.

Can you just use navigator.platform to detect if the computer is running MacOS?

There is some issue with this, details here:

The only workaround available at the moment is to force Webgl1 on those devices, which works correctly.

1 Like

Ok, so we force webgl1 on MacOS (unless running Safari) until a fix is ready. And how do we force webgl1 from code at runtime?

Frustratingly it’s only on some Macs with certain hardware combinations. To force WebGL1, you would have to modify the __start__.js file as it has to be done before the GL context is created

With this section:

    try {
        app = new pc.Application(canvas, {
            elementInput: devices.elementInput,
            keyboard: devices.keyboard,
            mouse: devices.mouse,
            gamepads: devices.gamepads,
            touch: devices.touch,
            graphicsDeviceOptions: window.CONTEXT_OPTIONS,
            assetPrefix: window.ASSET_PREFIX || "",
            scriptPrefix: window.SCRIPT_PREFIX || "",
            scriptsOrder: window.SCRIPTS || []
        });

The option to use WebGL 1/2 is in the window.CONTEXT_OPTIONS json object.

So it will be something like

    try {
        if (somethingToDetectMacOSX) {
            window.CONTEXT_OPTIONS.preferWebGl2 = false;
        }

        app = new pc.Application(canvas, {
            elementInput: devices.elementInput,
            keyboard: devices.keyboard,
            mouse: devices.mouse,
            gamepads: devices.gamepads,
            touch: devices.touch,
            graphicsDeviceOptions: window.CONTEXT_OPTIONS,
            assetPrefix: window.ASSET_PREFIX || "",
            scriptPrefix: window.SCRIPT_PREFIX || "",
            scriptsOrder: window.SCRIPTS || []
        });

As far as we know, the fix for this is coming down the pipe for Chrome as it works fine in Canary at the moment

1 Like

I think this also works for editor based projects, disable Prefer WebGL 2.0:

That would do it for all platforms, I believe they only want to have WebGL1 on Macs only

Ah got it, thought it was for testing only, makes sense.

Thanks a lot, I changed the header to match where the thread ended up :slight_smile:

1 Like