x


Unity Terrain Texture Swap...how to?

Hi 3 scenarios:

  1. 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?

  2. 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?

  3. can you use a greyscale mask to define where certain splatmaps are painted?

Many thanks AC

more ▼

asked May 29 '10 at 03:44 AM

AaronC gravatar image

AaronC
76 13 15 20

(comments are locked)
10|3000 characters needed characters left

3 answers: sort newest

http://answers.unity3d.com/questions/285816/change-terrain-texture-and-tree-at-runtime.html#answer-285924

a little upgraded script that allows to change texture without full repainting, e.g. it saves paint map and changes texture.

more ▼

answered Jul 19 '12 at 06:11 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

(comments are locked)
10|3000 characters needed characters left

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);
}
more ▼

answered May 30 '12 at 06:17 PM

dex gravatar image

dex
4 1 1 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1472
x65
x51
x48
x9

asked: May 29 '10 at 03:44 AM

Seen: 2286 times

Last Updated: Jul 19 '12 at 06:11 PM