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

Double texture blend 2D

FPS view shader with color/texture and metallic

Volumetric Billboards (3D Texture sampled by plane stacking)

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
James
James
1 year ago

tysm <3