subtract blendMode odd behaviour

I have two sprites that I want to overlay with standard alpha blending. However the 'front' sprite is itself derived from a snapshot texture of a node tree that uses subtractive blending. I wouldn't expect that to make a difference - the SKTexture that comes out has been flattened, hasn't it? So as long as it's used to create a front sprite that uses normal alpha blending I wouldn't expect a problem. Except it behaves very oddly. The following code illustrates the point (it's a simplified version of my code).

        backgroundColor = .black
        let masterNode = SKNode()
        let bground = SKShapeNode(circleOfRadius: 100)
        bground.fillColor = .red
        bground.position.x = -75
        bground.zPosition = -1
        bground.blendMode = .alpha
        masterNode.addChild(bground)
        let temp1 = SKShapeNode(circleOfRadius: 100)
        temp1.fillColor = .lightGray
        let temp2 = SKShapeNode(circleOfRadius: 50)
        temp2.fillColor = .red
        temp2.blendMode = .subtract
        temp2.zPosition = 1
        temp1.addChild(temp2)
        let fground = SKSpriteNode(texture: SKView().texture(from: temp1))
        fground.blendMode = .alpha
        masterNode.addChild(fground)
        addChild(masterNode)
        masterNode.position.x = UIScreen.main.bounds.width/2
        masterNode.position.y = UIScreen.main.bounds.height/2


I realise some of these lines are unnecessary, it's just to make clear the blendMode being applied.


I'm expecting a cyan hole that isn't blended at all with the background because the cyan hole should have alpha values of 1.0.


It follows that I'm NOT expecting the bground shape to "show through" the hole - but it does.


Also, I'm definitely not expecting the bground shape to be blending additively with the hole - it's not even demonstrating normal alpha blending.


Can anyone help me understsand what's going on?


Matt

Replies

Red circle beneath grey circle with subtracted hole


This is the result of the above code, just to make it a bit clearer. The red circle underneath is plainly showing through which suggests that the "hole" has alpha between 0 and 1 which makes no sense to me. Can anyone point me to a clear explanation of how the subtract blend mode works? I'd really prefer not to have to deal with custom shaders. Subtract should be perfect for what I need.


Thanks,


Matt

Well, this is embarrassing, turns out it's just a fault with the simulator. It works absolutely fine on the device. A good lesson for the future for me!