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) -> Shader

    Parameters

    source

    The bitmap to use inside the shader.

    tileModeX

    The 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

    source

    The bitmap to use inside the shader.

    tileModeX

    The tiling mode to use when sampling the bitmap in the x-direction.

    localMatrix

    The 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) -> Shader

    Parameters

    shader

    The shader to apply

    tileModeX

    the 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

    shader

    The shader to apply

    localMatrix

    The 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) -> Shader

    Parameters

    start

    The start point for the gradient.

    end

    The end point for the gradient.

    colors

    The array colors to be distributed between the two points.

    colorPos

    The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

    mode

    The 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

    start

    The start point for the gradient.

    end

    The end point for the gradient.

    colors

    The array colors to be distributed between the two points.

    colorPos

    The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

    mode

    The 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

    center

    The center of the circle for this gradient.

    radius

    The positive radius of the circle for this gradient.

    colors

    The array colors to be distributed between the center and edge of the circle.

    colorPos

    The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

    mode

    The tiling mode.

    localMatrix

    optional, 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

    center

    The coordinates of the center of the sweep.

    colors

    The array colors to be distributed between the center and edge of the circle.

    colorPos

    The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

    mode

    The tiling mode.

    startAngle

    The start of the angular range.

    endAngle

    The end of the angular range.

    localMatrix

    optional, 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

    start

    The coordinates for the starting point.

    startRadius

    The radius at the starting point.

    end

    The coordinates for the end point.

    endRadius

    The radius at the end point.

    colors

    The array colors to be distributed between the center and edge of the circle.

    colorPos

    The positions (in the range of 0..1) of each corresponding color, or null to evenly distribute the colors.

    mode

    The radius at the end point.

    localMatrix

    optional, 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) -> Shader

    Parameters

    baseFrequencyX

    The frequency in the x-direction in the range of 0..1.

    baseFrequencyY

    The frequency in the y-direction in the range of 0..1.

    numOctaves

    he number of octaves, usually fairly small.

    seed

    The randomization seed.

    tileSize

    The 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) -> Shader

    Parameters

    baseFrequencyX

    The frequency in the x-direction in the range of 0..1.

    baseFrequencyY

    The frequency in the y-direction in the range of 0..1.

    numOctaves

    he number of octaves, usually fairly small.

    seed

    The randomization seed.

    tileSize

    The 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) -> Shader

    Parameters

    with

    The colors from this shader are seen as the source by the blend mode.

    blend

    The blend mode that combines the two shaders.

    Return Value

    a new shader that composes the current shader with the provided one