trying to do a simple:
- add up generated noise layers
- apply to heightmap
- add a texture to the terrain per noise layer
- (fail) use each noise layer as splat maps (alphaMaps),
i even write to texture per 4 noise layers, thinking i could, like in the past, just assign a RGBA Texture2D to the terrain splatmap
code:
for (int i = 0; i < terrainCount; i++)
{
for (int j = 0; j < terrains[i].terrainData.alphamapTextureCount; j++)
{
int splatindex = j;
if(splatCount > terrainCount)
splatindex = j + (i * terrainCount);
var splatMap = splatMaps[splatindex];
Color[] pix = splatMap.GetPixels();
float[,,] AMaps = new float[splatMap.width, splatMap.height, terrains[i].terrainData.terrainLayers.Length];
for (int k = 0; k < splatMap.width; k++)
{
for (int l = 0; l < splatMap.height; l++)
{
Vector4 pixColor = pix[l + (k * splatMap.width)];
for (int n = 0; n < 4; n++)
{
AMaps[k, l, n] += pixColor[n]/4;
}
}
}
terrains[i].terrainData.SetAlphamaps(0, 0, AMaps);
terrains[i].Flush();
}
}
I dont understand how we are suppose to iterate through the Alphamaps if a terrain has more then one.
if i use Terrain tools to extract the splatmaps after running this code, the first on looks good, second just black… (btw i set 8 textures before so have 2 splats / terrain)
In the code i try to sample the color from the generated splatmaps and assign to the mysterious AlphaMaps.
as the docs say the 3rd element:
“corresponds to the number of splatmap textures.”
or
“while the third denotes the splatmap texture to which the alphamap is applied.”
but as it turns out, it looks more like the 3rd param represents the splatmap channels thats being written too…
anyway either i dont get how to write to channels or how to write to more then 1 splatmap on a terrain.