Threshold Mask Blend

A shader for threshold-based blending of one texture onto another using a mask.

Shader code
shader_type spatial;
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;

uniform sampler2D Albedo;
uniform sampler2D BlendTexture;
uniform vec4 BlendColor : source_color = vec4(0.9, 0.0, 0.0, 1.0);
uniform sampler2D BlendMask;
uniform float blend : hint_range(0.0, 1.0, 0.10) = 0.0;

void fragment() {
	vec4 _albedo = texture(Albedo, UV);

	vec4 _blend_texture = texture(BlendTexture, UV);

	vec3 _colored_blend_texture = vec3(_blend_texture.xyz) * vec3(BlendColor.xyz);

	vec4 stencil_mask = step(texture(BlendMask, UV), vec4(blend));
	vec4 mixed_textures = mix(_albedo, vec4(_colored_blend_texture, 0.0), stencil_mask.x);

	ALBEDO = vec3(mixed_textures.xyz);
}
Live Preview
Tags
4.0, 4.x, mask
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Lakamfo

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments