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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Procedural terrain - how to blend textures between meshes

Discussion in 'Editor & General Support' started by Leggy7, Feb 21, 2014.

  1. Leggy7

    Leggy7

    Joined:
    Feb 18, 2014
    Posts:
    21
    I try to phrase better this question.

    I'm developing a procedural terrain structured with voxel chunks.

    Every chunk:

    - contains a NxNxN voxel array generated with perlin noise 3d
    - contains a Mesh derived from the surface points of the voxel array
    - is rendered with marching cubes algoritm

    Every mesh has its own Material

    Every Material is made of 3 texture: one main texture and 2 minor textures to be blended with the main one depending on the slope. Every material has its own shader attached.

    So I have a terrain made of a certain number of chunks, that are a certain number of meshes generated as the game launches. Inside every chunk blending if okay, since I have the only material for the current mesh I have only to blend its textures depending on heights - and this is done by the shader.

    In this attached image

    $materials_not_blending.jpg

    you can see quite clearly what I acheived until now.
    As you can see, everything is mostly divided in "squares", which are the meshes. Each square has a texture green or beige (grass or sand).

    My concern is that:
    When passing from grass to sand there is no blending, i.e. blending between 2 meshes is my real problem, because inside the shader if have the surf function which iterates over all the input vertices. But those vertices are only from one mesh. To blend correctly I would need informations also about the vertices of the mesh nearby.

    So the question is:
    how can I blend properly materials belonging to different meshes?
     
    Last edited: Feb 28, 2014
  2. Leggy7

    Leggy7

    Joined:
    Feb 18, 2014
    Posts:
    21
    Let's take this thread up in the list!
    I thought procedural terrain were more popular than it seems they are
     
  3. wiseowlstudios

    wiseowlstudios

    Joined:
    Feb 13, 2011
    Posts:
    741
    have you tried texture by height eg if below 100 use sand 100-200 grass etc it might make it less blocky similar to what the terrain toolkit does
     
  4. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    What kind of terrain generator are you using? Do you need so many terrains really? Maybe you can reduce count of them and than try to blend them(that should be easyer)

    As wiseowlstudios said color terrain by height dependency would be very good and its easy to implement/prepare.

    If you still prefer to make blending for terrain maybe you should try some kind of painting tool? Like VPaint or Surface Painter?
     
  5. Leggy7

    Leggy7

    Joined:
    Feb 18, 2014
    Posts:
    21
    I'm generating a structure with perlin noise for then rendering it with marching cubes. I generate every chunk 32x32x32, then every cell has a isSurface property. I then collect every surface point to generate a mesh. And yes, I wil have several materials because this will be the very base of the game: to provide the player the most common real materials, randomly spawning on the surface.

    What is this color terrain by height you are talking about? It is something done at script level or at shader level?
     
  6. Leggy7

    Leggy7

    Joined:
    Feb 18, 2014
    Posts:
    21
    hmmm, anyone ever dealt with such situation?
     
  7. Stankiem

    Stankiem

    Joined:
    Dec 4, 2013
    Posts:
    115
    Sorry your explanation I think is a bit confusing which is why you may not be getting many answers. Maybe try rephrasing your question in your original post with more details on what plugin you are using to do all this (if any) and why in some blocks it turns out perfect looking and others it's just like a checker board?
     
  8. Leggy7

    Leggy7

    Joined:
    Feb 18, 2014
    Posts:
    21
    I tried to make myself clearer. Updated starting post
     
  9. MODev

    MODev

    Joined:
    Jul 30, 2013
    Posts:
    229
    It is done by shader. You know, you may setup for shader for 2 textures and in shader you can make some think like:
    if(vertexY > hillsHeight)
    useRock;
    else
    useGrass;
    Of course thats an example:)