Shader
public final class Shader
Shaders specify the source color(s) for what is being drawn. If a paint has no shader, then the paint’s color is used. If the paint has a shader, then the shader’s color(s) are use instead, but they are modulated by the paint’s alpha. This makes it easy to create a shader once (e.g. bitmap tiling or gradient) and then change its transparency w/o having to modify the original shader… only the paint’s alpha needs to be modified.
Use any of the various static make methods to create the shader
-
Undocumented
Declaration
Swift
public func makeEmpty() -> Shader -
Undocumented
Declaration
Swift
public static func makeColor(color: Color) -> Shader -
Creates a new shader that will draw with the specified bitmap.
If the bitmap cannot be used (has no pixels, or its dimensions exceed implementation limits) then an empty shader may be returned. If the source bitmap’s color type is Alpha8 then that mask will be colorized using the color on the paint.
Declaration
Swift
public static func makeBitmap(source: Bitmap, tileModeX: ShaderTileMode, tileModeY: ShaderTileMode) -> ShaderParameters
sourceThe bitmap to use inside the shader.
tileModeXThe tiling mode to use when sampling the bitmap in the x-direction.
Return Value
Returns a new SKShader, or an empty shader on error.
-
Creates a new shader that will draw with the specified bitmap.
If the bitmap cannot be used (has no pixels, or its dimensions exceed implementation limits) then an empty shader may be returned. If the source bitmap’s color type is Alpha8 then that mask will be colorized using the color on the paint.
Declaration
Swift
public static func makeBitmap(source: Bitmap, tileModeX: ShaderTileMode, tileModeY: ShaderTileMode, localMatrix: Matrix) -> Shader?Parameters
sourceThe bitmap to use inside the shader.
tileModeXThe tiling mode to use when sampling the bitmap in the x-direction.
localMatrixThe matrix to apply before applying the shader.
Return Value
Returns a new SKShader, or an nil shader on error.
-
Creates a new shader that produces the same colors as invoking this shader and then applying the color filter.
Declaration
Swift
public static func makeColorFilter(shader: Shader, colorFilter: ColorFilter) -> ShaderParameters
shaderThe shader to apply
tileModeXthe color filter to apply
Return Value
Returns a new SKShader, or an empty shader on error.
-
Creates a shader that first applies the specified matrix and then applies the shader.
Declaration
Swift
public static func makeLocalMatrix(shader: Shader, localMatrix: Matrix) -> Shader?Parameters
shaderThe shader to apply
localMatrixThe matrix to apply before applying the shader.
Return Value
Returns a new SKShader, or nil on error (the matrix can not be inverted)
-
Creates a shader that generates a linear gradient between the two specified points.
Declaration
Swift
public static func makeLinearGradient(start: Point, end: Point, colors: [Color], colorPos: [Float]?, mode: ShaderTileMode) -> ShaderParameters
startThe start point for the gradient.
endThe end point for the gradient.
colorsThe array colors to be distributed between the two points.
colorPosThe positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.
modeThe tiling mode.
Return Value
Returns a new SKShader, or an empty shader on error.
-
Creates a shader that generates a linear gradient between the two specified points.
Declaration
Swift
public static func makeLinearGradient(start: Point, end: Point, colors: [Color], colorPos: [Float]?, mode: ShaderTileMode, localMatrix: Matrix? = nil) -> Shader?Parameters
startThe start point for the gradient.
endThe end point for the gradient.
colorsThe array colors to be distributed between the two points.
colorPosThe positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.
modeThe tiling mode.
Return Value
Returns a new SKShader, or nil on error
-
Creates a shader that generates a radial gradient given the center and radius.
Declaration
Swift
public static func makeRadialGradient(center: Point, radius: Float, colors: [Color], colorPos: [Float]?, mode: ShaderTileMode, localMatrix: Matrix? = nil) -> Shader?Parameters
centerThe center of the circle for this gradient.
radiusThe positive radius of the circle for this gradient.
colorsThe array colors to be distributed between the center and edge of the circle.
colorPosThe positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.
modeThe tiling mode.
localMatrixoptional, the matrix to apply before applying the shader.
Return Value
a new shader
-
Creates a shader that generates a sweep gradient given a center.
Declaration
Swift
public static func makeSweepGradient(center: Point, colors: [Color], colorPos: [Float]?, mode: ShaderTileMode = .clamp, startAngle: Float = 0, endAngle: Float = 360, localMatrix: Matrix? = nil) -> Shader?Parameters
centerThe coordinates of the center of the sweep.
colorsThe array colors to be distributed between the center and edge of the circle.
colorPosThe positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.
modeThe tiling mode.
startAngleThe start of the angular range.
endAngleThe end of the angular range.
localMatrixoptional, the matrix to apply before applying the shader.
Return Value
a new shader
-
Creates a shader that generates a conical gradient given two circles.
Declaration
Swift
public static func makeTwoPointConicalGradient(start: Point, startRadius: Float, end: Point, endRadius: Float, colors: [Color], colorPos: [Float]?, mode: ShaderTileMode = .clamp, localMatrix: Matrix? = nil) -> Shader?Parameters
startThe coordinates for the starting point.
startRadiusThe radius at the starting point.
endThe coordinates for the end point.
endRadiusThe radius at the end point.
colorsThe array colors to be distributed between the center and edge of the circle.
colorPosThe positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.
modeThe radius at the end point.
localMatrixoptional, the matrix to apply before applying the shader.
Return Value
a new shader
-
Creates a new shader that draws Perlin fractal noise.
Declaration
Swift
public static func makePerlinNoiseFractalNoise(baseFrequencyX: Float, baseFrequencyY: Float, numOctaves: Int32, seed: Float, tileSize: ISize? = nil) -> ShaderParameters
baseFrequencyXThe frequency in the x-direction in the range of 0..1.
baseFrequencyYThe frequency in the y-direction in the range of 0..1.
numOctaveshe number of octaves, usually fairly small.
seedThe randomization seed.
tileSizeThe tile size used to modify the frequencies so that the noise will be tileable for the given size.
Return Value
a new shader
-
Creates a new shader that draws Perlin turbulence noise.
Declaration
Swift
public static func makePerlinNoiseTurbulence(baseFrequencyX: Float, baseFrequencyY: Float, numOctaves: Int32, seed: Float, tileSize: ISize? = nil) -> ShaderParameters
baseFrequencyXThe frequency in the x-direction in the range of 0..1.
baseFrequencyYThe frequency in the y-direction in the range of 0..1.
numOctaveshe number of octaves, usually fairly small.
seedThe randomization seed.
tileSizeThe tile size used to modify the frequencies so that the noise will be tileable for the given size.
Return Value
a new shader
-
Create a new compose shader, which combines two shaders optionally, with a blend mode. The colors from this shader are seen as the destination by the blend mode.
Declaration
Swift
public func compose(with: Shader, blend: BlendMode? = nil) -> ShaderParameters
withThe colors from this shader are seen as the source by the blend mode.
blendThe blend mode that combines the two shaders.
Return Value
a new shader that composes the current shader with the provided one
View on GitHub
Install in Dash
Shader Class Reference