I have been trying to find information on this, but I just can't find anything. The SKShader and SKUniform reference documents do not provide this information, and neither does the SpriteKit Programming Guide document (and in fact, it seems that shaders are not mentioned there at all, even though the document is linked to from the SKShader and SKUniform reference documents). Couldn't find this by googling either.
The SKShader documentation recommends sharing shaders between sprites as much as possible. In other words, if two sprites use the same shader, it's better to share the same SKShader object between them rather than create a new shader for each one.
But what if two such sprites use the same shader, but different uniform values? For example, there may be a uniform named "factor" used in the shader, and one sprite wants to use a value of 0.25 for it, while another wants to use a value of 0.4. (As far as I understand, this is something that can be done with one single shader, and it should be completely efficient. Nothing changes when rendering the sprites, except the value of that uniform, which should be possible and efficient.)
I can't find any info on what the kosher way of doing this in SpriteKit using SKShader.
The 'shader' property of SKSpriteNode retains the object. Which means that the one and same SKShader object will be shared between two sprites if I simply assign one to both. Obviously this won't work if I want them to use a different value for a uniform.
I notice that SKShader is copyable. Should I assign a copy of the original SKShader object to each sprite? Will this work? Will it be efficient? Can then each copy be assigned different uniform values and then they will work properly? Or do I need to replace the SKUniform objects in each copy with new objects?
What is the correct way of doing this?
After reviewing the latest WWDC, it seems that you were right. If you have a 3 guys using the same shader but with different Uniform values, you need to create three instances of the shader.
Now, in iOS 10, you can use SKAttributes to share a shader between different Sprites and set and attribute on the sprite that the shader will use instead of the Uniform.
Check Session 610.
Hope it helps