Corrosion Shader – 3D
This shader was inspired by games like Silent Hill, and how they transform their environments. Even though it was originally created with the shader graph, using Godot’s built-in converter I’ve switched it to a script, so it could be uploaded here. This means that this will not be a perfect conversion but it should be good enough to edit and further iterate upon!
I am hoping to remake this shader entirely in code later on, but for now, this should work for any project that may need something like this!
Shader code
shader_type spatial;
render_mode cull_disabled, specular_schlick_ggx;
uniform sampler2D noise_texture;
uniform float fade_scale;
uniform sampler2D end_texture : hint_albedo;
uniform sampler2D base_texture : hint_black_albedo;
void vertex() {
// Output:0
}
void fragment() {
// Input:2
vec3 n_out2p0 = vec3(UV, 0.0);
// Input:35
vec3 n_out35p0 = vec3(UV, 0.0);
// Texture:30
vec4 tex_frg_30_read = texture(noise_texture, n_out35p0.xy);
vec3 n_out30p0 = tex_frg_30_read.rgb;
float n_out30p1 = tex_frg_30_read.a;
// ScalarUniform:36
float n_out36p0 = fade_scale;
// ScalarClamp:44
float n_in44p1 = 0.00000;
float n_in44p2 = 1.00000;
float n_out44p0 = clamp(n_out36p0, n_in44p1, n_in44p2);
// ScalarMix:33
float n_in33p2 = 0.50000;
float n_out33p0 = mix(n_out44p0, dot(n_out30p0, vec3(0.333333, 0.333333, 0.333333)), n_in33p2);
// ScalarFunc:34
float n_out34p0 = round(n_out33p0);
// TextureUniform:37
vec3 n_out37p0;
float n_out37p1;
{
vec4 n_tex_read = texture(end_texture, UV.xy);
n_out37p0 = n_tex_read.rgb;
n_out37p1 = n_tex_read.a;
}
// TextureUniform:38
vec3 n_out38p0;
float n_out38p1;
{
vec4 n_tex_read = texture(base_texture, UV.xy);
n_out38p0 = n_tex_read.rgb;
n_out38p1 = n_tex_read.a;
}
// If:29
vec3 n_out29p0;
if(abs(dot(n_out2p0, vec3(0.333333, 0.333333, 0.333333)) - dot(n_out30p0, vec3(0.333333, 0.333333, 0.333333))) < n_out34p0)
{
n_out29p0 = n_out37p0;
}
else if(dot(n_out2p0, vec3(0.333333, 0.333333, 0.333333)) < dot(n_out30p0, vec3(0.333333, 0.333333, 0.333333)))
{
n_out29p0 = n_out38p0;
}
else
{
n_out29p0 = n_out38p0;
}
// Output:0
ALBEDO = n_out29p0;
}
void light() {
// Output:0
}
Hi, you could try using this line instead (GODOT 4):
(And change hint_albedo and hint_black_albedo for hint_default_white, hint_default_black, respectively)
Hey, great shader! This works really well!
I’ve gone ahead and transferred this to code.
3D:
shader_type spatial;
uniform float fade_scale : hint_range(0.0, 1.0) = 0.5;
uniform sampler2D noise_texture;
uniform sampler2D base_texture : hint_default_black;
uniform sampler2D end_texture : hint_default_white;
void fragment() {
//Get height threshold of noise
float height_cutoff = round(mix(fade_scale, texture(noise_texture, UV).r, 0.5));
//Set final albedo (if height in noise is higher than cutoff, use end colour, otherwise do base color)
ALBEDO = mix(texture(end_texture, UV).rgb, texture(base_texture, UV).rgb, step(height_cutoff, 0.0));
}
2D:
shader_type canvas_item;
uniform float fade_scale : hint_range(0.0, 1.0) = 0.5;
uniform sampler2D noise_texture;
uniform sampler2D base_texture : hint_default_black;
uniform sampler2D end_texture : hint_default_white;
void fragment() {
//Get height threshold of noise
float height_cutoff = round(mix(fade_scale, texture(noise_texture, UV).r, 0.5));
//Set final albedo (if height in noise is higher than cutoff, use end colour, otherwise do base color)
COLOR = vec4(mix(texture(end_texture, UV).rgb, texture(base_texture, UV).rgb, step(height_cutoff, 0.0)), 1.0);
}