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
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;