<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/SKShader",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "SpriteKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SKShader"
  },
  "title" : "SKShader"
}
-->

# SKShader

An object that allows you to apply a custom fragment shader.

```
class SKShader
```

## Overview

An [`SKShader`](/documentation/SpriteKit/SKShader) object holds a custom OpenGL ES fragment shader. Shader objects are used to customize the drawing behavior of many different kinds of nodes in SpriteKit.

To use a custom shader, create an [`SKShader`](/documentation/SpriteKit/SKShader) object and provide the source for the custom fragment shader. If your shader needs to provide uniform data to the shader, create one or more [`SKUniform`](/documentation/SpriteKit/SKUniform) objects and associate them with the shader object. If your shader needs to provide per-node data to the shader, create one or more [`SKAttribute`](/documentation/SpriteKit/SKAttribute) objects and associate them with the relevant nodes. Then, assign the shader object to the [`shader`](/documentation/SpriteKit/SKSpriteNode/shader) property of any sprites that need the custom behavior.

Compiling a shader and the uniform data associated with it can be expensive. Because of this, you should:

- Initialize shader objects when your game launches, not while the game is running.
- Avoid changing the shader’s source or changing the list of uniforms or attributes while your game is running. Either of these things recompiles the shader.
- Share shader objects whenever possible. If multiple sprites need the same behavior, create one shader object and associate it with every sprite that needs that behavior. Do not create a separate shader for each sprite.

> Important:
> ``doc://com.apple.spritekit/documentation/SpriteKit/SKShader`` does not support OpenGL Extensions. SpriteKit will return an error if you compile a project containing a fragment shader using extensions.

## Topics

### Creating a Shader

[Creating a Custom Fragment Shader](/documentation/SpriteKit/creating-a-custom-fragment-shader)

Write a fragment shader using the set of SpriteKit-exposed symbols, and supply it with custom data.

[`init(fileNamed:)`](/documentation/SpriteKit/SKShader/init(fileNamed:))

Creates a new shader object by loading the source for a fragment shader from a file stored in the app’s bundle.

[`shaderWithSource:uniforms:`](/documentation/SpriteKit/SKShader/shaderWithSource:uniforms:)

Creates a new shader object using the specified source and uniform data.

[`shaderWithSource:`](/documentation/SpriteKit/SKShader/shaderWithSource:)

Creates a new shader object using the specified source code.

[`shader`](/documentation/SpriteKit/SKShader/shader)

Creates a new empty shader object.

[`init(source:uniforms:)`](/documentation/SpriteKit/SKShader/init(source:uniforms:))

Initializes a new shader object using the specified source and uniform data.

[`init(source:)`](/documentation/SpriteKit/SKShader/init(source:))

Initializes a new shader object using the specified source code.

### Providing Uniform Data to a Shader

[`addUniform(_:)`](/documentation/SpriteKit/SKShader/addUniform(_:))

Adds a uniform to the shader.

[`removeUniformNamed(_:)`](/documentation/SpriteKit/SKShader/removeUniformNamed(_:))

Removes a uniform from the shader.

[`uniforms`](/documentation/SpriteKit/SKShader/uniforms)

The list of uniforms associated with the shader.

[`uniformNamed(_:)`](/documentation/SpriteKit/SKShader/uniformNamed(_:))

Returns the uniform object corresponding to a particular uniform variable.

### Providing Attribute Data to a Shader

[`attributes`](/documentation/SpriteKit/SKShader/attributes)

The list of attributes associated with the shader.

### Accessing or Setting a Shader’s Source Code

[`source`](/documentation/SpriteKit/SKShader/source)

The source code for the shader.

### Executing Shaders in Metal and OpenGL

[Executing Shaders in Metal and OpenGL](/documentation/SpriteKit/executing-shaders-in-metal-and-opengl)

Toggle between renderers to make sure your shader code compiles in both the Metal and OpenGL environments.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)