Search Unity

Terrain Splat Map limits? Really need answers

Discussion in 'Editor & General Support' started by oblivionfeet, Jul 24, 2010.

  1. oblivionfeet

    oblivionfeet

    Joined:
    Jul 24, 2010
    Posts:
    481
    Ok I have searched everywhere, finding nothing but posts wanting bump maps etc and so on for terrains, which isn't what I'm wanting, or at this stage even care about, and this is now my last resort, having to ask for help, which I hate doing.

    When painting a terrain, how many textures can be used? Am I limited to just four repeating textures? Example: Beach, Grass, Cliff, Mud. Across the entire terrain?

    I've seen conflicting and as yet zero useful reports that one minute the terrain can have as many textures as you like, the next it's limited to only four of them.

    Which is it?

    The terrain texture editor part of Unity allows you to bring in what appears to be any amount of textures to paint on the terrain. Yet things seem to bug (can no longer click at all to paint) if I have more than four textures. Even though it let me paint them on until I moved onto something else, then wouldn't let me edit the terrain at all after I came back to it.

    I'm completely confused and considering scrapping any use of the built in terrain whatsoever if it really is that limiting. If this is true, is there a way around it? Four textures across an entire terrain really doesn't sound right to me, not when you see so many claiming to be making huge seamless MMO type games. Surely they can't be doing it all in just four textures? I don't even want to do anything that big, yet four textures on a terrain is far too limiting even then.

    I know in Oblivion etc. there's a limit on the number of terrain textures which can be blended next to each other, but not across the whole terrain, and Unity appears to do it's terrain textures differently, so I'm really not following, and as I say, I've had NO luck finding any useful information out there.

    I really need some real answers to this because it's driving me insane.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Both. Each splatmap can only have 4 textures (controlled by rgba channels), but you can have any number of splatmaps. Each one you add slows it down more though.

    --Eric
     
  3. oblivionfeet

    oblivionfeet

    Joined:
    Jul 24, 2010
    Posts:
    481
    Thanks for the quick reply! :)

    Ok, so how do they all work together? I'm unable to change their order, delete them, export them. Once I've clicked off the terrain (on purpose or by accident) I can no longer go back and paint anything at all either, when using more than four textures, And the second I use more than four textures on the terrain I can no longer click to select objects in the display and can only select them in the menu (and can't transform or rotate etc in the display either).
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You delete them by clicking "edit textures" and selecting "remove texture". (Which is also how you can change the order.) I'm not sure why you need to export them; they already exist in your project.

    That's very strange; haven't heard of anything like that happening before.

    --Eric
     
  5. oblivionfeet

    oblivionfeet

    Joined:
    Jul 24, 2010
    Posts:
    481
    nonono not the textures, the splatmaps, can't seem to do anything with those short of deleting the entire terrain and starting from scratch. removing textures seemed to just crash everything when using more than four, and the splatmap went bright red and refused to update or go away

    as for the weird bug thing, it seems to be linked to lightmaps, the second I make a lightmap, bing! can't do nothing, can't paint textures, can't edit the height map (though it did once do it but I couldn't see what it was doing unless I reloaded the scene).

    sorry if im sounding ratty but im insanely frustrated and been suffering with this for months :(
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sounds like you should file a bug report.

    --Eric
     
  7. oblivionfeet

    oblivionfeet

    Joined:
    Jul 24, 2010
    Posts:
    481
    This is only version 2.6.1, not v3, doubt they'd have the time or resources to fix an issue in some old version. This no response bug thing is new though, only started happening this afternoon. Best guess is it started about the same time I downloaded and installed the external lightmapping package, though removing that had no effect, still happens. Reinstalling and hoping this fixes it, if not I'm f***ed. :-(


    Edit: Well sh*t, reinstalling also likes to delete ALL packages in the folder too, there goes everything I've collected over the past year. Wow, in one day Unity has gone from awesome to a bigger pain than my ex.

    Oh and the bug is still there. Do any kind of light map and bam, gotta restart it to be able to see anything you edit, can't even see the blue brush till you do.
     
  8. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
  9. oblivionfeet

    oblivionfeet

    Joined:
    Jul 24, 2010
    Posts:
    481
    OMG, that worked! I love you man! lol!

    I'd still love to find out why it's started doing it suddenly, been through everything and can't work out the problem (and annoyed cause I only originally wanted to ask about number of textures used on a terrain then this appeared and pushed me over the edge, lol).

    Thank you soooooooooooo much!



    Edit: Thanks to a backup, I got most of the packages back and some all important scripts too, who knew MS would be awesome enough to make their backup format work with Virtualbox lol.


    Sorry all for being all frustrated short and annoyed, it was the normal mapped straw that broke the camels back so to speak.
     
  10. Antitheory

    Antitheory

    Joined:
    Nov 14, 2010
    Posts:
    549
    There could be plenty of reasons. Anyways you can export them to a file if you want by using the terrain.terrainData.GetAlphaMaps() method. It will give you a float[,,].

    From there you will have to write your own class to convert the float data to byte-data. If you have three Alphamaps (for three textures) you could write an RGB .RAW file by writing the bytes in sequential order R,G,B, R,G,B, R,G,B, etc.

    If you have photoshop or another good image program you should be able to open up your file, edit it, and import it back into unity using the reverse of what you did above.

    It's kind of a lot of work... I wrote a mapper (with inspiration from Tom's Terrain Tools) to achieve the RGB image -> Alphamaps. I haven't bothered to go the other way around because I wouldn't want to bother using Unity's IDE for splatmapping. (or really anything to do with terrain).
     
  11. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    OK, this is a slight necro post... but I wanted to add the code below for anyone who needed to overwrite the terrain splat map texture directly.

    First you need to save this as a .js file and attach it as a component to your terrain gameobject. Then supply a texture file to the 'colorkey' input, and press the 'update now' checkbox. IT'll traverse your texture pixels and write them to your terraindata file. note, that this doesn't check for texture size discrepencies, so make sure that your colorkey texture is the same dimension as specified by your 'Control Texture Resolution' under Terrain/resolution.

    Also, this assumes you only have 1 splatmap, and that you have already added 4 terrain textures to your terrain (for the RGBA values of the texture).

    Anyway, I needed this functionality quick for a small project I'm working on and was frustrated that I couldn't just pass in the texture2D data directly(!!!). This will get around that for you. Hope it's helpful to someone!



    Code (csharp):
    1.  
    2.  
    3. @script ExecuteInEditMode()
    4.  
    5. var updateNow : boolean = false;
    6. var colorkey : Texture2D;
    7.  
    8. function Update(){
    9.         if (updateNow){
    10.                 updateNow = false;
    11.                 UpdateSplatMap();
    12.         }
    13. }
    14.  
    15. function UpdateSplatMap(){
    16.  
    17.     var TD = this.gameObject.GetComponent(TerrainCollider).terrainData;
    18.     var pixels : Color[] = colorkey.GetPixels(0,0,colorkey.width,colorkey.height,0);
    19.     var map: float[,,] = new float[TD.alphamapWidth, TD.alphamapHeight, 4];
    20.    
    21.     var pixNum : int = 0;
    22.     for(var xs : int = 0; xs < colorkey.width; xs++){
    23.     for(var ys : int = 0; ys < colorkey.height; ys++){
    24.  
    25.         map[xs,ys,0] = pixels[pixNum].r; //r
    26.         map[xs,ys,1] = pixels[pixNum].g; //g
    27.         map[xs,ys,2] = pixels[pixNum].b; //b
    28.         map[xs,ys,3] = pixels[pixNum].a; //a
    29.        
    30.         pixNum += 1;
    31.     }
    32.     }
    33.  
    34.     TD.SetAlphamaps(0,0,map);
    35. }