SKShader performance slowdown

萝らか妹 提交于 2019-12-03 10:09:24

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)
    }

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!