如何降低渲染器利用率?

时间:2015-11-05 20:41:32

标签: ios opengl-es scenekit

我在使用SceneKit游戏遇到严重的性能问题。总顶点数为4000.渲染器利用率在ipad3上为100%,帧率为16fps,即使Tiler利用率仅为8%左右。这是OPENGL ES Analysis的截图。

enter image description here

这是用于指定对象应该是什么样的整个代码。如您所见,没有自定义着色器。只是一个因为应用了物理而落在地板上的盒子。纹理和2个灯应用于.scn文件中。一切都很简单,基本但表现很糟糕。如何降低设备上的渲染器利用率?我猜测sceneKit使用的一些默认设置不适合我的应用程序,并导致严重的性能问题。我应该仔细检查哪一个?

//called in viewDidLoad:
 func setupScene(){
            scene = SCNScene(named: "GameScene.scn")
            sceneView.scene = scene
            sceneView.delegate = self
            scene.physicsWorld.contactDelegate = self
            scene.physicsWorld.gravity = SCNVector3Make(0, 0, 0)
            scene.physicsWorld.speed = 1.8
            sceneView.jitteringEnabled = true
            sceneView.autoenablesDefaultLighting = false


        sceneView.antialiasingMode = SCNAntialiasingMode.None
        let valueVector: NSValue = NSValue(SCNVector3: SCNVector3Make(0.7, 0.7, 0.7))
        objectNode = scene.rootNode.childNodeWithName("object", recursively: true)!
        let physicsShape = SCNPhysicsShape(node: objectNode, options: [SCNPhysicsShapeTypeKey:SCNPhysicsShapeTypeBoundingBox, SCNPhysicsShapeScaleKey:valueVector])
        objectNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: physicsShape)

        let floorNode = scene.rootNode.childNodeWithName("floor", recursively: true)
        floorNode?.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static, shape: nil)
     objectNode.categoryBitMask = 1
        floorNode?.categoryBitMask = 1
        objectNode.physicsBody?.categoryBitMask = 1
        floorNode?.physicsBody?.categoryBitMask = 1
        objectNode.physicsBody?.collisionBitMask = 1
        floorNode?.physicsBody?.collisionBitMask = 1

        floorNode?.physicsBody?.restitution = 0.7
        objectNode.physicsBody?.restitution = 0.7


        }

func speed(velocity:SCNVector3) -> Float
    {
        let dx = Float(velocity.x)
        let dy = Float(velocity.y)
        let dz = Float(velocity.z)
        return sqrtf(dx*dx+dy*dy+dz*dz)
    }
    func angularSpeed(angularSpeed: SCNVector4)->Float{
        let x = angularSpeed.x

        let y = angularSpeed.y
        let z = angularSpeed.z

        return sqrtf(x*x+y*y+z*z)
    }

    func nearlyAtRest(node:SCNNode) -> Bool
    {

        return speed((node.physicsBody?.velocity)!) < 0.05 && ( self.resting == false) && (angularSpeed((node.physicsBody?.angularVelocity)!) < 1)
    }


// PHYSICS CONTACT DELEGATE DELEGATE METHOD
        func renderer(renderer: SCNSceneRenderer, didSimulatePhysicsAtTime time: NSTimeInterval) {

      if nearlyAtRest(objectNode) && speed((objectNode.physicsBody?.velocity)!) != 0 {
    print("it stopped")
    }

0 个答案:

没有答案