Search Unity

Wang Tiles

Discussion in 'Scripting' started by Phenotype, Nov 13, 2010.

  1. Phenotype

    Phenotype

    Joined:
    Oct 26, 2010
    Posts:
    53
    I am working on a 2d game and am wondering if anyone has tried implementing Wang Tiles. Unity does it's own tiling but I'd like to override that and replace it with a wang tile or corner tile implementation. Any suggestions on how I'd proceed?

    Thanks
     
  2. Jesse Anders

    Jesse Anders

    Joined:
    Apr 5, 2008
    Posts:
    2,857
    What tiling are you referring to?
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    A wang is something in my trousers so I'm rather confused by this whole concept.
     
  4. Vicenti

    Vicenti

    Joined:
    Feb 10, 2010
    Posts:
    664
    Indeed. xD

    If you're talking about these Wang Tiles then I'm afraid I'm not quite sure what you're getting at. Making textures tile is a matter of setting the UV values of a face to somewhere outside the texture. If you mean you want to grab tiles from a tileset image and spread them across a single plane, what you need is a plane made up of lots of triangles instead of just two, and you just need to assign UVs correctly using teh maths.
     
  5. Phenotype

    Phenotype

    Joined:
    Oct 26, 2010
    Posts:
    53
    Vicenti, currently when I apply a texture to a terrain for example it tiles the texture periodically in the x and y. When you zoom out you get a pattern of horizontal and vertical stripes. It doesn't look natural but that is the nature of periodic tiles. Wang tiles or corner tiles solve this by randomly fitting different tiles together, aperiodically, so that when you zoom out there are no horizontal or vertical bands. It looks like one natural field. But I guess this means I need to create a new terrain script. Can this be done or is this a hard wired thing?
     
  6. Phenotype

    Phenotype

    Joined:
    Oct 26, 2010
    Posts:
    53
    @hippocoder, you have some guy from china in your trousers? Too much info...
     
  7. Vicenti

    Vicenti

    Joined:
    Feb 10, 2010
    Posts:
    664
    It may be possible to write a terrain shader that flips textures randomly as it tiles them, but that's way beyond me. You might try asking in the Shader forum.

    Another possible solution is to break up your terrain textures by painting a little bit of other textures over them in some places. That can help break up the tiled look.
    You could also increase the size of your textures and/or decrease the contrast or add detail objects such as trees and large rocks to hide places that look especially tiled.
    And one more thing to try is, in the Terrain settings, increasing the Tiling X and Y values of the textures. They'll repeat less often, and it may be enough to remove the tiled look from the player's point of view.

    Meshes are easier, since you can assign UVs in a modeling program to manually mix up the tiling if you just break up your plane into many triangles instead of just 2.
     
  8. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Because of the repeating patterns of grass, for example, it looks terrible on landscapes, hills with the stadard Unity-UV tiling technique !!! (also in urban scenes, like with concrete surfaces) It is really a anoying thing & bad that we are nowadays don´t get rid of this "repeating patterns" with the "wang tile" shader technique.

    Don´t understand why most games doesn´t implemented this technique. Never saw a game that use the WT-shader tech. Or does anyone here saw a game with that technique ? Is it because of the performance (i guess)? Is there any other technique (i know only the standard layering technique) ? Can "ShaderForge" handle this ?

    In a 3D App, its pretty simple & fast (faster than noise shades) to use this technique. No special UV-mapping is required as you use the standard texture mapping. So what do you think ?