---
title: SKShader
framework: spritekit
role: symbol
role_heading: Class
path: spritekit/skshader
---

# SKShader

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

## Declaration

```swift
class SKShader
```

## Mentioned in

Controlling Shape Drawing with Shaders Applying Shaders to a Sprite Creating a Custom Fragment Shader Creating a New Node By Rendering To a Texture Customizing the Behavior of a Node Executing Shaders in Metal and OpenGL Getting Started with Particle Shaders

## Overview

Overview An 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 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 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 objects and associate them with the relevant nodes. Then, assign the shader object to the 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: 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](spritekit/creating-a-custom-fragment-shader.md)
- [init(fileNamed:)](spritekit/skshader/init(filenamed:).md)
- [init(source:uniforms:)](spritekit/skshader/init(source:uniforms:).md)
- [init(source:)](spritekit/skshader/init(source:).md)

### Providing Uniform Data to a Shader

- [addUniform(_:)](spritekit/skshader/adduniform(_:).md)
- [removeUniformNamed(_:)](spritekit/skshader/removeuniformnamed(_:).md)
- [uniforms](spritekit/skshader/uniforms.md)
- [uniformNamed(_:)](spritekit/skshader/uniformnamed(_:).md)

### Providing Attribute Data to a Shader

- [attributes](spritekit/skshader/attributes.md)

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

- [source](spritekit/skshader/source.md)

### Executing Shaders in Metal and OpenGL

- [Executing Shaders in Metal and OpenGL](spritekit/executing-shaders-in-metal-and-opengl.md)

### Initializers

- [init(coder:)](spritekit/skshader/init(coder:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Shaders

- [SKAttribute](spritekit/skattribute.md)
- [SKAttributeValue](spritekit/skattributevalue.md)
- [SKUniform](spritekit/skuniform.md)
