[ REDACTED ]
A shader that redacts a mesh by applying a customizable color, static amount and an albedo texture.
Since Godot 4.x no uses Vulkan, this shader no longer needs any script file to work.
I also added a horizontal offset feature and comments explaining the code to this one!!!
A deprecated 3.x version can be found here.
Shader code
shader_type spatial;
// Render the shader outside of scene light
render_mode blend_mix,depth_draw_opaque,cull_front,unshaded,shadows_disabled,ambient_light_disabled;
uniform vec2 scroll_speed = vec2(3.0, 5.0);
uniform float static_intensity : hint_range(0.0, 1.0, 0.05) = 0.25;
uniform vec4 color : source_color = vec4(0.0);
uniform float tex_scale : hint_range(0.01, 10.0, 0.01) = 3.0;
uniform sampler2D albedo_tex : hint_default_white;
uniform float tiling_offset : hint_range(0.0, 1.0, 0.01) = 0.5;
// Color randomizer per fragment. Randomizes a value between black and white.
float rand(vec2 co){
return fract(sin(dot(co, vec2(1123.81321, 1161.803398))) * 3142.92653);
}
void fragment() {
// Get the base UV from the screen texture and scale the X axis so it retains the original aspect ratio.
vec2 base_uv = vec2(SCREEN_UV.x - 0.5, SCREEN_UV.y - 0.5) * (1.0 / tex_scale);
base_uv.x *= VIEWPORT_SIZE.x / VIEWPORT_SIZE.y;
// Grab the distance between the camera and the mesh ith the shader.
float camera_distance = length(NODE_POSITION_WORLD - CAMERA_POSITION_WORLD) + 0.1;
// Scale and pan the texture based on the scroll uniform. Also avoid dividing by 0.
vec2 pan_and_scale = base_uv * camera_distance + (scroll_speed * TIME * 0.1);
// Offset the texture now. Doing it before, breaks the shader.
pan_and_scale.x += floor(pan_and_scale.y) * tiling_offset;
// Make the texture and make the alpha channel into a black color.
vec4 tex = texture(albedo_tex, pan_and_scale);
tex.rgb = mix(vec3(0.0), tex.rgb, tex.a);
// Add noise to the texture.
float noise = pow(rand(UV * TIME * 0.1), 3) * static_intensity;
// Apply color to noise. Setting some of the noise to the inverse of the fragment color helps in noise visibility.
vec3 cnoise = mix(color.rgb, vec3(1.0) - color.rgb, noise);
// Calculate the final color of the fragment.
vec3 final = mix(cnoise * tex.rgb, cnoise, noise * 0.5);
// Apply the shader.
ALBEDO = final;
}



