distortionEffect
Returns a new view that applies shader to self as a geometric distortion effect on the location of each pixel.
Declaration
compose().distortionEffect(
shader: SwiftUI.Shader,
options: {
maxSampleOffset: CGSize;
isEnabled?: boolean;
}
)nonisolated func distortionEffect(
_ shader: Shader,
maxSampleOffset: CGSize,
isEnabled: Bool = true
) -> some ViewParameters
shader*SwiftUI.ShaderThe shader to apply as a distortion effect.
options.maxSampleOffset*CGSizeThe maximum distance in each axis between the returned source pixel position and the destination pixel position, 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 distortion effect it must have a function signature matching:
[[ stitchable ]] float2 name(float2 position, args...)where position is the user-space coordinates of the
destination pixel applied to the shader. args... should be
compatible with the uniform arguments bound to shader. The
function should return the user-space coordinates of the
corresponding source pixel.
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.
- drawingGroupComposites this view's contents into an offscreen image before final display.
- glassEffectApplies a glass effect to this view.