SKShader performance slowdown

前端 未结 2 894
广开言路
广开言路 2021-02-11 09:04

I need to implement a custom shader node using SpriteKit. In simulator everything is ok. On a device (iPad 3rd gen) shader animation is smooth just for first ~30 seconds, after

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-11 09:48

    This is an issue with the u_time uniform, I got around it by adding my own uniform float and using it instead of using u_time

    Shader

    void main(void)
         {
            float currTime = myUniform;
            ...
        }
    

    Update

     override func update(currentTime: CFTimeInterval) {
            let shadedNode = self.childNodeWithName("shadedNode") as SKSpriteNode
            let uniform = shadedNode.shader!.uniformNamed("myUniform")
            uniform!.floatValue = Float(currentTime)
        }
    

提交回复
热议问题