# Implement cloud shadows using perlin noise

How could I implement some kind of rectangular texture that acts like moving cloud shadows?

I read that unity has a built-in Mathf.PerlinNoise but I couldn’t understand what exactly it does from the documentation.

Thank you!

In case you’re unfamiliar:

Perlin noise is a gradient noise calculated with a certain method. Gradient noise basically means that sequential values are all “close to” each other. The PerlinNoise function in Unity generates 2D noise, so it can be represented on a plane, like in the picture in the manual:

In this representation of Perlin noise, each pixel represents an output value, which is somewhere between 0.0 and 1.0. The outputs are shown by using different shades of grey. As you move in any direction across the output plane, the values change smoothly. This is why a visual representation like this one looks blurry.

To use it in Unity, we just do something like

float perlinOutput = Mathf.PerlinNoise(x, y);

Then, some value between 0 and 1 will be in `perlinOutput`. We process it and store it somewhere, then repeat as we iterate through x and y. This is what the example in the docs is doing.

I imagine a way to make cloud shadows with this is to generate a texture like the one above by sampling across limits in X and Y and creating an alpha map from the outputs. Applying it to the terrain and moving it slowly would make it look sort of like cloud shadows.

Texture generation is a pretty typical use for gradient noise. It’s also commonly used for terrain generation.

Perlin noise uses an array of vectors as the basis of calculation in its algorithm, and they are always the same in Unity, so sampling the same values always gives the same outputs. If you want a new pattern, you can just sample at a different range of values in x and y.

If you want to try using Perlin noise to generate things, you should be come more familiar with processing methods. Visit the following links to get a better idea of how to use it.