# Generation module

Generation module (UGenerationModule) is the abstract base class for the noise modules.

A generation module is an object that calculates and outputs a value given a three-dimensional input value.

Each type of generation module uses a specific method to calculate an output value. Some of these methods include:

Calculating a value using a coherent-noise function or some other mathematical function.

Mathematically changing the output value from another noise module in various ways.

Combining the output values from two noise modules in various ways.

The generation modules can be combined with other generation modules to generate complex output values. Each one of the generation modules may be connected to other generation modules, and so on.

There is no limit to the number of generation modules that can be connected together this way. However, each connected generation module increases the time required to calculate an output value.

Note: output values are between -1 and 1. Get values functions clamp the output value in this range.

## Get values

Once your generation module created (from a generator, of a combination of modifier,…) you can get values to use them in your project.

### 1. GetValue

The get value function is the easiest : it returns a floating value between -1 and 1 when you pass a GenerationModule and a Vector as parameter.

You can either pass a vector with X, Y and Z component if you want to use your noise as a 3D noise. Or just use 2 components : X, Y and set Z as 0, using this way, your noise is a 2D noise.

Note: it’s better to use coordinates between 0 and 1. Check the example project to see how our blueprints are done.

### 2. GetPlaneNoiseMap

If you want to use your noise as a 2D noise, a function is all designed : the GetPlaneNoiseMap. This function returns an array containing all the floating values of the noise. The output array has only 1 dimension. So to determine array index based on the X and Y coordinates, you must use : Index = Y*SizeX + X

This function needs as input :

Generation module containing the noise

SizeX which will determinate the output array size.

SizeY which will determinate the output array size.

BoundMinX used to select the X part of the noise to use.

BoundMaxX used to select the X part of the noise to use.

BoundMinY used to select the Y part of the noise to use.

BoundMaxY used to select the Y part of the noise to use.

Tileable? If checked, your noise is seamless and can be tiled.

Bounds determine the part of the noise to use. Bounds between 0 and 1 are a good option. If you need an other “tile”, you can then use bounds between 1 and 2. Because of the coherent noise, your two tiles are seamless!

### 3. GetNormalMap

If you want to get the normal vector on each point of the noise, you can use the GetNormalMap funnction. This function returns an array containing Vectors which are the normals of the noise. The output array has only 1 dimension. So to determine array index based on the X and Y coordinates, you must use : Index = Y*SizeX + X

This function needs as input :

Generation module containing the noise

SizeX which will determinate the output array size.

SizeY which will determinate the output array size.

BoundMinX used to select the X part of the noise to use.

BoundMaxX used to select the X part of the noise to use.

BoundMinY used to select the Y part of the noise to use.

BoundMaxY used to select the Y part of the noise to use.

Tileable? If checked, your noise is seamless and can be tiled.

Bounds determine the part of the noise to use. Bounds between 0 and 1 are a good option. If you need an other “tile”, you can then use bounds between 1 and 2. Because of the coherent noise, your two tiles are seamless!

Creating your own noise modules

In order to create your own noise, create a new class that publicly derives from UGenerationModule.

Override the GetValue function

float GetValue(const FVector& Coordinates) const;

This function must output a value between -1 and 1 based on the input coordinates. If this function returns the same output for two inputs with the same value, your noise is coherent.

Example of coherent get value:

float GetValue(const FVector& Coordinates) const

{

return Coordinates.X & 1 ^ Coordinates.Y & 1 ^ Coordinates.Z & 1 ? -1.0 : 1.0;

}

Example of non-coherent get value:

float GetValue(const FVector& Coordinates) const

{

return FMath::Rand();

}

You must also create a static initializer for your new noise. This static initializer must be a blueprint UFUNCTION and return a pointer to the UGenerationModule class.