Texture Blend

Blend two colors and/or textures together based on a greyscale mask.

Shader code
shader_type spatial;

uniform sampler2D mask_texture:hint_albedo;
uniform vec4 albedo_a:hint_color = vec4(1.0f);
uniform sampler2D texture_a:hint_albedo;
uniform vec4 albedo_b:hint_color = vec4(1.0f);
uniform sampler2D texture_b:hint_albedo;

void fragment() {
	vec3 mask = texture(mask_texture, UV).rgb;
	vec3 a = albedo_a.rgb * texture(texture_a, UV).rgb;
	vec3 b = albedo_b.rgb * texture(texture_b, UV).rgb;
	vec3 color = mix(a, b, mask);
	ALBEDO = color;
}
Tags
blend, combine, merge, Mix, textures
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.

Related shaders

3-point texture filtering

Stochastic Procedural Texture Shader

Texture mix example

guest
0 Comments
Inline Feedbacks
View all comments