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;
}
Tags
3d, Spatial, splat map, splatting, terrain, texture
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from mujtaba-io

sine wave camera view shader

cheap Toon shader [quick dirty code]

Ray marching ocean waves + atmosphere

Related shaders

PSX Shader with Vertex Colors and Corruption Slider

ORM material blending using vertex colors and noise with hard/soft transitions

3D HP Bar of 2 Blended Colors

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments