I doubt anyone is reading this six years later, but I just ran into this and it is not working. For some reason, it is applying the SKAttribute to all copies of the sprite node.
The sprite with shader is initialized like this:
birdFillShader = shaderWithFilename( "birdFill", fileExtension: "fsh", uniforms: uniforms )
birdFillShader.attributes = [SKAttribute(name: "a_rand", type: .float)]
self.birdNode = SKShapeNode( rect: CGRect(x: -100, y: -100, width: 200, height: 200) )
if let birdNode = self.birdNode {
birdNode.strokeColor = .clear
birdNode.fillShader = birdFillShader
}
Later on, the sprite is cloned and the SKAttribute is set:
if let birdNode = self.birdNode?.copy() as! SKShapeNode? {
let aRand = Float.random(in: 0.0...1.0)
birdNode.setValue(SKAttributeValue(float: aRand), forAttribute: "a_rand")
/* ... set position of node ... */
}
For the moment, the shader is doing this:
void main()
{
gl_FragColor = vec4(vec3(a_rand), 1.0);
}
I am cloning multiple sprites and they all seem to share the same value for a_rand as noted by the color being uniform and changing across all created sprites.