- Home /
Unity Terrain Texture Swap...how to?
Hi 3 scenarios:
I have one texture, a map covering whole terrain-no tiling. Can I by script swap that entire texture for another also with no tiling? How would I do that?
say I am using 3 or four splatmaps, can I swap one of these out for another texture at runtime also? so ingame I can swap out grass for dirt for example?
can you use a greyscale mask to define where certain splatmaps are painted?
Many thanks AC
Answer by dex · May 30, 2012 at 06:17 PM
I am currently using the following function, but it does not seem efficient enough, so i am also looking for a better solution.
// Load specified texture and only that texture in given terrain
void LoadTerrain(TerrainData terrain_data, int texture_level) {
float[, ,] alphas = terrain_data.GetAlphamaps(0, 0, terrain_data.alphamapWidth, terrain_data.alphamapHeight);
// make sure every grid on the terrain is modified
for (int i = 0; i < terrain_data.alphamapWidth; i++) {
for (int j = 0; j < terrain_data.alphamapHeight; j++) {
// make sure only set layer is visible
for (int k = 0; k < terrain_data.alphamapLayers; k++) {
if (k == texture_level) {
alphas[i, j, k] = 1;
} else {
alphas[i, j, k] = 0;
}
}
}
}
// apply the new alpha
terrain_data.SetAlphamaps(0, 0, alphas);
}
Answer by ScroodgeM · Jul 19, 2012 at 06:11 PM
a little upgraded script that allows to change texture without full repainting, e.g. it saves paint map and changes texture.