Search Unity

Multi-layer tile based terrain shader for mobile?

Discussion in 'Shaders' started by zero1, Aug 26, 2013.

  1. zero1

    zero1

    Joined:
    Apr 17, 2013
    Posts:
    4
    Hi there,

    A question of total shader writing noob on multi-layer shaders.

    I'd like to be able create a tile based shader / texturing for terrain like surfaces. It would be interesting to know if this is possible to do - I know there are commercial solutions like Terrain Tile Editor, but I'm not sure if it is suitable for this kind of use, i.e. for creating Warcraft 3 style tilemapping from level data which would also work on mobile platforms like iOS.

    Shader should operate on following principle;
    1. Have a tilesheet for a material. Have multiple overlay materials (1 base material, maybe 3 overlay layers)
    2. Have a level data set for each material layer.
    3. Fill each tile (polygon) of level mesh with tile area using texture area from tilesheet (each tilesheet have the same tile layout most likely)
    4. Render all tiles. Proceed to next layer.
    5. Next layers will use different tilesheet, and different tile data.
    6. Alpha blend each layer on top of a previous layer, using tilesheet texture alpha channel.
    7. A tile in any layer won't use same UV area as previous layer's tile most likely (different materials overlayed have different patterns)

    Problem:
    - When approached from manual way of creating this, Unity's limitation of 1 UV for texture and 1 UV for lightmapping becomes obvious. It is not possible to just have 4 materials, each of which would have it's own UV set.

    So,

    - Is it possible to modify / generate UV coordinates for each polygon of plane "terrain" when rendering material layer?

    - Is it possible to overlay another layer of texture on the same polygons, using different set of UVs? I don't mind if there will be little bit more draw calls, it wouldn't be a problem if there was 4 draw calls for 4 material layers. I'm wondering, if it is even possible to make a shader which communicates with level data in this manner?

    - I don't like the idea to use built-in terrain. I'd like to use tiles+alpha map from tilesheet, this way blending of tiles is artistically controlled.

    - Using multiple meshes on top of each other doesn't sound like a good idea either.

    - Using local sticker like texture planes for variation wouldn't be usable either, as the terrain texturing should be tile-like, constantly changing on large terrain with height variations.

    I did quite a lot of searching about this topic and came up with very little results, so any tips, links and solutions would be appreciated!

    Thanks in advance.
     
  2. Broken-Toy

    Broken-Toy

    Joined:
    Jan 16, 2010
    Posts:
    455
    With a shader that blends textures using vertex colors or a splat texture, you can layer many different textures on the same mesh, usually up to four per material (five if you add a 'base' texture). That's also how the Unity terrain works.
     
  3. zero1

    zero1

    Joined:
    Apr 17, 2013
    Posts:
    4
    I have to admit I don't know that much about Unity Terrain -> maybe I should take a closer look, at least into the shader part. If I may ask, does it allow 4 different UV sets to be used - i.e. does it's shader allow texturing of each terrain polygon with unique UV area for each layer of terrain material?

    We would also be using alpha map from the same texture to blend each piece of texture, not vertex colors. Initially we discarded the idea of using terrain as it doesn't seem to suit our needs (create WoW like tiling terrain texturing).
     
  4. f5fairy

    f5fairy

    Joined:
    Nov 21, 2012
    Posts:
    10
    Where can I find such shader? "Terrain Four Layer" from wiki doesn't work on mobile. And even standard terrain shader is glitchy on my mali-400 device.

    ***
    Nevermind, I found out how to do it
     
    Last edited: Mar 2, 2014
  5. alsharefeeee

    alsharefeeee

    Joined:
    Jul 6, 2013
    Posts:
    80
    Actually I have the same problem, How did you solve the problem?
     
  6. gherat

    gherat

    Joined:
    Oct 30, 2013
    Posts:
    4
    This is a forum, explain how you solved the issue!! Other people might have the same problem..