Is there a way to save terrain texturing to be applied later? I’m using terrain tools to proceduraly generate textures. And terrain mapper to generate trees based on the textures. I’m still working on getting all of that right. But there are some textures that need to be applied and stay that way. I general trace buildings, roads, parking lots etc. with a specific texture. I want to be able to texture those areas and export them. Than re-apply them after I proceduraly texture the entire terrain. How would I do that. Thanks.
You might try creating three terrains. One with your procedural textures, another with the roads and such and a third that you use to merge the changes to and use for your final terrain. This would allow you to freely apply textures to the two working terrains independently.
You can use a script to sync the actual terrain heights, and another to merge the textures.
Interesting! I can’t find anything about this on the forum. Do you have an example or a starting point for a script I can adapt? I’m familiar with c#. Thanks.
Yeah, I think I can scratch something up, I have some stuff at home that might help. I have a custom inspector that syncs height data from one terrain to another, it should be easy for you to expand on for the textures.
You’ll just have to make sure that all of your textures are the same size, resolution, etc or things will look weird…or go boom ![]()
So, you can share terrain data between terrains by just doing this:
DestinationTerrain.terrainData = SourceTerrain.terrainData;
And then update the terrain to show the changes by doing this:
DestinationTerrain.terrainData.SetHeights(0, 0, new float[,]{});
But, all that really does is share the terrain data, or link it between them. It’s really not the same as copying. It wouldn’t let you have three independant terrains. Worse, you would lose the terrain textures and such, the terrains would pretty much just be the same copies of the source terrain.
If you actually wanted to copy the height data between terrains, you would do something like this:
var sourceHeights = SourceTerrain.terrainData.GetHeights(0, 0,
SourceTerrain.terrainData.heightmapResolution,
SourceTerrain.terrainData.heightmapResolution);
DestinationTerrain.terrainData.SetHeights(0,0,sourceHeights);
DestinationTerrain.terrainData.SetHeights(0, 0, new float[,]{});
Getting the textures (or splat maps) is a little trickier. I haven’t tested this, but it should be about right:
var sourceAlphas = SourceTerrain.terrainData.GetAlphamaps(0, 0, SourceTerrain.terrainData.heightmapWidth,
SourceTerrain.terrainData.heightmapHeight);
So, if you have a terrain that is created from a heightmap that is 1024x1024. Is the terrain properties, check out the Control Texture Reslution.
The control texture resolution sets how detailed the textures are on your terrain. So if your heightmap is 1024x1024, and your control texture is 1024…that means there is a 1 to 1 ratio. I’m probably explaining this horribly. If your control texture was 512, that means that for every 1 pixel of your heightmap that control terrain height, painting a texture would take up twice the space.
Anyway, when you get the alphamaps, you get a 3d array, not 2d. The two dimensions are the height/width of your alpha map, your control texture map that controls how the textures are painted on your terrain.
The third dimension is HOW MUCH of each texture is at that position.
So, if you had two textures, grass and dirt. And you wanted half dirt at one place, and half grass. You would do something like this:
// bottom, left hand corner of the terrain
int terrainX = 0;
int terrainY = 0;
sourceAlphas[terrainY, terrainX, 0] = 0.5f; // half grass (texture 0 )
sourceAlphas[terrainY, terrainX, 1] = 0.5f; // half dirt (texture 1)
So, when you merge texture data, all of the values in the 3rd dimension have to add up to 1. If you only set 1 to .5, and leave the other at zero, you’ll get some weird terrain textures because it’s trying to blend half of one with nothing, basically.