Skip to main content
even clearer
Source Link
Leggy7
  • 1.5k
  • 15
  • 32

I think I should structure this question better.

My terrain consists inI'm developing a serie ofprocedural terrain structured with voxel chunks procedurally generated. I then connect surface voxels to create meshes. Since it

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 all dynamic I cannot workmade of 3 texture: one main texture and 2 minor textures to be blended with the main one depending on blending via the unity editor andslope. Every material has its own shader attached.

So I have to do alla terrain made of a certain number of chunks, that are a certain number of meshes generated as the work via scripts and shadersgame launches.
In Inside every chunk blending if okay, since I have the following picture you can seeonly material for the result achieved atcurrent mesh I have only to blend its textures depending on heights - and this is done by the momentshader.

In this attached image

enter image description here

as you can noticesee quite clearly what I acheived until now. As you can see, the areaeverything is mostly divided into squares (which actuallyin "squares", which are cubes with a mesh inside)the meshes. For everyEach square is dynamically randomly assignedhas a Materialtexture green or beige (grass or sand). Both material are for simplicity going with 3 textures

My concern is that: the main texture (grass or sand) and rock and gravel which are used to blend the When passing from grass (orto sand) depending on the slope.
As shown in the picture there is no blending, i.e. blending among textures (grass -> gravel -> rock or sand -> gravel -> rock)between 2 meshes is performed nicelymy real problem, although this works onlybecause inside a singlethe shader if have the surf function which iterates over all the input vertices. But those vertices are only from one mesh.
Nevertheless I don't know how to have a smooth passage when To blend correctly I crosswould need informations also about the vertices of the mesh having 2 different material one next to anothernearby.

TheSo the question could look likeis:    how can I have a smooth passage between 2 different materials, knowing that thoseblend properly materials don't belongbelonging to the same meshdifferent meshes?

I think I should structure this question better.

My terrain consists in a serie of voxel chunks procedurally generated. I then connect surface voxels to create meshes. Since it is all dynamic I cannot work on blending via the unity editor and have to do all the work via scripts and shaders.
In the following picture you can see the result achieved at the moment.

enter image description here

as you can notice, the area is divided into squares (which actually are cubes with a mesh inside). For every square is dynamically randomly assigned a Material (grass or sand). Both material are for simplicity going with 3 textures: the main texture (grass or sand) and rock and gravel which are used to blend the grass (or sand) depending on the slope.
As shown in the picture, blending among textures (grass -> gravel -> rock or sand -> gravel -> rock) is performed nicely, although this works only inside a single mesh.
Nevertheless I don't know how to have a smooth passage when I cross mesh having 2 different material one next to another.

The question could look like:  how can I have a smooth passage between 2 different materials, knowing that those materials don't belong to the same mesh?

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?

question refrased
Source Link
Leggy7
  • 1.5k
  • 15
  • 32

Procedural terrain - how to blend textures between dynamic meshes

UPDATE START I think I should structure this question better.

My terrain consists in a serie of voxel chunks My understandings concerning shaders in unityprocedurally generated: through struct Input{} it may gather mesh information via the Render.Mesh properties of the gameObject. Like if I write:

mesh.Color = someColor; 

then in the shader I can have:

struct Input { myRGB_ : COLOR } 

and thenconnect surface voxels to create meshes. Since it is all dynamic I can access insidecannot work on blending via the shader what I defined elsewhere forunity editor and have to do all the Color prpertywork via scripts and shaders.
I think Color is just one possibility. But I don't really understand how it works: maybe unity knows which areIn the mesh property types and whenfollowing picture you define a variale of the correct type in the shader it directly import data from mesh? I'm having an hard time finding out by myself..

My thought in these last 2 days was that if I could store some information about surrounding meshes, maybe I can later (insee the shader) access them to make proper blending between two meshesresult achieved at the moment. Am I out of my mind already?

UPDATE ENDenter image description here

Developing a procedural terrain, in Unity4.3.4, I'm stuck in an annoying situationas you can notice, here described.

At the moment I have 32x32 meshes each onearea is divided into squares (which actually are cubes with its own materiala mesh inside). Every materialFor every square is made up ofdynamically randomly assigned a Material (grass or sand). Both material are for simplicity going with 3 textures: the main texture (grass or sand) and there is a shader attached so that inside one mesh blending is performed correctly.

Problems come when I pass from a meshrock and gravel which are used to blend the one next to it, with a different material assignedgrass (or sand) depending on the slope. Since shader are per-material
As shown in the picture, no blendblending among textures (grass -> gravel -> rock or sand -> gravel -> rock) is performed between two different materials, that would mean to blend texture for material1nicely, then blend textures for material2 and finally blend the two materials toghetheralthough this works only inside a single mesh. But
Nevertheless I don't really know wherehow to begin.

Here followeshave a picturesmooth passage when I cross mesh having 2 different material one next to give a better idea of the situation

enter image description hereanother.

You can clearly see the sand square surrounded by grass in the bottom right corner of the picture. There is no blending between those two materials. That blending is my goalThe question could look like: how can I have a smooth passage between 2 different materials, knowing that those materials don't belong to the same mesh?

Procedural terrain - how to blend textures between meshes

UPDATE START

My understandings concerning shaders in unity: through struct Input{} it may gather mesh information via the Render.Mesh properties of the gameObject. Like if I write:

mesh.Color = someColor; 

then in the shader I can have:

struct Input { myRGB_ : COLOR } 

and then I can access inside the shader what I defined elsewhere for the Color prperty.
I think Color is just one possibility. But I don't really understand how it works: maybe unity knows which are the mesh property types and when you define a variale of the correct type in the shader it directly import data from mesh? I'm having an hard time finding out by myself..

My thought in these last 2 days was that if I could store some information about surrounding meshes, maybe I can later (in the shader) access them to make proper blending between two meshes. Am I out of my mind already?

UPDATE END

Developing a procedural terrain, in Unity4.3.4, I'm stuck in an annoying situation, here described.

At the moment I have 32x32 meshes each one with its own material. Every material is made up of 3 textures and there is a shader attached so that inside one mesh blending is performed correctly.

Problems come when I pass from a mesh to the one next to it, with a different material assigned. Since shader are per-material, no blend is performed between two different materials, that would mean to blend texture for material1, then blend textures for material2 and finally blend the two materials toghether. But I don't really know where to begin.

Here followes a picture to give a better idea of the situation

enter image description here

You can clearly see the sand square surrounded by grass in the bottom right corner of the picture. There is no blending between those two materials. That blending is my goal

Procedural terrain - how to blend textures between dynamic meshes

I think I should structure this question better.

My terrain consists in a serie of voxel chunks procedurally generated. I then connect surface voxels to create meshes. Since it is all dynamic I cannot work on blending via the unity editor and have to do all the work via scripts and shaders.
In the following picture you can see the result achieved at the moment.

enter image description here

as you can notice, the area is divided into squares (which actually are cubes with a mesh inside). For every square is dynamically randomly assigned a Material (grass or sand). Both material are for simplicity going with 3 textures: the main texture (grass or sand) and rock and gravel which are used to blend the grass (or sand) depending on the slope.
As shown in the picture, blending among textures (grass -> gravel -> rock or sand -> gravel -> rock) is performed nicely, although this works only inside a single mesh.
Nevertheless I don't know how to have a smooth passage when I cross mesh having 2 different material one next to another.

The question could look like: how can I have a smooth passage between 2 different materials, knowing that those materials don't belong to the same mesh?

some thought evolution
Source Link
Leggy7
  • 1.5k
  • 15
  • 32

UPDATE START

My understandings concerning shaders in unity: through struct Input{} it may gather mesh information via the Render.Mesh properties of the gameObject. Like if I write:

mesh.Color = someColor; 

then in the shader I can have:

struct Input { myRGB_ : COLOR } 

and then I can access inside the shader what I defined elsewhere for the Color prperty.
I think Color is just one possibility. But I don't really understand how it works: maybe unity knows which are the mesh property types and when you define a variale of the correct type in the shader it directly import data from mesh? I'm having an hard time finding out by myself..

My thought in these last 2 days was that if I could store some information about surrounding meshes, maybe I can later (in the shader) access them to make proper blending between two meshes. Am I out of my mind already?

UPDATE END

Developing a procedural terrain, in Unity4.3.4, I'm stuck in an annoying situation, here described.

At the moment I have 32x32 meshes each one with its own material. Every material is made up of 3 textures and there is a shader attached so that inside one mesh blending is performed correctly.

Problems come when I pass from a mesh to the one next to it, with a different material assigned. Since shader are per-material, no blend is performed between two different materials, that would mean to blend texture for material1, then blend textures for material2 and finally blend the two materials toghether. But I don't really know where to begin.

Here followes a picture to give a better idea of the situation

enter image description here

You can clearly see the sand square surrounded by grass in the bottom right corner of the picture. There is no blending between those two materials. That blending is my goal

UPDATE: I think I should point out that I'm not just seeking a way to blend materials from dynamic meshes, I also want to keep track of the material I'm walking on. I noticed that it is possible for a mesh to have stored an array of materials but I cannot really understand if this can be of help. I mean: maybe I can use some technique to teach the shader which verts belongs to a material and which does not?

Developing a procedural terrain, in Unity4.3.4, I'm stuck in an annoying situation, here described.

At the moment I have 32x32 meshes each one with its own material. Every material is made up of 3 textures and there is a shader attached so that inside one mesh blending is performed correctly.

Problems come when I pass from a mesh to the one next to it, with a different material assigned. Since shader are per-material, no blend is performed between two different materials, that would mean to blend texture for material1, then blend textures for material2 and finally blend the two materials toghether. But I don't really know where to begin.

Here followes a picture to give a better idea of the situation

enter image description here

You can clearly see the sand square surrounded by grass in the bottom right corner of the picture. There is no blending between those two materials. That blending is my goal

UPDATE: I think I should point out that I'm not just seeking a way to blend materials from dynamic meshes, I also want to keep track of the material I'm walking on. I noticed that it is possible for a mesh to have stored an array of materials but I cannot really understand if this can be of help. I mean: maybe I can use some technique to teach the shader which verts belongs to a material and which does not?

UPDATE START

My understandings concerning shaders in unity: through struct Input{} it may gather mesh information via the Render.Mesh properties of the gameObject. Like if I write:

mesh.Color = someColor; 

then in the shader I can have:

struct Input { myRGB_ : COLOR } 

and then I can access inside the shader what I defined elsewhere for the Color prperty.
I think Color is just one possibility. But I don't really understand how it works: maybe unity knows which are the mesh property types and when you define a variale of the correct type in the shader it directly import data from mesh? I'm having an hard time finding out by myself..

My thought in these last 2 days was that if I could store some information about surrounding meshes, maybe I can later (in the shader) access them to make proper blending between two meshes. Am I out of my mind already?

UPDATE END

Developing a procedural terrain, in Unity4.3.4, I'm stuck in an annoying situation, here described.

At the moment I have 32x32 meshes each one with its own material. Every material is made up of 3 textures and there is a shader attached so that inside one mesh blending is performed correctly.

Problems come when I pass from a mesh to the one next to it, with a different material assigned. Since shader are per-material, no blend is performed between two different materials, that would mean to blend texture for material1, then blend textures for material2 and finally blend the two materials toghether. But I don't really know where to begin.

Here followes a picture to give a better idea of the situation

enter image description here

You can clearly see the sand square surrounded by grass in the bottom right corner of the picture. There is no blending between those two materials. That blending is my goal

additional informations
Source Link
Leggy7
  • 1.5k
  • 15
  • 32
Loading
Tweeted twitter.com/#!/StackGameDev/status/437304244157571074
added 175 characters in body
Source Link
Leggy7
  • 1.5k
  • 15
  • 32
Loading
Source Link
Leggy7
  • 1.5k
  • 15
  • 32
Loading