Search Unity

Texture Terrain At Run Time

Discussion in 'Scripting' started by mumbot, Mar 30, 2015.

  1. mumbot

    mumbot

    Joined:
    Oct 19, 2012
    Posts:
    86
    Hey all unity3D members for a while now iv been messing around with Terrain API features iv made a script that randomly generates hills on a terrain befor the map starts making the map always random when you go into it now the problem im having is how can i texture the terrain if lets say a hill is at a specified height can i only apply a rock texture to it and everything else will be grass iv spent 4 hours trying to figure this out and 2 hours looking at forums but nothing is helping me so please can anyone help me.

    Thanks.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    TerrainData and SplatMaps.

    Terrain uses a separate layer in the splat map for each texture. By modifying the array you can choose which texture to display
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Fair warning: changes to TerrainData are permanent. Do so at your own risk. And not on hand crafted terrains.
     
  4. mumbot

    mumbot

    Joined:
    Oct 19, 2012
    Posts:
    86
    Sorry iv been looking it up but i dont quite understand how its ment to automaticly apply texture to a hill thats been randomly generated could you please give me an example of how to do it? because isnt a splat map just an image of red,blue,black,green and the textures in a shader specify what textures are filled in with that?
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yup. Simply grab the splat map with TerrainData.GetAlphamaps. The third dimension of the array is the texture you are using. Set it to one at the position you want. Then reassign it with SetAlphamaps.

    Understood?
     
  6. mumbot

    mumbot

    Joined:
    Oct 19, 2012
    Posts:
    86
    Sorry im still a little confused how is it meant to texture based on the current hills on the terrain if the texture is deffined where to be placed on the splat map?
     
  7. Brominion

    Brominion

    Joined:
    Sep 30, 2012
    Posts:
    48
    (fair warning: i have not played with this in unity5 yet)
    The splat map color values are used to indicate how the terrain textures are blended onto the terrain.
    To try this out add 3 terrain textures (say sand, grass, hill) in the editor as if you where going to hand paint the terrain.
    Then instead use your script to grab the splat map and assign the weights of the different textures based on the height of your terrain. (or perhaps use an over obvious test pattern to ensure its working before basing it on your heightmap)
     
  8. mumbot

    mumbot

    Joined:
    Oct 19, 2012
    Posts:
    86
    Ah ok thanks ill give this a shot soon :)