A container for dynamic shader data associated with a node.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
SpriteKit nodes that are rendered with a custom shader can use
SKAttribute objects to pass dynamic values which can change without requiring that shader to be recompiled. An attribute value is passed to a shader using a node’s
set method using the relevant attribute’s name. For example, given a shader with a
SKAttribute attribute named
The following code sets the value of this attribute to
10 and passes it to a
SKSprite object’s shader:
a, is available as a global floating-point variable within the shader code.
Using this technique, a single shader can be shared across many nodes and each nodes can supply its own attributes. This approach is an alternative to using
SKUniform objects which would require a recompilation for each distinct set of parameters.