Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

ios - SKLightNode performance issues

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...