Class PixelNoise
Generates random per-pixel noise similar to Photoshop's "Add Noise" filter. Supports Uniform and Gaussian distributions, monochromatic and color modes. Provides both RNG-based (sequential) and hash-based (coordinate-addressable) evaluation paths.
Inherited Members
Namespace: Scylla.Core.Util.Noise
Assembly: ScyllaCore.dll
Syntax
public static class PixelNoise
Remarks
Unlike coherent noise algorithms (OpenSimplex2, Perlin, Value, etc.) which produce spatially correlated patterns with smooth gradients, pixel noise generates statistically independent random values at each pixel. Neighboring pixels share no spatial correlation, which is the defining characteristic of this technique. Common uses include film grain, texture roughening, dithering, aging, and photographic noise simulation.
Two API styles are provided:
-
RNG-based (
Fill(Color32[], PixelNoiseSettings, IRandomSource)etc.): Consumes sequential values from an IRandomSource. Best for generating noise once - for example, baking a texture at application startup - where reproducibility is not required across runs. -
Hash-based (
Fill(Color32[], int, int, long, PixelNoiseSettings)etc.): Uses a seed and pixel (x, y) coordinates to produce deterministic, random-access values via HashToFloat(long, int, int). Best for procedural textures where any pixel can be re-evaluated in isolation, or where the same seed must always produce identical output.
Gaussian distribution is approximated using an Irwin-Hall sum of four uniform [-1, 1]
hashes scaled to unit standard deviation. In hash mode, four independently seeded hashes
of the same pixel coordinates are averaged; in RNG mode, NextGaussian
is used directly.
All output pixels are centered on mid-gray (128/255 = 0.5 in float, 128 in Color32).
Alpha channels are never modified by any method in this class.
All methods are allocation-free after the output array is provided by the caller.
Methods
Apply(Color32[], PixelNoiseSettings, IRandomSource)
Applies additive RNG-based pixel noise to an existing UnityEngine.Color32 array, modifying each pixel's R, G, and B channels in place by adding a noise offset to the existing channel value. The result is clamped to [0, 255]. Alpha channels are preserved unchanged. When Amount is zero or negative, the array is not modified.
Declaration
public static void Apply(Color32[] pixels, PixelNoiseSettings settings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32[] | pixels | The pixel array to modify in place. Must not be |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
| IRandomSource | rng | The random source that provides sequential noise samples. Must not be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Apply(Color32[], int, int, long, PixelNoiseSettings)
Applies additive hash-based pixel noise to an existing UnityEngine.Color32 array, modifying each pixel's R, G, and B channels in place. The noise offset for each pixel is derived from its (column, row) coordinate and the provided seed, producing the same noise pattern every time for the same inputs. The result is clamped to [0, 255]. Alpha channels are preserved unchanged. When Amount is zero or negative, the array is not modified.
Declaration
public static void Apply(Color32[] pixels, int width, int height, long seed, PixelNoiseSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32[] | pixels | The pixel array to modify in place. Must have at least |
| int | width | The number of pixel columns. Must be at least 1. |
| int | height | The number of pixel rows. Must be at least 1. |
| long | seed | The seed for deterministic noise generation. |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
Apply(Color[], PixelNoiseSettings, IRandomSource)
Applies additive RNG-based pixel noise to an existing UnityEngine.Color array, modifying each pixel's R, G, and B channels in place by adding a noise offset to the existing channel value. The result is clamped to [0, 1]. Alpha channels are preserved unchanged. When Amount is zero or negative, the array is not modified.
Declaration
public static void Apply(Color[] pixels, PixelNoiseSettings settings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| Color[] | pixels | The pixel array to modify in place. Must not be |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
| IRandomSource | rng | The random source that provides sequential noise samples. Must not be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Apply(Color[], int, int, long, PixelNoiseSettings)
Applies additive hash-based pixel noise to an existing UnityEngine.Color array, modifying each pixel's R, G, and B channels in place. The noise offset for each pixel is derived from its (column, row) coordinate and the provided seed, producing the same noise pattern every time for the same inputs. The result is clamped to [0, 1]. Alpha channels are preserved unchanged. When Amount is zero or negative, the array is not modified.
Declaration
public static void Apply(Color[] pixels, int width, int height, long seed, PixelNoiseSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| Color[] | pixels | The pixel array to modify in place. Must have at least |
| int | width | The number of pixel columns. Must be at least 1. |
| int | height | The number of pixel rows. Must be at least 1. |
| long | seed | The seed for deterministic noise generation. |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
Evaluate(long, int, int, PixelNoiseSettings)
Evaluates hash-based pixel noise for a single pixel at the given integer coordinates,
returning a mid-gray-centered noisy UnityEngine.Color32 value. The result is fully
deterministic: the same seed, x, y,
and settings always produce the same output. This method is useful
for coordinate-addressable noise where any pixel can be evaluated independently, without
iterating over the full array.
Declaration
public static Color32 Evaluate(long seed, int x, int y, PixelNoiseSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| long | seed | The seed for deterministic noise generation. |
| int | x | The X coordinate of the pixel in the virtual noise grid. |
| int | y | The Y coordinate of the pixel in the virtual noise grid. |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode.
When Monochromatic is |
Returns
| Type | Description |
|---|---|
| Color32 | A noisy UnityEngine.Color32 centered on mid-gray (128, 128, 128). Alpha is always 255. When Amount is zero or negative, returns neutral mid-gray (128, 128, 128, 255) with no noise applied. |
Fill(Color32[], PixelNoiseSettings, IRandomSource)
Fills a UnityEngine.Color32 array with RNG-based pixel noise, writing mid-gray-centered noise values to every element. Each pixel is written as (r, g, b, 255) where the channel values are 128 plus the noise offset, clamped to [0, 255]. When Amount is zero or negative, all pixels are set to neutral mid-gray (128, 128, 128, 255) with no noise.
Declaration
public static void Fill(Color32[] output, PixelNoiseSettings settings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32[] | output | The output array to fill. Every element is overwritten. Must not be |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
| IRandomSource | rng | The random source that provides sequential noise samples. Must not be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Fill(Color32[], int, int, long, PixelNoiseSettings)
Fills a UnityEngine.Color32 array with hash-based pixel noise, using each pixel's (column, row) coordinates as the hash inputs. The output is fully deterministic: the same seed and settings always produce the same result. Pixels are written in row-major order starting at index 0. Each pixel is a mid-gray-centered noise value (128, 128, 128) with the noise offset applied. Alpha is always 255. When Amount is zero or negative, all pixels are set to neutral mid-gray with no noise.
Declaration
public static void Fill(Color32[] output, int width, int height, long seed, PixelNoiseSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| Color32[] | output | The output array to fill. Must have at least |
| int | width | The number of pixel columns. Must be at least 1. |
| int | height | The number of pixel rows. Must be at least 1. |
| long | seed | The seed for deterministic noise generation. |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |
Fill(Color[], PixelNoiseSettings, IRandomSource)
Fills a UnityEngine.Color array with RNG-based pixel noise, writing mid-gray-centered noise values to every element. Each pixel is written as (r, g, b, 1) where the channel values are 0.5 plus the noise offset, clamped to [0, 1]. When Amount is zero or negative, all pixels are set to neutral mid-gray (0.5, 0.5, 0.5, 1) with no noise.
Declaration
public static void Fill(Color[] output, PixelNoiseSettings settings, IRandomSource rng)
Parameters
| Type | Name | Description |
|---|---|---|
| Color[] | output | The output array to fill. Every element is overwritten. Must not be |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
| IRandomSource | rng | The random source that provides sequential noise samples. Must not be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Fill(Color[], int, int, long, PixelNoiseSettings)
Fills a UnityEngine.Color array with hash-based pixel noise, using each pixel's (column, row) coordinates as the hash inputs. The output is fully deterministic: the same seed and settings always produce the same result. Pixels are written in row-major order starting at index 0. Each pixel is a mid-gray-centered noise value (0.5, 0.5, 0.5) with the noise offset applied. Alpha is always 1. When Amount is zero or negative, all pixels are set to neutral mid-gray with no noise.
Declaration
public static void Fill(Color[] output, int width, int height, long seed, PixelNoiseSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| Color[] | output | The output array to fill. Must have at least |
| int | width | The number of pixel columns. Must be at least 1. |
| int | height | The number of pixel rows. Must be at least 1. |
| long | seed | The seed for deterministic noise generation. |
| PixelNoiseSettings | settings | The pixel noise configuration controlling intensity, distribution, and channel mode. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
| ArgumentException | Thrown if |
| ArgumentOutOfRangeException | Thrown if |