Blend damage revealed with noise texture mask

I created this shader to reveal damage on an object, using a noise texture as mask to create blots of damage that will eventually grow and cover the whole surface. It requires:

  • Base Texture: showing the “untouched” state of the object.
  • Damage Texture: showing the damaged state of the object.
  • Noise Texture: a NoiseTexture2D that you can generate in Godot itself, used as mask.

You can control the damage amount using the instance parameters:

  • Damage Amount: Ranges from 0 to 100, where 100 will show the Damage Texture at 100% visibilty.
  • Treshold: From which percentage no damage is yet visible. Defaults at 25%.
Shader code
shader_type spatial;

uniform sampler2D BaseTexture;
uniform sampler2D DamageTexture : hint_default_black;
uniform sampler2D NoiseTexture;
instance uniform float DamageAmount : hint_range(0, 100) = 0;
instance uniform float Treshold = 25.0;

void fragment() {
	vec4 damage_tex = texture(DamageTexture, UV);
	vec4 base_tex = texture(BaseTexture, UV);
	vec4 noise_tex = texture(NoiseTexture, UV);

	float scalar = noise_tex.x * DamageAmount;
	float smooth_step = smoothstep(scalar, DamageAmount, Treshold);

	vec3 output = mix(vec3(damage_tex.xyz), vec3(base_tex.xyz), vec3(smooth_step));

	ALBEDO = output;
}
Tags
3d, blend, damage, mask, noise, texture
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.

More from Erwin_Br

3D Health Bar

Related shaders

Double texture blend 2D

Texture Blend

Shock damage

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments