Coloring the Tiles
This section covers how to color the tiles.
Solid Tile Color
To give a solid color to each tile, you can use the Color
property on the tile structure.
1. Computing the Color for each Tile
The following code shows an example of how to assign a color to the tiles. This is a simple example and the rules for the color can be as specific as you want.
BlueprintsC++
// Iterates over all tiles.
for (FHexaTile& Tile : Tiles)
{
// Gets how much the tile is extruded. A higher number means a higher tile.
const float Height = Tile.Height();
// If the height is <= 0.f, we set its color to blue to represent water.
if (Height <= 0.f)
{
Tile.Color = FLinearColor(0.055f, 0.53f, 0.8f); // Blue for water.
}
// If the tile is a ground tile.
else
{
// Mixes the color based on the height to have a nice gradient.
// The mix value called Alpha is Height / 100.f.
// When Alpha ~= 0.f, the tile is green. It becomes more red as it
// approaches 1.f and finally turns to white as it approaches 2.f.
Tile.Color = FHexaSphereUtils::MixColorsManyLinear
(
FLinearColor(0.2f, 1.f, 0.2f), // Green for grass.
FLinearColor(1.f, 0.8f, 1.f), // Red-ish for mountains.
FLinearColor::White, // White for high mountains for snow.
// Above colors are mixed based on the following value.
// Can be modified to change the height of grass, mountain, etc.
// Note that it depends on the radius of the planet.
Height / 100.f
);
}
}

2. Pass the Color Data to the Mesh
When you generate the mesh data, make sure to also pass the vertex color data.
BlueprintsC++
#include "ProceduralMeshComponent.h"
#include "HexaSphere/HexaSphereLib.h"
#include "HexaSphere/HexaTile.h"
// ...
TArray<FVector> Vertices;
TArray<int32> Faces;
TArray<FColor> Colors;
TArray<FVector> Normals;
TArray<FProcMeshTangent> Tangents;
TArray<FVector2D> UV0;
FHexaSphereLib::TilesToMesh(Tiles, Vertices, Faces, Colors, true);
ProceduralMesh->CreateMeshSection(0, Vertices, Faces, Normals, UV0, Colors, Tangents, false);

3. Assign a Material
The last step is to assign a material that uses the vertex color data. You can use the material named MAT_VertexColor
.
BlueprintsC++
// C++ example code not available yet.

The code of MAT_VertexColor
can be found below:

You should now have a coloring similar to what is shown in the image below:
