- Home /
SetAlphaMaps Opacity Gradient
Hello guys,
in my actual project I can place an object on my terrain and the alpha map under the object chances to another texture. The problem is, that there is no smooth transition between the two textures, like if you brush the terrain with the given tools.
My question is: How can I get a opacity gradient to the new painted texture? Similiar to the falloff you can see in brushes.
Below you can see the code:
public void PaintTexture(int terrainLayers)
{
terrain = hit.transform.GetComponent<Terrain>();
int mapMaxX = Convert.ToInt32(buildingToBuild.grundriss.x);
int mapMaxZ = Convert.ToInt32(buildingToBuild.grundriss.z);
float[,,] map = new float[mapMaxX, mapMaxZ, terrainLayers];
// For each point on the alphamap...
for (int y = 0; y < mapMaxZ; y++)
{
for (int x = 0; x < mapMaxX; x++)
{
map[x, y, 3] = (float)(1);
}
}
int mapX = (int)(((hit.point.x - 6 - terrain.transform.position.x) / tData.size.x) * tData.alphamapWidth);
int mapY = (int)(((hit.point.z - 6 - terrain.transform.position.z) / tData.size.z) * tData.alphamapHeight);
tData.SetAlphamaps(mapX, mapY, map);
}
And a picture of the actual result:
Your answer
Follow this Question
Related Questions
C#: Changing Terrain Textures 0 Answers
terrainData.heightmapTexture float value range 2 Answers
Distribute terrain in zones 3 Answers
Why does my .raw heightmap create ugly errors when loaded into a terrain? 1 Answer
How to generate multiple Terrain objects with different TerrainData and Splat Texture via C# script? 1 Answer