grunk/src/shaders/gunk.gdshader

60 lines
1.6 KiB
Plaintext
Raw Normal View History

2025-03-01 14:40:02 -07:00
shader_type spatial;
2025-03-02 17:39:17 -07:00
render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, sss_mode_skin;
2025-03-01 14:40:02 -07:00
2025-03-02 17:39:17 -07:00
uniform vec3 color_1: source_color = vec3(0.0, 0.03, 0.1);
uniform vec3 color_2: source_color = vec3(0.0, 0.1, 0.3);
uniform vec3 emission_color: source_color = vec3(0.25, 0.88, 1.0);
2025-03-02 16:54:22 -07:00
2025-03-02 17:39:17 -07:00
uniform float pixellation = 50.0;
2025-03-02 16:54:22 -07:00
2025-03-01 14:40:02 -07:00
uniform float roughness: hint_range(0.0, 1.0) = 0.15;
2025-03-02 17:39:17 -07:00
uniform float specular_contribution = 0.8;
uniform float emission_strength = 0.05;
2025-03-01 14:40:02 -07:00
2025-03-02 14:12:17 -07:00
// Used ONLY by the gunk, does not affect the gunk mask.
uniform vec2 uv_scale = vec2(1.0);
2025-03-02 14:57:24 -07:00
uniform float time_scale = 1.0;
2025-03-02 14:12:17 -07:00
uniform float edge_bleed = 0.1;
2025-03-01 14:40:02 -07:00
uniform sampler2D gunk_mask;
2025-03-02 14:57:24 -07:00
uniform highp sampler3D gunk_noise;
uniform highp sampler3D gunk_normal_map;
2025-03-01 14:40:02 -07:00
2025-03-02 14:12:17 -07:00
float hardstep(float value) {
float x = clamp(value, 0.0, 1.0);
return 0.5 * tanh( (20.0 * x - 10.0) * inversesqrt(x - x * x) ) + 0.5;
}
2025-03-01 14:40:02 -07:00
void fragment() {
2025-03-02 16:54:22 -07:00
vec2 local_uv = floor(UV * uv_scale * pixellation) / pixellation;
2025-03-02 14:57:24 -07:00
vec3 uvt = vec3(local_uv.x, local_uv.y, TIME * time_scale);
float value = texture(gunk_noise, uvt).r;
2025-03-02 17:39:17 -07:00
vec3 color = mix(color_1, color_2, value);
2025-03-01 14:40:02 -07:00
ALBEDO = color.rgb;
2025-03-02 17:39:17 -07:00
ROUGHNESS = value * roughness;
EMISSION = (1.0 - value) * emission_color * emission_strength;
SPECULAR = 0.5 * inversesqrt(specular_contribution);
2025-03-02 14:57:24 -07:00
NORMAL_MAP = texture(gunk_normal_map, uvt).xyz;
2025-03-02 14:12:17 -07:00
float mask = texture(gunk_mask, UV).r;
// soften edges
NORMAL_MAP *= smoothstep(1.0, 0.0, mask);
/*
// Hard edge
if(mask + edge_bleed < 0.5) {
ALPHA = 1.0;
} else {
ALPHA = 0.0;
}
*/
// Hardish edge
ALPHA = hardstep(1.0 - mask + edge_bleed);
2025-03-01 14:40:02 -07:00
}