Texture-based Color Overlay (4.3)

The first shader I’ve ever written by myself. Allows you to overlay an existing material with a color based on a texture, with variable tolerance. This can be useful for things like gradually breaking walls, covering things with paint, etc. Originally intended to only be used with noise, but hand painted textures work too.

Usage:

Create a material of any kind

Add a new ShaderMaterial under Next Pass

Put this into the Shader option in the material

Tweak settings to your liking

Shader code
shader_type spatial;

uniform vec4 noise_color : source_color;
uniform sampler2D noise_texture : source_color, filter_nearest;
uniform float tolerance : hint_range(0,1.0);
uniform float noise_scale : hint_range(0.0,10.0);

void fragment() {
	vec2 uv = vec2(0.0);

	uv = UV;

	ALBEDO = noise_color.rgb;
	vec4 noise = texture(noise_texture, uv * noise_scale);
	float avg = (noise.r+noise.g+noise.b)/3.0; //get average value of pixel from noise
	if (avg < tolerance) 
		ALPHA = noise_color.a; //if average value is within tolerance, show the noise
	else
		ALPHA = 0.0; //otherwise dont
}
Tags
burn, Color, noise, overlay
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

Color shift Color Reducer post-processing

Tileset Worldspace Noise/Decal Overlay

2D TileMap grid overlay with mouse highlight

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments