Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Best approach to texturing huge terrains...

Discussion in 'Editor & General Support' started by jeremyace, Apr 5, 2006.

  1. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Hey guys, I am doing some tests and was wondering if anyone has any ideas for how to texture a huge terrain without pixelating.

    I have been doing tests with the multi-camera LOD trick (main cam renders the high-res stuff a short distance ahead then a secondary camera renders the low-res stuff beyond that, both cams layered on screen), but I am having a hard time figuring out how to texture this beast and have details like roads, dirt patches, etc. The ideas I have had so far (but they are all hacks) are:

    1: Break the terrain up into many (many many) small blocks and have a seperate high-res texture for each cell and use the LOD camera trick to make the actual amount of textures displayed sane and keep the computer from exploding. The problems with this are the time required to do this, and actually painting the textures without tiling, especially for roads, etc.

    2: Have a base tiling texture over the whole terrain and somehow (projector?) add textures where needed such as cliffs, mountains, roads, etc. Problems being; hard to get right, limiting, texture transitions would be a real pain, and it may not work in Unity as we don't really have decals do we?

    3: Ask here and hope someone else has an idea.

    I am really hoping someone here has better ideas?Unity really needs a proper terrain system IMO.

    Thanks a lot for any help guys,
    -Jeremy
     
  2. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    I'd love to hear other suggestions for this, but IMHO the best way to do terrains is your dreaded #1 solution.

    But it's not about breaking up the terrain into many faces, it's about breaking the terrain into many UV maps.

    A simple example for grass terrain with roads:

    1. Create a tileable grass texture that is seamless in both U and V directions.

    2 Create secondary textures for roads and other anomalies such as rocky patches that are maybe only tileable in U or V and that are seamless to your main grass texture in U or V.

    3. Spend the time to properly UV map and assign the different textures to all the faces of your terrain mesh. This is a time consuming process (not only creating all these tileable textures, but UV mapping them to the terrain), but it seems to be the method used by a lot of games.

    HTH
     
  3. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Ugh...I was afraid of that... UV mapping and Jeremy don't exactly get along very well yet (wow I refered to myself in the third-person...don't I feel smart). Also texture transitions would be hard (like road to grass) unless I do multi-layered textures which I assume could get expensive.

    I will have to find some resource or book for UV mapping in XSI... I can do basic stuff, but when it comes to subprojections, working with a huge map and such my eyes start to blur and I get dizzy...

    Hopefully there is another way to do this (doubt it), but in the mean time I will brush up on my texturing...uh...skills.

    Thanks Antenna,
    -Jeremy
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    No texture layering needed, you just need to get pumped for some serious hours tweaking, clone stamping, blending, offsetting, and color correcting images in Photoshop to work out all these seamless textures.

    I can't think of a single thing I find fun about UV mapping... except for an end result that actually looks good :wink:
     
  5. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Doesnt XSI have planar mapping? If so just center the projection on the terrain from above. This takes no time at all and you will have almost perfect uv's as long as you dont have super steep hills.

    As far as texturing goes I think it's best to use a multilayer system such as this. If you need a shader made I can whip one up if you like, or maybe richard would share his? Either way I dont think that terrains are to daunting. I think there actually really fun to make. I love the poly brush in maya, It lets me paint on the hills, which is so cool.

    Bill
     
  6. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Oh yeah, XSI has planar mapping. I was just saying that UV mapping generally scares me. I can get a texture mapped to the whole mess, but mapping the detail stuff seems a bit daunting at times as I have no real experience with UV mapping.

    Wow, very nice offer thank you. I don't want anyone to go to any trouble though as I am just doing testing to see how to get a full outdoor scene going (trees, grass the whole works). I will ask richard if he will share his, but I may take you up on your offer later on if it still stands. Thanks a lot. :)

    XSI has paint tools which I will look into more, but that is one area where I think it is pretty clear that Maya wins hands down. XSI's tools are used mainly for weight maps or Vector art.

    Thanks for the help,
    -Jeremy
     
  7. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    It's actually no trouble at all. I could do it pretty quick and it sounds like you will need it for your testing. Using a multi-texture shader actually doesnt look like it would be to slow at all. Not having to do every layer in a different pass seems to really speeds things up. I will have some extra time tomorrow at school, I have a huge gap in schedule and I will be needing some thing to do. You give the word and I'll see what I can do.

    Bill
     
  8. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Well I would love it if it's no trouble. Thanks a million Bill!

    -Jeremy
     
  9. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    No problem, I have started to really like this shader stuff. 8) Its very rewarding for some reason. Do you use AIM at all? I would like to chat some time...

    Bill
     
  10. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Thanks man. I haven't started with shader programming yet but it seems very exciting.

    I don't use AIM though, I go on the net with my PC as I have issues connecting with my Mac sometimes for some reason, I only have msn and xfire on this machine... Hmm... I don't like AIM on PC with it's spyware and such... Any other ways? Would be cool to chat. Or if I can find a hacked version of AIM with spyware removed.

    EDIT: man I can't type tonight...I have had to edit typos on most of my posts tonight

    -Jeremy
     
  11. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Well it's not hacked but the best chat app in the world is AdiumX It's free and super customizable it does aim, icq, yahoo, msn, ect. Which is totally nice since a lot of people use different stuff. Also im sure theres no spyware. But of course theres always iChat.... but it's not my fav. For PC theres middleman and another this other good one ill remember in a sec..

    Bill
     
  12. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I shall try to get something... Trillian does AIM doesn't it? In the mean time PM me your name and if all goes well I will talk to ya there...not tonight though, it is 4:45am here ;)

    TTYL,
    -Jeremy
     
  13. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    My AIM screen name is in my profile, or at the bottom of my post. (click on the yellow stick guy whos running) :wink:

    Bill
     
  14. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    ROFL...I need to get to sleep...

    TTYL,
    -Jeremy
     
  15. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    yeah Jeremy, if you get an AIM account let me know too. Sync and I have some fun late nights on chat :wink:

    I was going to mention Richard's alpha layering shader, but the thing is with any huge terrain you're still going to have to tile textures because you just can't afford to have all these huge textures that cover the entire terrain. There's just no way around this paradigm of creating tiles that you can replicate throughout you're environment to create a larger cohesive terrain... at least not until GFX cards have gigabytes of RAM to spare.
     
  16. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I got AIM...I'll pm you my name...

    Yeah I know I will still have to tile it up, but at least with a shader I don't have to do as much hand painting for 50+ cells if you know what I mean. I can have a tiling base texture and add detail tile-by-tile as I need it. Not perfect but it helps...well, we will see.

    -Jeremy
     
  17. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    He could get away with a shader like that for most things... He can tile the two coloring textures. The only limitation will be when the mask starts getting so stretched you can see the pixels being blended. But yes for HUGE things he will need tiles of this sorta thing.

    Bill
     
  18. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Ok, so here is a shader you can use to do terrains like we were talking about.

    Here is the code

    Code (csharp):
    1.  
    2. Shader "MyShaders/Terrain" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,1,1,1)
    5.         _MainTex ("Main Texture (RGB)", 2D) = "white"
    6.         _PathTex ("Path Texture (RGB)", 2D) = "white"
    7.         _PathMask ("Path Mask (Grey)", 2D) = "white"
    8.     }
    9.     SubShader {
    10.        Pass {
    11.            ZWrite On
    12.            Lighting On
    13.            Cull Back
    14.            
    15.            Material {
    16.                Diffuse [_Color]
    17.                Ambient [_Color]
    18.            }
    19.            SetTexture [_PathTex] {
    20.                combine texture
    21.            }
    22.            SetTexture [_PathMask] {
    23.                combine previous, previous-texture
    24.            }
    25.            SetTexture [_MainTex] {
    26.                combine previous lerp (previous) texture
    27.            }
    28.            SetTexture [_MainTex] {
    29.                combine previous * primary
    30.            }
    31.        }
    32.     }
    33.     FallBack " Diffuse", 1
    34. }
    35.  
    And a pic as well as the shader.
     

    Attached Files:

  19. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    984
    Great! ...and a pic is always appreciated.

    How much of a performance hit would it be to have a few of those layers, not just path, but... 3 or 4 layers all masked on top of each other? It looks like it would be dead easy to alter the shader, I suppose I should just try it. ;)

    I'm also trying to figure out the method that Warcraft III uses. It's sort of a complex tiling scheme like in a 2D game, laid down on top of the mesh, but also with several layers. I guess that must mean multi texturing using multiple UV maps in combination with a this layering method to smooth out the transitions between types.

    Just to be clear on the method talked about earlier where the mesh is broken up into multiple UV maps (which I don't actually know how to do in Maya... but I haven't looked into it either.) You'd have to make a shader with many, many textures, right? Possible 25 or more, right? The shader would have to link them to the correct UV map and you'd probably name each texture something like terrain1-1, terrain1-2, terrain1-3, terrain1-4, terrain1-5, terrain2-1, terrain2-2, etc. Is that the idea?
     
  20. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    You actaully cant I guess with unitys current shader compilation scheme you can only have 4 textures per pass max. You could add more layers in other passes but obviously the more passes makes it slower. I dont think it would be to taxing to add another pass. Jeremy also asked this. One thing to remember is we have to make another mask texture every time we want a different tillable one. I can mess around with making another pass if you like.


    Actually when you break your mesh up in maya, you will want to break it up in squares each with a different material. Each material has it's own set of uv's and once in unity each material section can have a different shader. They dont share shaders.

    So lets say he have a 4 tile terrain... What I would do is make a huge 4048x4048 mask once it's down divide it into quarters so you have 4 peices each peice is for a different tile. Divide your mesh into 4 materials in maya apply those textures. Make the terrain according to how you masked different areas. Then import the entire thing into unity. You will end up with one mesh with 4 materials each with there own masks that wont have seams.

    hope that helps.

    Bill
     
  21. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Thanks again for taking the time to do this shader.

    This shader works great. I can see the possible need for more layers, but I don't know how many would be a good number. I am thinking no more than 4 but 3 would even work (main tex and two extra layers). I dunno. I think the more layers we can get away with without killing perfomance the better. At least for terrain shaders.

    Thanks,
    -Jeremy
     
  22. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    Actually they can, and in fact it is much easier to just take a large sheet, 1024 or 2048 pixels, and divide it up into 256 or 512 pixel sectioins and put each one of your tiles into one of these sections. Then when you UV map a face, or span of faces, you UV map their coordinates into the UV section space that corresponds to that section in your image texture. Then you are using only one material with many tiles available in one texture... trust me this will save you from the headache of having dozens of materials and textures that you need to keep track of, even if you are really good with naming and organizing them all.
     
  23. guategeek_legacy

    guategeek_legacy

    Joined:
    Jun 22, 2005
    Posts:
    659
    Hey aNTeNNa trEE

    Thats exatly what I was thinking about doing and didn't know that was already a standard way of texturing an object. I have been having some truble with the UV part though. Is there any easy way to have it take each face and make a UV square for that and place these which some space in between. So that I can just grab each faces UVs and place them over the tile I want in that section? Also is there a way of making guides I can have a UV snap to in Maya? Thanx, man I feel like a noob :p Jeff
     
  24. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Yeah, that seems to be that hard part with this unless I am missing something too. In XSI there is a function called dice polygons which does a sort of subdivision on the object to break it up into a grid. That helps as a guide, but it actually adds a seam. Luckily I can remove the operation at any time without screwing my other stuff up. I am sure Maya will have something similar, but I don't know if you will be able to remove it later. It's a realy pain when you have a huge terrain.

    -Jeremy
     
  25. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,325
    I'm not sure how standard it is, but it works for me and seems to speed stuff up when I can group all textures of a certain kind into a single material. I am running into a MIP problem with this technique... the MIP will cause some undesired seams from certain distances/angles.... as the texture decreases in pixel dimensions the seams become visible... my workaround right now is to scale the UV dimensions back a very small amount.

    Well, I can't go into all the Maya tools for UV mapping... just too many to go over. I'd look at the Unitize function for selecting a bunch of faces and stretching them to the entire UV space for tiling... Unitize all the faces then scale down into the proper section of the texture. I use a lot of grid snapping in the UV editor and to be honest doing stuff by "eye". I hate formulaic mapping and prefer to line UVs up and stretch them in certain directions by eye to get some subtle variations in the tiling. If you do everything by grid it shows in the end result and just looks "computer". I'd rather have some imperfect seams here and there (that 90% of players won't notice) than have perfect tiling that looks like it was created by a robot. The human eye picks up repetition very fast and it's best to avoid it at all costs.

    So I have my own process for creating larger terrains and I'm curious to see what Jeremy or others are going to create with this layered masking technique... I honestly don't think it's going to work properly for varied terrains. I think the alpha mask can never be big enough without ugly pixelation or oversized textures, and I don't think it solves a thing with regards to variation on the terrain... you can have a tiling "road" texture over a tiling "grass" texture, but that's going to look pretty old school without any control over texture variations... I think you guys are looking for a "quick fix" to a more complicated situation.
     
  26. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Naw. Not at all. Just a time saver. If I can only use it for roads or simple little things then it's still worth it. This kind of thing is also useful for people making cartoony games and really only need 2 or 3 terrain textures anyway. (not me ;) )

    -Jeremy
     
  27. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
  28. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Man, Bill must write Unity shaders in his sleep!

    Great job on the multitexture shader, Bill! And thanks for sharing it!


    [edited to correct my idiocy]
     
  29. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    haha, this is easy man! ShaderLab looks intimidating, but it's really not. :wink:

    Also all these are pretty basic. I need a computer that has a better graphics card so I run can Cg vertex and fragment programs. Then you will be seeing some really cool shaders from me. :p

    Any one else need a shader? :D

    Bill
     
  30. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    On a kind-of-related note, does anyone know where a fellah can get his hands on some good tutorials/demos/examples of the Screen Effects and Render to Texture stuff in Pro?
     
  31. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I was hoping someone would share a shader like this. Thanks!
    Any chance of one with more than 2 texture options? Maybe you could make a variable or slider that would control how many...

    Maybe I will try my hand at shaders sometime.
     
  32. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Well _if_ there was documentation on screen affects it would be here. But it seems there is none. :?

    I wonder when that might get added.

    I thought render to texture was as simple at assigning a camera to a texture slot? We should talk, marty, IM me when/if you get on today.

    Bill
     
  33. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    I answered that earlyer. :p

    But happy to say again. With unity's current compilation scheme you can only have 4 textures a pass. I dont know why, thats just what peter said. (peter feel free to get more technical ;) ) So to do more layers they would need to be done in more passes making this shader a little slower. It's possible and if you want I could give it a try for you.

    I dont think it wouldnt be possible to make a slider to controll how many layers there are. Maybe in Cg, but I dunno.

    Bill
     
  34. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    984
    I'm a bit ignorant of making shaders, but when you say 4 textures, does that INCLUDE the mask image? So, really, the limit is already hit? Or could there be one or two more textures with their own masks? Just to be clear on it.

    Also, Yoggy, thanks for the pic. :)

    Don't you also have to then break that straightened road down into segments that sit on the texture, or does it just repeat correctly?
     
  35. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    The limit does include the mask textures. Bill said he would have to use another pass to add another layer.

    About breaking it down, you just have a tiling base texture (grass) and a tiling dirt or road texture, then one mask file that just controls what's displayed. You tweak the scale values of each texture, but the mask stays the same.

    Hope that helps,
    -Jeremy
     
  36. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Well I got three layers now, (one base 2 tiles and masks) It's not perfect but it will do. I would rather not use blending but I dont know how to lerp between a texture and a previous pass. I think you are suppose to use the "usePass" but I am not sure how...

    So here is a pic and the shader.
     

    Attached Files:

  37. marty

    marty

    Joined:
    Apr 27, 2005
    Posts:
    1,170
    Wow, this is getting better and better.

    Now, if we could just get multitextured scenes in Maya to import right into Unity.
     
  38. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I get a "syntax error at line 1" with that. with some testing it appears that it gives a "syntax error" on the first line with a "{" no matter what that is.

    is this a bug?
     
  39. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    other custom shaders seem to work fine


    oops double post. ment to be an edit.
     
  40. Sync1B

    Sync1B

    Joined:
    Sep 13, 2005
    Posts:
    561
    Thats odd, few people have tried it with no errors. How did you get it into unity? Also are you talking about the 3 layers or 2 layer one.

    Bill
     
  41. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I had that exact same problem when I was trying to add the shader to my project folder manually. What I did was copy it off the web on my PC and then save it as plain text and network it over to my mac. I also got it when I pasted shader code in anything other than from unity (SEE actually, but opened from unity). When I did the create new shader function in unity and then pasted the code in it was fine. If you download the actual .shader file though you should be able to just drop it in. I did.

    -Jeremy
     
  42. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    I tried to download the actual shader file before but if I do
    "Download Link Target" it gives me a download.php. so I copied the address to the file, put it on a link on my site temporarily and then downloaded it from there. Now it says "No subshaders can run on this card" at line -1. Does this mean my gfx card sucks to much to run this shader? If so I will lol my head off.
     
  43. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    Lol, I don't see why it wouldn't work. I know very little about shaders but AFAIK it doesn't do anything weird, it is just a blended shader. Maybe try to copy paste Bill's original shader off the forum and paste it directly into unity. Might help. Weird.

    -Jeremy