SKLabel Alpha Blending SKRenderer

I’ve added an SKRenderer to my MTKView. I’m able to add SkLabels and SKSprites as expected. But I believe there’s an issue with the alpha configuration in my PipelineDescriptor.

When I attempt to draw an SKLabel over an SKSprite, the alpha of the label completely overwrites the sprite.

    cLabel = SKLabelNode(fontNamed: "ArialMT")
cLabel.text = "Test Text"
cLabel.fontSize = 65
cLabel.fontColor = SKColor.white
cLabel.position = CGPoint(x: 1125 / 2, y: (2436-2436 / 10))
scene.addChild(cLabel)

let sprite = SKSpriteNode(imageNamed: "banner.png")
sprite.position = CGPoint(x: 1125 / 2, y: (2436-2436 / 12))
sprite.name = "sprite"
scene.addChild(sprite)

Render Issue

1 Like

I’m away from my computer for a few days, but I can take a look late next week if you don’t find a solution first. I doubt I can help, as that sort of thing is generally straightforward.
I see someone on stackoverflow had the same problem. I actually thought SKRenderer wasn’t working at all, as I had issues in the last book update, but perhaps it’s fixed now.
What Xcode and os are you using?

1 Like

Hey Caroline,

Thank you so much for looking into this. I’m using Xcode 12.5.1 and targeting iOS 14.5. I’m relatively new to swift and didn’t know you could apply spritekit shaders.

Just as a test I created TextShader.fsh and I call my SKRenderer at the end of my RenderCommandEncoder

void main()
{
   vec4 color = SKDefaultShading(); // the current label color

   //0.2 was determined to be a good roll off point
   if(color.a < 0.2){
      //Replace this with background color set by uniform
      color.r = 0.498;
      color.g = 0.278;
      color.b = 0.866;
    
      color.a = 1;
    }
   gl_FragColor = color;
}

And got the expected result

Resolved

1 Like