Hi there,
This is some code to blend textures based on a splatmap. It's perfect for terrains.
`
shader_type spatial;
uniform float grassres = 30;
uniform float rockres = 30;
uniform float dirtres = 30;
uniform float normalres = 10;
uniform sampler2D grass;
uniform sampler2D rock;
uniform sampler2D dirt;
uniform sampler2D splatmap;
uniform sampler2D normalmap;
void fragment(){
float grassval = texture(splatmap, UV).g;
float rockval = texture(splatmap, UV).b;
float dirtval = texture(splatmap, UV).r;
vec3 grasstex = texture(grass, UVgrassres).rgb grassval;
vec3 rocktex = texture(rock, UVrockres).rgb rockval;
vec3 dirttex = texture(dirt, UVdirtres).rgb dirtval;
vec3 result = grasstex + rocktex + dirttex;
ALBEDO = result;
vec3 normal = texture(normalmap, UV*normalres).rgb ;
NORMAL = normal;
METALLIC = texture(normalmap, UVnormalres).b ;
ROUGHNESS = texture(normalmap, UVnormalres).r;
}
`
My level is made of objects like walls and platforms, each will have multiple textures blended together.
With the above shader it's too slow because i need create a splat map per object. Instead vertex color should be quicker.
How can i get vertex color and pass it to fragment to work on pixels ?