layerEffect
Returns a new view that applies shader to self as a filter on the raster layer created from self.
Declaration
compose().layerEffect(
shader: SwiftUI.Shader,
options: {
maxSampleOffset: CGSize;
isEnabled?: boolean;
}
)nonisolated func layerEffect(
_ shader: Shader,
maxSampleOffset: CGSize,
isEnabled: Bool = true
) -> some ViewParameters
shader*SwiftUI.ShaderThe shader to apply as a layer effect.
options.maxSampleOffset*CGSizeIf the shader function samples from the layer at locations not equal to the destination position, this value must specify the maximum sampling distance in each axis, for all source pixels.
options.isEnabledbooleanWhether the effect is enabled or not.
Return value
A new view that renders self with the shader applied as a distortion effect.
Discussion
For a shader function to act as a layer effect it must have a function signature matching:
[[ stitchable ]] half4 name(float2 position,
SwiftUI::Layer layer, args...)where position is the user-space coordinates of the
destination pixel applied to the shader, and layer is a
subregion of the rasterized contents of self. args...
should be compatible with the uniform arguments bound to
shader.
The SwiftUI::Layer type is defined in the
<SwiftUI/SwiftUI.h> header file. It exports a single
sample() function that returns a linearly-filtered pixel
value from a position in the source content, as a premultiplied
RGBA pixel value:
namespace SwiftUI {
struct Layer {
half4 sample(float2 position) const;
};
};The function should return the color mapping to the destination
pixel, typically by sampling one or more pixels from layer at
location(s) derived from position and them applying some kind
of transformation to produce a new color.
See also
More in Visual effects.
- allowedDynamicRangeReturns a new view configured with the specified allowed dynamic range.
- backgroundExtensionEffectAdds the background extension effect to the view. The view will be duplicated into mirrored copies which will be placed around the view on any edge with available safe area. Additionally, a blur effect will be applied on top to blur out the copies.
- blurApplies a Gaussian blur to this view.
- brightnessBrightens this view by the specified amount.
- clippedClips this view to its bounding rectangular frame.
- colorEffectReturns a new view that applies shader to self as a filter effect on the color of each pixel.
- colorInvertInverts the colors in this view.
- colorMultiplyAdds a color multiplication effect to this view.
- compositingGroupWraps this view in a compositing group.
- contrastSets the contrast and separation between similar colors in this view.
- distortionEffectReturns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
- drawingGroupComposites this view's contents into an offscreen image before final display.