Hello, I’m new ! And I have a question : how can I blend a lot of textures in one mesh ? When I search on google, it screams “Use a shader and vertice color !!!” but there is a big problem… The color of a vertex contains only 4 variables : R, G, B, A and if I want to fade for example 15 textures, I am lost and I don’t know how to do that.
So, have you a solution ? Thank you in advance !
In Unity 5 you can blend textures with the standard shader.
Here’s a great video going through the standard shader and more specifically what you want at 12:11 minute mark:
However it’s been a while since I’ve seen that vid but so I’m not completely sure about the 15 texture blend but you can atleast blend 2 sets.
@Esu, Kilian was onto something there. Use Vertex blending to apply colors that match a splat map. Then apply your textures through Triplanar projection so you don’t have to worry about UVs as you dig.
You guys seem to all talk about different things here so I’ll add my few cents. The main question was about vertex blend, not splatmaps or vertex coloring.
I work with vertex blend/heighmaps in a custom engine, but I havent seen any good examples in unity yet. There might be good shader programmers that can make this for you or you do it in shader forge, amplify shader. There are a lot if tutorials out there. Look into vert blending with heightmaps as a go to solution. More work to setup, but worth it.
In general about vert blending. Based on the comments, I’m not sure how much vertex blending you guys have done, but there are performance reasons why vertex blend is still superior to splat maps and masks. Spatmaps are ok for custom areas, but waste memory. If you want realistic detail and want to keep it cheap you use a bunch of tileables, up to 4 textures/materials, each linked to separate rgba channels. Each vert channel acts like a white mask, similar to the rgba channels in photoshop. The colors are there as channel names only. Vertex color and vertex blend are totally separate things. Vertex color can be used to color the assets, bake cheap lighting, shadow, while same channels can also be used to blend between materials. If you need more than 4 textures, you need to create more materials where one texture is shared where the blend occurs.
For vertex blends, try to stay away from 4 texture since the more you add, the more expensive it runs. Rather use max 2-3, and create more materials that take over where the first material ends. As an example fir a 2 texture setup. mat1:grass+rock…mat2: grass+mud…mat3: mud+water. You set the rgba channels so grass is always R, mud always B…so when you paint, both materials can be blended and there is no seams where the material swap occurs. Multi material blends are usually done in maya or 3dsmax. Assigning the materials to the terrain polygons manually, then blending in maya or in unity. More work but efficient if you create large games. Unity paints the blends with plugins like ikari vertex painter. Stick to one material as a start to learn the technique before looking into multi material blends. That can get tricky
Another way the blends are done is with separate decals, or projection decals that get added on top. This is not recommended for mobile games since it adds to overdraw, but worth knowing about. With these setups, you use a 3 material vert/height blend setup at bottom, and add decals on top. As a 3rd pass, you add rock, grass meshes to make it look real. Expensive but works in next gen systems.
Substance painter is used for custom assets, or custom terrain, but keep in mind that every texture adds up. Memory, overdraw and drawcalls is a severe problem still. Always keep things simple. The fewer materials you use, the faster it will run.
Anyway, explaining the differences here and how we use it in the gaming industry. There seems to be a lot of confusion about vertex color, vertex blend, splatmaps, masks in general. Aim to keep things simple and cheap for terrain. It’ll make things easier once changes occur. Memory and time issues is the main reason AAA games use a vert/heightmap solution still. Masks are great, but too memory consuming if every area needs to be custom.
/ Tim
I have this shader that i think is what you want: Parallax Shader by Oris
Well, 2 ways to do this. The easy one is to use Photoshop or GIMP or some other image editing program to blend your textures into 1, then use that texture.
If you need to do it runtime - you will need to write a shader to do it.
Yes, a shader color only has 4 variables, r,g,b,a. You don’t need more than that - the output is always going to be just one color, namely the one that gets drawn.
As I repeatedly say on this forum, I am not really good at shaders, but what you’d need to do is something like
Shader "MyShader" {
Properties {
_MyTexture1 ("Texture1", 2D) = "white" { }
_MyTexture2 ("Texture2", 2D) = "white" { }
_MyTexture3 ("Texture3", 2D) = "white" { }
///and so on
}
SubShader {
#pragma surface surf Lambert
struct Input {
float2 uv_Tex1;
float2 uv_Tex2;
float2 uv_Tex3;
};
sampler2D _MyTexture1;
sampler2D _MyTexture2;
sampler2D _MyTexture3;
void surf (Input IN, inout SurfaceOutput o) {
//get colors of textures
float4 col1 = tex2D (_MainTex, IN.uv_Tex1).rgb;
float4 col2 = tex2D (_MainTex, IN.uv_Tex2).rgb;
float4 col3 = tex2D (_MainTex, IN.uv_Tex3).rgb;
//blend them somehow - here I just use average color
float finalR = col1.r/3 + col2.r/3 + col3.r/3;
float finalG = col1.g/3 + col2.g/3 + col3.g/3;
float finalB = col1.b/3 + col2.b/3 + col3.b/3;
float4 final;
final.r = finalR;
final.g = finalG;
final.b = finalB;
o.Albedo = final;
}
ENDCG
}
}
Don’t expect that to actually work, I’m not good at shaders and the shaders I do write are always vertex and fragment shaders, I’m sure there is a lot of syntax in there that’s incorrect. I think a surface shader should do for just blending textures though.