0

In SpriteKit, how is the default blending mode (SKBlendModeAlpha) calculated? Can you please verify that it works on my example points below? All nodes below use the default SKBlendModeAlpha.

My scene has a white background and two identical child nodes of uniform color that partially intersect each other. The true RGB of each node is (16, 195, 117) and alpha = 0.4.

When I look at the blended color of the node sitting on the white background, the color is (158, 221, 190). (This was confirmed by doing a screen capture and checking in gimp).

How was this calculated by SpriteKit?

When I look at the blended color of the intersected area of two nodes on the white background, the RGB is (112, 203, 153).

How was this calculated by SpriteKit?

Thanks!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
rimsky
  • 1,163
  • 3
  • 16
  • 27
  • 1
    GIMP, macs and iOS devices have different color spaces which may result in different RGB values. If you use the digital color meter.app you can change the color space you measure in. –  Feb 08 '15 at 09:46

1 Answers1

1

Thanks Okapi. That was the key to finding the answer. Using "Display native values" helped me see that for each RGB component, it's:

final_color = previous_final_color * (1 - alpha) + new_color * alpha.

For one layer on white, I indeed get an RGB of

(159, 231, 200) = floor(0.6 * (255, 255, 255) + 0.4 * (16, 195, 117))

For the two layers on white, I get an RGB of

(101, 216, 166) = floor(0.6 * (159, 231, 200) + 0.4 * (16, 195, 117))
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
rimsky
  • 1,163
  • 3
  • 16
  • 27