Search code examples
macosalphametal

How to render a semi transparant MTKView on macOS?


I've got a Metal shader with an output of alpha 0.5 running fine on iOS, showing the underlying views. Tho on macOS is's not working. There's a black background, even tho the background of the MTKView's layer is set to clear..

I've noted that the MTKView's .isOpaque property is not settable on macOS, tho not sure if that is the problem as it's already set to false.

Is there another way to achieve transparacy?


Solution

  • You need to set the isOpaque property of the CAMetalLayer to false. There's a comment in the CAMetalLayer.h header file (Objective-C) that says:

    /* Note: The default value of the `opaque' property for CAMetalLayer
     * instances is true. */