Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Blending textures on a custom mesh

Discussion in 'General Graphics' started by Gian1983, Dec 2, 2019.

  1. Gian1983

    Gian1983

    Joined:
    Jan 2, 2019
    Posts:
    32
    Hello everybody,

    Here is my problem : I generate a procedural map (which gives me altitude, biomes and road network) and then a terrain mesh, from a perlin noise map. Then I want to apply a texture to my triangles, depending on the tile biome. I assign a material to the mesh, with a 2D texture I made in Gimp that contains every biome texture, and then I set the UVs of my mesh. But... I would like to add two others layers of texture : an other "biome layer" to deal with borders (for instance, if the tile is surrounded by snow, I want to avoid sharp borders) and a "road layer" (with the road texture if the tile has a road). The road network is defined once for all and will never change.

    What is the more efficient and easier to implement way to achieve that ? My question may be silly, but I've looked a lot of topics on forums and didn't find an answer.

    Should I set several textures (one for each layer) to my mesh material ? But then, how I assign a UVs map for each layer ? Using the UV2 and UV3 properties of my mesh ? Do I need to change the shadder ? (I don't know a lot about shadders...) An easy way would be to make in Gimp a texture with every possible combination of biome and road type... but I would like to avoid that solution, to keep things more adaptable...

    Thank you in adance for your help.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,256
    Sounds like the standard terrain issues. Look up terrain shaders and you should find plenty of examples of ways to do this. However it sounds like you're using a texture atlas for the terrain textures which will confuse things a little bit for you. However you're intuition on using the additional UV sets is correct, or alternatively you could use the additional 2 components of the first UV by using SetUVs() instead of .uv so you can use the full Vector4/float4 of that first UV. You can either have two materials on your terrain, one with the blend and one without, or you can have a single material and have a fully transparent part of the texture you overlay on most areas and the transition edges you overlay on the rest. And yes, you'd want to use a custom shader for this.
     
  3. DrabanL

    DrabanL

    Joined:
    Nov 13, 2014
    Posts:
    40
    Any chance the blending of the two textures can be done using Shader Graph?

    I`ve already mapped and painted everything (2 textures with alpha value to blend within, sampled from a tile map)
    but i`m struggling with blending smoothly between the two textures (in this preview i use Sampler State as 'Point')
    upload_2020-10-5_23-19-29.png


    mind you, 'Linear' Sampler State will almost always magically blend my textures perfectly, but sometimes not..
    upload_2020-10-5_23-21-28.png upload_2020-10-5_23-21-49.png

    --------

    EDIT:
    OK, found a solution
    my problem was that i was "Linear" sampling a single Tile map for both the tile IDs AND the alpha blending values.
    the correct way is to sample the Tile map twice, once with "Linear" sampling, which later to extract only the blending value from, and a different "Point" sampling which extracts the Tile ID.

    upload_2020-10-6_17-1-10.png
     
    Last edited: Oct 6, 2020
  4. STHedgeHog

    STHedgeHog

    Joined:
    Jun 24, 2015
    Posts:
    2
    Hello DrabanL, I realize this is an old topic and you may have moved on to newer things, but, if you still have it, could you post the shader you used to blend the tiles from a texture atlas please?
    I'm making a voxel world (ala Minecraft), combining meshes and manually setting the uv's to get the atlas to display the right texture. But it hard cuts from one to texture to another, and I'd like to smoothly merge between them to make it look much better.
    My knowledge of Shader Graph is very limited and I've been scratching my head for a few days trying to figure it out.
    Thanks.