SKLightNode performance issues
Asked Answered
R

1

6

I've been experimenting with SKLightNode in SpriteKit (new in iOS8) and, even in a really simple test case, I've been getting terrible performance. For instance, with a single light source on a solid color SKSpriteNode I get 13.2 FPS on a 3rd generation iPad. If I add a second light source, it drops to an abysmal 7.7 FPS.

The WWDC session video What's New in SpriteKit mentions that you might get less than 60 FPS if you have more than one light on the same sprite, but I can't even get 60 FPS with one. Here's the relevant section.

Here's my test scene in swift (it starts with one light source and more can be added by tapping):

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        let center = CGPointMake(size.width / 2.0, size.height / 2.0)

        let background = SKSpriteNode(color: SKColor.lightGrayColor(), size: size)
        background.position = center
        background.lightingBitMask = 1
        addChild(background)

        let light = SKLightNode()
        light.position = center
        light.falloff = 1.0
        light.lightColor = SKColor(hue: 0.62 , saturation: 0.89, brightness: 1.0, alpha: 0.4)
        light.shadowColor = SKColor.blackColor().colorWithAlphaComponent(0.4)
        addChild(light)
    }

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        for touch: AnyObject in touches {
            let location = touch.locationInNode(self)

            let light = SKLightNode()
            light.position = location
            light.falloff = 1.0
            light.lightColor = SKColor(hue: 0.62 , saturation: 0.89, brightness: 1.0, alpha: 0.4)
            light.shadowColor = SKColor.blackColor().colorWithAlphaComponent(0.4)
            addChild(light)
        }
    }

}

Here are some screen shots of it running on my 3rd gen iPad:

1 light source 2 light sources

And here's what the performance tab looks like after clicking the "Analyze" button when it's running with a single light source:

performance analysis

It's obviously GPU bound, but what I'm trying to figure out is if I'm just doing something horribly wrong, or if this is just an issue with the beta that will (hopefully) be cleared up by release time. I'm currently using Xcode6-Beta5.


UPDATE

I upgraded my iPhone 5S to iOS8 and tried the same thing there and it ran perfectly fine at 60FPS with 8 light sources. So, I guess this is just an issue with the 3rd generation iPad's GPU just not being up to the task. I'll try again after the next beta is released and see if anything changes, just in case.

Rahmann answered 15/8, 2014 at 2:30 Comment(10)
Have you tried running time profiler to see where the slowdown is?Riser
I added a screen shot of the performance tab after running its analyzer. It's definitely something that's GPU bound, but that's all provided by SpriteKit itself (I don't have any custom shaders or anything) so I don't know if there's anything I can do about it.Rahmann
What if you configure and add the SKLightNode ahead of time, and hide it? Then just show it in touchesBegan?Riser
(That would help if the actual initialization was expensive.)Riser
Ok, I tried that. Full 60 FPS with the SKLightNode initialized and added to the scene graph but disabled, drops back to 13 FPS when the SKLightNode is enabled.Rahmann
Just a thought, but have you tried putting a println() in didMoveToView to see how many times it's getting called?Kahn
I assume you are running this on your actual device, but have you got several apps open which are draining memory. I copied your code into my own project and ran it on my iPad 3 and could have up to 7 light nodes with 60FPS so i can't understand why you are having such difficulties.Plinth
@JackC I am running this on my actual device which is a 3rd gen iPad (I think that's different than an iPad 3 though). I have no other apps running. Maybe my hardware is just too old? I'm going to try upgrading my iPhone 5S to iOS8 to see how it runs there.Rahmann
@MikeS Good Idea. It ran on my 5S very well.Plinth
@JackC looks like it runs perfectly fine on my 5S, so I guess it's just an issue with my iPad's GPU not being up to the task. Thanks for your help.Rahmann
R
2

This ended up just being an issue with the GPU on the 3rd gen iPad not being up to the task to using SKLightNodes. I've now tested on iOS 8 and iOS 8.1 using the latest version of Xcode at the time (Version 6.1 (6A1052d) for iOS 8.1), with the same results. My test code runs at 60FPS on a iPhone 5s with 8 light sources, so the code itself doesn't seem to be the issue.

Rahmann answered 12/11, 2014 at 1:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.