Simple Splat-map Shader for 3D Terrain (uses Vertex colors as splatmap)
A simple splat-map terrain shader. it uses vertex colors as a splat-map. The alternative approach is to use texture sampler as splat-map but I didnt use it because I think it will take resources. I used it in my RTS game tutorial for procedurally generated terrain. If you like my work, consider supporting it on patreon (linked on website) as it will allow me to pay for the website hosting and motivate me.
Shader code
shader_type spatial;
uniform sampler2D grass_texture;
uniform sampler2D grass2_texture;
uniform sampler2D dirt_texture;
uniform float texture_scale = 1.0;
void fragment() {
// Get vertex color
vec3 vertex_color = COLOR.rgb;
// Sample each texture
vec2 uv_scaled = UV * texture_scale;
vec4 grass_tex = texture(grass_texture, uv_scaled);
vec4 grass2_tex = texture(grass2_texture, uv_scaled);
vec4 dirt_tex = texture(dirt_texture, uv_scaled);
// Mix textures based on vertex colors
vec4 final_color = vec4(0.0);
final_color += grass_tex * vertex_color.r; // Grass for red
final_color += grass2_tex * vertex_color.g; // Grass2 for green
final_color += dirt_tex * vertex_color.b; // Dirt for blue
// Output the final color
ALBEDO = final_color.rgb;
}