<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Shader",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6ShaderV"
  },
  "title" : "Shader"
}
-->

# Shader

A reference to a function in a Metal shader library, along with its
bound uniform argument values.

```
struct Shader
```

## Overview

Shader values can be used as filter effects on views, see the
[`colorEffect(_:isEnabled:)`](/documentation/SwiftUI/View/colorEffect(_:isEnabled:)),
[`distortionEffect(_:maxSampleOffset:isEnabled:)`](/documentation/SwiftUI/View/distortionEffect(_:maxSampleOffset:isEnabled:)),
and [`layerEffect(_:maxSampleOffset:isEnabled:)`](/documentation/SwiftUI/View/layerEffect(_:maxSampleOffset:isEnabled:)) functions.

Shaders also conform to the [`ShapeStyle`](/documentation/SwiftUI/ShapeStyle) protocol, letting their
MSL shader function provide per-pixel color to fill any shape or
text view. For a shader function to act as a fill pattern it must
have a function signature matching:

```
[[ stitchable ]] half4 name(float2 position, args...)
```

where `position` is the user-space coordinates of the pixel applied
to the shader, and `args...` should be compatible with the uniform
arguments bound to `shader`. The function should return the
premultiplied color value in the color space of the destination
(typically extended sRGB).

## Topics

### Creating a shader

[`init(function:arguments:)`](/documentation/SwiftUI/Shader/init(function:arguments:))

Creates a new shader from a function and the uniform argument
values to bind to the function.

[`Argument`](/documentation/SwiftUI/Shader/Argument)

A single uniform argument value to a shader function.

### Getting the shader function

[`function`](/documentation/SwiftUI/Shader/function)

The shader function called by the shader.

[`arguments`](/documentation/SwiftUI/Shader/arguments)

The uniform argument values passed to the shader function.

### Configuring the shader

[`dithersColor`](/documentation/SwiftUI/Shader/dithersColor)

For shader functions that return color values, whether the
returned color has dither noise added to it, or is simply
rounded to the output bit-depth. For shaders generating smooth
gradients, dithering is usually necessary to prevent visible
banding in the result.

## Relationships

### Conforms To

[`Equatable`](/documentation/Swift/Equatable)

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`ShapeStyle`](/documentation/SwiftUI/ShapeStyle)

[`Escapable`](/documentation/Swift/Escapable)

[`Copyable`](/documentation/Swift/Copyable)

---

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)