I think I should structure this question better.

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

enter image description here

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?


1 Answer 1


Check out this link(Archive.org mirror), it should work for you (massive terrain + blended textures). Has a huge demo project size since he uses a big static mesh, but he applies the textures using a shader as well so you can take a peek at his blending algorithm. He also managed to make it seamless with multiple meshes.

  • \$\begingroup\$ This is indeed a very interesting project. I'm at my first try with unity and I'm quite a beginner with graphics. What I am understanding is that this guy has 64 meshes and for each one he has the same terrain. This tarrain contains 6 textures. As far as I had been able to understand he uses 64 maps, one per mesh, of 4 different types which are used in the shader. This cannot fit my project since can't have static maps to choose which materials are to show and which to hide. He built his project with static components so they match perfectly on their boundaries. But I have dynamic meshes \$\endgroup\$
    – Leggy7
    Feb 22, 2014 at 16:31
  • \$\begingroup\$ The 64 meshes are not the same (or don't have to be). You can match boundaries by code, but what you should really look at is his shaders, since there is quite a bit of "magic" there, matching up the mesh edges so removing the seams and blending the textures to create a nice terrain. \$\endgroup\$
    – Kanadaj
    Feb 22, 2014 at 22:51
  • \$\begingroup\$ indeed the result is awesome but maybe I am not undersanding something. In the project there are 64 model mesh, 64 mpas for lighting effect, 64 shadow effect and so on. Then a script iterate over the 64 meshes and set the renderer through the shader which blends everything for each mesh. So this is some static thing because if I change one mesh (for example swapping its position with another mesh) their rendering is no longer fine \$\endgroup\$
    – Leggy7
    Feb 22, 2014 at 23:57
  • \$\begingroup\$ For lighting and shadows you need Unity Pro anyways for dynamic meshes to work properly... The shader itself though should work properly even if you change your meshes. If it's not clear, say it, I'll clear it up as much as I can when I have the time. \$\endgroup\$
    – Kanadaj
    Feb 24, 2014 at 1:51
  • \$\begingroup\$ sure, you can find me here when you are available \$\endgroup\$
    – Leggy7
    Feb 24, 2014 at 8:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .