<!--
{
  "documentType" : "article",
  "framework" : "SpriteKit",
  "identifier" : "/documentation/SpriteKit/applying-shaders-to-a-sprite",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Applying Shaders to a Sprite"
}
-->

# Applying Shaders to a Sprite

Write custom GLSL code that modifies the look of your sprite.

## Discussion

You can use the [`shader`](/documentation/SpriteKit/SKSpriteNode/shader) property of a sprite node to change the appearance of a texture with a custom OpenGL ES fragment shader embedded within a [`SKShader`](/documentation/SpriteKit/SKShader) object. Custom shaders offer almost limitless possibilities, from adding blurs and color treatments to textures to generating imagery such as random noise.

The following code shows a small custom shader which inverts the color of a texture while leaving the alpha or transparency unaffected:

```swift
let negativeShader = SKShader(source: "void main() { " +
    "    gl_FragColor = vec4(1.0 - SKDefaultShading().rgb, SKDefaultShading().a); " +
    "}")
rocket.shader = negativeShader
```

The following figure illustrates the effect of the shader. The original image, on the left, has its colors inverted by the shader:

![Example of a color inverted sprite](images/com.apple.spritekit/media-2983067@2x.png)

---

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)