grunk/src/shaders/gunk/gunk.gdshader

69 lines
1.9 KiB
Plaintext
Raw Normal View History

shader_type spatial;
render_mode depth_prepass_alpha;
#include "common.gdshaderinc"
group_uniforms jitter;
uniform mediump float jitter_magnitude = 0.0;
uniform lowp float jitter_time_scale = 0.1;
uniform highp sampler3D jitter_noise;
group_uniforms inflation;
uniform highp float vertex_inflation = 0.0;
uniform highp float inflation_pixellation = 10.0;
void vertex() {
float mixer = VERTEX.x + 0.553 * VERTEX.z + 1.618 * VERTEX.y;
float local_time = floor(TIME * jitter_time_scale * time_pixellation) / time_pixellation;
float sample = texture(jitter_noise, vec3(cos(mixer), sin(mixer), local_time)).r;
float inflation = floor(vertex_inflation * inflation_pixellation) / inflation_pixellation;
float jitter = jitter_magnitude * (sample - 0.5 + inflation);
VERTEX *= 1.0 + jitter;
}
float bump_sample(vec3 uvt, float dx, float dy) {
vec2 offset = vec2(dx / pixellation, dy / pixellation);
return texture(gunk_noise, uvt + vec3(offset, 0.0)).r;
}
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(uvt, 0.0, 0.0);
float h_right = bump_sample(uvt, 1.0, 0.0);
float h_down = bump_sample(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
);
}