Non-opaque windows blend incorrectly with other windows when using MTKView

Originator:gnachman
Number:rdar://42225473 Date Originated:7/15/2018
Status:Closed Resolved:
Product:macOS Product Version:10.14 beta 3
Classification: Reproducible:Always
 
Area:
AppKit

Summary: An MTKView with a non-opaque layer in a non-opaque window should blend its contents with the windows behind it according to the alpha value produced by the fragment shader, but it appears much more opaque than it should be.

The attached screenshot shows the modified HelloTriangle over a PixelMator window with a half black, half white image, demonstrating that black pixels are transformed to red while white is almost unchanged.

Steps to Reproduce:

Modify the HelloTriangle demo to:
1. Set the MTKView's layer's opaque property to NO
2. Set the window's opaque property to NO
3. Set the window's hasShadow property to NO
4. Set the window's backgroundColor to NSColor.clearColor
5. Modify the fragment shader to return float4(1, 0, 0, 0.1)
6. Run it and place it over a window that is part white, part black.

See the attached code.

Expected Results:
The area inside the triangle should be 99% transparent, adding a barely noticeable red color to its contents. Pixels behind it that are white should be just barely pink, while pixels behind it that are black should be a very dark black.

Actual Results:
Black pixels behind the triangle become bright red. White pixels are still nearly white (going from 255,255,255 to 255,254,255 according to digital color meter).

Version/Build:
macOS 10.14 Beta (18A326h)
Xcode Version 10.0 beta 3 (10L201y)

Configuration:

---

Apple Developer Relations
July 17 2018, 9:37 AM
We have determined that this is an issue for you to resolve.

The CoreAnimation compositor requires all of its inputs be premultipled by alpha. See these references for more information:
https://en.wikipedia.org/wiki/Alpha_compositing
https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/

When RGB are premultipled by alpha, then any RGB component that is > the alpha component is undefined through the hardware’s blending.

Modifying your fragment shader to return (0.1, 0, 0, 0.1), which is “0.1 alpha, full red” produces the expected results.

Please let us know whether the issue is resolved for you by updating your bug report.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!