Just wondering what the common practice is for uv mapping irregular meshes such as terrain for use with tiling textures.
Just looking at this image here from John Germanns portfolio is a shot from one of Uncharted 2 levels:
![image-JG-icecave-mp-4-1.jpg](http://www.johngermann.com/images/image-JG-icecave-mp-4-1.jpg)
![image-JG-icecave-mp-4-2.jpg](http://www.johngermann.com/images/image-JG-icecave-mp-4-2.jpg)
Can't get my head around how you'd split the mesh up uniformly to take advantage of tiling textures.
Seems there'd be a lot of texture stretching if you where to take pieces of the mesh and just relax them to conform to a square and them fit them to 0-1 uv space so that they'd tile.
I see they use a lot of texture blending so maybe texture seams aren't that important if they can just blend another texture over the seams.
One way i though of doing it was to create a plane with the required subdivisions, then uv map each quad so that it covers the full 0-1 uv space, then you'd get perfect tiling and just model the plane into the shape required.
Any further insight would be grateful.
Replies
Well the problem is thats not really how you tile textures at all. Sure you "can" do that but for things tiling textures in the 0 to 1 is not something you do at all. Then again it depends on what type of texture blending you use be it vertex or blend maps.
The reason for this is each asset requires a different tiling rate to keep a uniform pixel density. Say for example you have a massive terrain chunk and small rock both using the same texture. If you crushed the UV's down in the 0 to 1 box you would require 2 different variations of the shader to get the same pixel density as the terrain would require a lot more tiling in the shader itself.
What you want to do is tile things in your UV's by making them larger or smaller outside of the 0 to 1 box. Using this method you can ensure that each asset using the same tiling texture has a closer pixel density ratio then if you crushed everything into the 0 to 1. Not to mention the 0 to 1 crush would give you crazy amounts of texture stretching.
You want your unwraps to have as little distortion as possible.
How to get around seams is generally smart planning/placement of them not only in unwrapping but in modeling. For terrain the best places to break up UV's is on the inset of cracks and crevasses. Another place is right under the lip over hang of a cliff face. When modeling cliff faces like this its good to keep this concept in the back of your mind so you can add some well placed inset cracks in areas that will help break up your UV's to avoid to much stretching.
Another way to alleviate this problem is most modern day games (if not all modern next gen games) use vertex blending or blend maps for terrain. At Bungie we used blend maps for Reach. Basically its an extra texture map, that is only 3 colors. Red Green and Blue. Each color represent a tiling texture shader so Red could be your snow, Green your cliffs and Blue your cliffs with snow on them. Or what have you. You use this to blend the textures together nicely and it helps with texture seams but dosnt remove them compelty.
The blend map dosnt have to be super huge as you dont need it to be super detailed but again it is another texture map in memory. Also for blend maps the blend map will take all the terrain UV's and scale them to fit into the 0 to 1 box as it will be a unqiue texture and tiling is then controlled via the shader, not UV's. Again it all comes down to what your engine supports and how you want to go about it. Vertex blending would have UV's outside the 0 to 1 as you dont require a unique blend map texture to control where things blend. So tiling is not controled by the shader, more by the UV's
Here is an example UV layout of what I mean when your textures should tile outside of the 0 to 1. This is obviously not terrain, it is actually wood boards but I think you can get the idea.
for me this looks like a blend map between two materials. snow and rock. probably one uv layout, which was painted and projected on one texture.
then there are two base materials rock and snow both tiling textures. you can pu your seams or break up the uv's wherever you're texture is 100% blended with the other material. that's it.
at least i could reproduce the result with this technique.
add some vertex lightning or a lightmap on top and you get nice result. for sure the blend map needs quite some size, but you save that one the tiling texture.
if needed you can reuse part of the blend map for parts of the mesh to keep the texture size smaller.
What i meant with the statement you quoted, was breaking the mesh up into relatively sized square chucks that tile, then each part would get the same pixel density. This would probably cause some stretching, but there'd be no seams.
If you were to make rock wall chunks out of a ton of square pieces you would notice the tiling. Again why would you ever want stretched textures when simple planning can more or less eliminate them. Putting seams in the inset cracks and crevasses, having lighting/ao and using blend maps/vertex blending will remove the noticeably of seams while still giving your terrain/cliffs that unique realistic look instead of silly tiling chunks.
For cliff walls another technique you can use is to create 4 or 5 different large cliff wall faces. This wont tile front end to end at all, but will still use the same techniques as a large piece of terrain on where to put cuts and seams. You then zbuffer these chunks into each other to create large unique cliff faces. Naughty dog also did this with there cliff faces. Large terrain meshes like shown above are uniquely made.
Again you dont want your terrain/cliffs to look like they tile so creating square sized tiling chunks to make up your terrain is only going to show the tiling even more. You will also never get the unqiue look of real life from this method. It will have that very CG look to it. In reality I cant think of a single game that uses tiling cliff chunks to make up there walls. They might use large cliff chunks they zbuffer together but the chunks themselfs dont tile from end to end.
r_fletch_r: Look forward to seeing the results.
Autocon: I would be using vertex colour for the blending, im just looking for the best way about unwrapping something similar to that mesh in my first post to take advantage of tiling textures.
Oh yeah, get outside the 0-1 box dude! Let me guess, you're a character artist branching out to environments?
To put it really really simply the shader does blended box mapping of up to 3 textures and modulates between them with the R G and B Vertex colours.
It's a cool premise for some things, but a lot of the time I'd like exact control over how it looks. I suppose for open areas of grass and such, it's a great technique. I'm sure the shader is a bit expensive though. Blending multiple channels and textures is always spendy.
r_fletch_r: Looks awesome.
Justin_Meisse: No, i've always enjoyed environment stuff more than the character stuff. Just wasn't aware that anything outside of 0-1 uv space would transfer over to a game engine.
Tnx everyone for your inputs.
Although using a shader gives this thing a whole new dimension if its fast enough for real time situations.
Maybe even a mix of things like a script that colors vertex colors depending on angle or world orientation and then a traditional texture blending script based on vertex colors to blend them would be another way of doing things.
I'm re building the shader at the moment to use as few instructions as possible. Even if this is too expensive for realtime I'm going to make a MetaSL version so I can use it in Max. I think MetaSL may even do this natively.
Its just for max at the moment. You will need to use a directX material to apply it.
Workflow:
Assign Black Vertex Colours to the mesh.
Assign the Shader to the mesh.
*Load a texture into atleast the base, and texture2 map slots.
Paint Vextex Colours to expose the individual textures
Red to expose Texture2
Green to expose Texture3
Blue to expose Texture4