A representation of procedural noise, generated by a noise source, that you can use to process, transform, or combine noise.
- iOS 10.0+
- macOS 10.12+
- Mac Catalyst 13.0+
- tvOS 10.0+
Using procedural noise requires three steps:
GKNoisesubclass that generates the style of noise you’d like, and configure its properties to customize the noise generation algorithm.
GKNoiseobject from that noise source. A noise source generates a field of floating-point noise values between
1across an infinite, three-dimensional domain—a noise object represents this field. Using
GKNoisemethods you can process the values in the noise field or combine values from multiple noise fields.
GKNoiseobject 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
SKTextureclass to generate texture images, or use the
SKTileclass 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
GKNoise 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
gradient 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(component 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.