grunk/src/shaders/gunk/gunk_overlay.gdshader

60 lines
1.5 KiB
Plaintext
Raw Normal View History

shader_type spatial;
render_mode depth_prepass_alpha;
#include "common.gdshaderinc"
group_uniforms gunk_mask;
uniform float edge_bleed = 0.25;
uniform sampler2D gunk_mask;
float bump_sample(vec2 uv, vec3 uvt, float dx, float dy) {
vec2 offset = vec2(dx / pixellation, dy / pixellation);
float height = texture(gunk_noise, uvt + vec3(offset, 0.0)).r;
float mask = texture(gunk_mask, uv + offset / uv_scale).r;
return height * smoothstep(1.0, 0.0, mask);
}
void fragment() {
vec3 uvt = scale_uvt(UV, TIME);
float value = sample_noise(uvt);
ALBEDO = base_albedo(UV, value);
ROUGHNESS = base_roughness(value);
EMISSION = base_emission(UV, value);
SPECULAR = base_specular();
// Build normal map from bump map
float h_center = bump_sample(UV, uvt, 0.0, 0.0);
float h_right = bump_sample(UV, uvt, 1.0, 0.0);
float h_down = bump_sample(UV, uvt, 0.0, 1.0);
float dx = (h_center - h_right) * bump_strength;
float dy = (h_center - h_down) * bump_strength;
vec3 normal_diff_map = normalize(vec3(dx, dy, 1.0));
NORMAL_MAP = normal_diff_map / 2.0 + 0.5;
// add fresnel
vec3 world_normal = mat3(TANGENT, BINORMAL, NORMAL) * normal_diff_map;
EMISSION += rim_glow(
world_normal,
VIEW,
fresnel_gradient,
fresnel_color,
fresnel_power,
fresnel_intensity
);
// add iridescence
ALBEDO += rim_glow(
world_normal,
VIEW,
iridescence_gradient,
iridescence_color,
iridescence_power,
iridescence_intensity
);
// Hardish edge
float mask = texture(gunk_mask, UV).r;
ALPHA = hardstep(1.0 - mask + edge_bleed);
}