'Rendering an SCNScene with transparent background makes the scene semi-transparent

My goal is to render an SCNScene off screen with a transparent background, as a PNG. Full reproducing project here.

It works, but when I enable jittering, the resulting render is semitransparent. In this example I pasted in the resulting PNG on top of an image with black squares, and you will notice that the black squares are in fact visible: enter image description here As you can see, the black boxes are visible through the 3D objects.

But, when I disable jittering, I get this:

enter image description here

As you can see, the black boxes are not visible.

I'm on Monterrey 12.1 (21C52). I'm testing the images in Preview and in Figma.

I'm using standard SDK features only. Here's what I do:

        scene.background.contents = NSColor.clear
        
        let snapshotRenderer = SCNRenderer(device: MTLCreateSystemDefaultDevice())
        snapshotRenderer.pointOfView = sceneView.pointOfView
        snapshotRenderer.scene = scene
        snapshotRenderer.scene!.background.contents = NSColor.clear
        snapshotRenderer.autoenablesDefaultLighting = true
        
        // setting this to false does not make the image semi-transparent
        snapshotRenderer.isJitteringEnabled = true
        
        let size = CGSize(width: 1000, height: 1000)
        
        let image = snapshotRenderer.snapshot(atTime: .zero, with: size, antialiasingMode: .multisampling16X)
     
        let imageRep = NSBitmapImageRep(data: image.tiffRepresentation!)
        let pngData = imageRep?.representation(using: .png, properties: [:])
        try! pngData!.write(to: destination)

The docs for jittering says

Jittering is a process that SceneKit uses to improve the visual quality of a rendered scene. While the scene’s content is still, SceneKit moves the pointOfView location very slightly (by less than a pixel in projected screen space). It then composites images rendered after several such moves to create the final rendered scene, creating an antialiasing effect that smooths the edges of rendered geometry.

To me, that doesn't sound like something that is expected to produce semi-transparency?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source