S
S
Stanislav Chernomorchenko2014-12-15 19:28:14
Unity
Stanislav Chernomorchenko, 2014-12-15 19:28:14

How to modify the Terrain texture in Unity3D using scripts?

The crux of the matter is as follows. I'm interested in how to write my own script so that when you click on the Terrain, the texture of the selected area changes. Simple drawing I would say. From the information that I reviewed, I realized that you need to use TerrainData and splatPrototype directly. But I can't figure out how to put it all together. Who faced such task? If there are code examples I will be grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Silin, 2014-12-16
@aroksetxua

The easiest correct way:
You need to take certain pixels from the texture (GetPixels), paint them with the desired color, then apply these changes to the terrain texture (SetPixels, Flush). Which pixels to take can be determined via raycast. The disadvantage of this method is that it is rather difficult to obtain high-quality, smooth changes.
quality way:
In addition to the terrain texture, we also need a splat texture and a shader that will work with it. We make the second texture smaller than the original one and repeat everything as in the first method, but with it. Since it is smaller when applied, it will be stretched and a smooth transition will be obtained. The shader itself looks at the second texture and, where necessary, adds another texture or color to the terrain texture, as you like.
Now not the correct high-quality and simple way:
We take a bunch of projector-tors and place them where necessary on the terrain.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question