Shader
A reference to a function in a Metal shader library, along with its bound uniform argument values.
Declaration
type Shader = { function: ShaderFunction; arguments: ShaderArgument[]; };struct ShaderProperties
function*ShaderFunctionThe shader function called by the shader.
arguments*ShaderArgument[]The uniform argument values passed to the shader function.
Overview
Shader values can be used as filter effects on views, see the
View.colorEffect(_:isEnabled:),
View.distortionEffect(_:maxSampleOffset:isEnabled:),
and View.layerEffect(_:maxSampleOffset:isEnabled:) functions.
Shaders also conform to the 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).
From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
- colorEffectReturns a new view that applies shader to self as a filter effect on the color of each pixel.
- distortionEffectReturns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
- layerEffectReturns a new view that applies shader to self as a filter on the raster layer created from self.
See also
More in Drawing and shapes.
- AngleA geometric angle whose value you access in either radians or degrees.
- AngularGradientAn angular gradient.
- AnyGradientA color gradient.
- BlendModeModes for compositing a view with overlapping content.
- ButtonBorderShapeA shape used to draw a button's border.
- ColorMatrixA matrix to use in an RGBA color transformation.
- ConcentricRectangleAnimatableDataThe type defining the data to animate.
- ContainerRelativeShapeA shape that is replaced by an inset version of the current container shape. If no container shape was defined, is replaced by a rectangle.
- ContentShapeKindsA kind for the content shape of a view.
- CoordinateSpaceProtocolA frame of reference within the layout system.
- DefaultGlassEffectShapeThe default shape applied by glass effects, a capsule.
- EllipticalGradientA radial gradient that draws an ellipse.