GKNoise
A representation of procedural noise, generated by a noise source, that you can use to process, transform, or combine noise.
Declaration
class GKNoiseOverview
Using procedural noise requires three steps:
Select the GKNoiseSource subclass that generates the style of noise you’d like, and configure its properties to customize the noise generation algorithm.
Create a GKNoise object from that noise source. A noise source generates a field of floating-point noise values between
-1.0and1.0across an infinite, three-dimensional domain—a noise object represents this field. Using GKNoise methods you can process the values in the noise field or combine values from multiple noise fields.Create a GKNoiseMap object from the noise object. A noise map samples values from a finite, two-dimensional slice of the noise field to create a concrete output. You can then read those values directly, use the SKTexture class to generate texture images, or use the
SKTileMapclass to generate tile maps.
GKNoise objects are lightweight. Because each noise object represents only a specific configuration of noise generation and processing steps, there’s little computation cost to creating noise objects from noise sources and applying operations to process, transform, or combine them. After you create noise objects and apply operations, creating a GKNoiseMap object from the resulting noise object performs only the computation needed to generate final output.
Colorizing and Combining Noise
A noise object doesn’t contain noise values or pixel color values for the noise field it describes. However, because you can combine multiple noise objects before producing colorized textures from the result, the gradientColors property specifies the colors that the SKTexture class uses to colorize output. For example, you can generate a realistic terrain texture by creating several styles of noise representing different biomes such as water, grassland, forests and mountains, each with their own color gradient, then combining them with the init(componentNoises:selectionNoise:) method. The selectionNoise parameter to that method determines which biomes shows through in which regions of the final output, and each retains its own color gradient.
Topics
Creating Noise
Creating Noise by Combining Noise
init(componentNoises:selectionNoise:)init(componentNoises:selectionNoise:componentBoundaries:boundaryBlendDistances:)
Colorizing Noise
Applying Operations to Noise Values
applyAbsoluteValue()invert()raiseToPower(_:)clamp(lowerBound:upperBound:)remapValues(toCurveWithControlPoints:)remapValues(toTerracesWithPeaks:terracesInverted:)