Advanced 7 Texture Albedo Terrain Shader
all you need is an RGBA mask, and a few seamless textures. made for godot 4.x but can probably work for 3.x
Shader code
shader_type spatial;
render_mode cull_back, blend_mix;
//uv scales
uniform lowp float uv_scale = 1.0;
uniform lowp float alpha_uvs_scale = 1.0;
uniform lowp float mask_uv_scale = 1.0;
//mix intensities
uniform lowp float mix0_intensity = 1.0;
uniform lowp float mix1_intensity = 1.0;
//mask
uniform mediump sampler2D terrain_mask : source_color;
//blacks and whites
uniform mediump sampler2D texture_black : source_color;
uniform lowp sampler2D texture_alphablack : source_color;
uniform lowp sampler2D texture_alphawhite : source_color;
//rgbs
uniform mediump sampler2D texture_red : source_color;
uniform mediump sampler2D texture_green : source_color;
uniform mediump sampler2D texture_blue : source_color;
void fragment() {
vec2 scaled_uvs = UV * uv_scale;
vec2 scaled_mask_uvs = UV * mask_uv_scale;
vec2 scaled_alpha_uvs = UV * alpha_uvs_scale;
//finals
vec4 texturemask = texture(terrain_mask, scaled_mask_uvs);
vec3 textureblack = texture(texture_black, scaled_uvs).rgb;
vec3 texturealphablack = texture(texture_alphablack, scaled_alpha_uvs).rgb;
vec3 texturealphawhite = texture(texture_alphawhite, scaled_alpha_uvs).rgb;
vec3 texturer = texture(texture_red, scaled_uvs).rgb;
vec3 textureg = texture(texture_green, scaled_uvs).rgb;
vec3 textureb = texture(texture_blue, scaled_uvs).rgb;
float summed_rgb_mask = (
texturemask.r +
texturemask.g +
texturemask.b
);
vec3 mixxed_rgb_terrain = clamp(
texturemask.r * texturer +
texturemask.g * textureg +
texturemask.b * textureb /
summed_rgb_mask,
vec3(0.0) , vec3(1.0)
);
vec3 mixxed_alpha_terrain = clamp(
texturemask.a * textureb /
texturemask.a,
vec3(0.0) , vec3(1.0)
);
ALBEDO = mix(mixxed_rgb_terrain, textureblack, 1.0 - summed_rgb_mask) * mix0_intensity + mix(mixxed_alpha_terrain, texturealphawhite, texturealphablack + texturemask.a) * mix1_intensity;
}
if you guys find any issues, or have any suggestions/improvements/fixes, tell me in the comments!
Does the shader do height and pixel blending?
The preview images seems to have hard edges
mmmm.. nahhhh