SKShader performance slowdown

前端 未结 2 892
广开言路
广开言路 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)
        }
    
    0 讨论(0)
  • 2021-02-11 09:58

    Gelan Almagro's answer above works perfectly. I'm adding the Objective-C code for the update: method.

    SKSpriteNode *shadedNode = (SKSpriteNode*)[self childNodeWithName:@"shadedNode"];
    SKUniform *uniform = [shadedNode.shader uniformNamed:@"myUniform"];
    uniform.floatValue = (float)currentTime;
    
    0 讨论(0)
提交回复
热议问题