shader_type spatial; render_mode depth_prepass_alpha; group_uniforms gunk_material; 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); uniform vec3 fresnel_color: source_color = vec3(0.25, 0.88, 1.0); uniform float pixellation = 128.0; uniform float time_pixellation = 30.0; uniform float roughness: hint_range(0.0, 1.0) = 0.15; uniform float specular_contribution = 0.8; uniform float emission_strength = 0.05; uniform float normal_scale = 1.0; uniform float fresnel_power = 4.0; uniform float fresnel_intensity = 0.0; uniform float bump_strength = 1.0; // Used ONLY by the gunk, does not affect the gunk mask. uniform vec2 uv_scale = vec2(1.0); uniform vec2 pan_speed = vec2(0.0); uniform float time_scale = 1.0; uniform highp sampler3D gunk_noise; uniform highp sampler3D gunk_normal_map; 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; group_uniforms overlay; uniform sampler2D overlay_albedo: hint_default_transparent, filter_nearest; uniform sampler2D overlay_emission: hint_default_transparent, filter_nearest; uniform float overlay_emission_scale = 1.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; } vec3 fresnel_glow(vec3 normal, vec3 view) { return pow((1.0 - dot(normalize(normal), normalize(view))), fresnel_power) * fresnel_color * fresnel_intensity; } 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; } void fragment() { float local_time = floor(TIME * time_scale * time_pixellation) / time_pixellation; vec2 local_uv = floor(UV * uv_scale * pixellation) / pixellation + local_time * pan_speed; // swirl vec3 uvt = vec3(local_uv.x, local_uv.y, local_time); uvt.x += sin(uvt.y * 1.54 * PI + uvt.z) * cos(uvt.y * 1.31 * PI + uvt.z) * 0.2; uvt.y += cos(uvt.x * 1.74 * PI + uvt.z) * -sin(uvt.y * 1.64 * PI + uvt.z) * 0.2; float value = texture(gunk_noise, uvt).r; vec3 color = mix(color_1, color_2, value); vec3 emission = (1.0 - value) * emission_color * emission_strength; // overlay texture vec4 overlay_color = texture(overlay_albedo, UV); color = mix(color, overlay_color.rgb, overlay_color.a); vec4 overlay_em = texture(overlay_emission, UV); emission = mix(emission, overlay_em.rgb * overlay_emission_scale, overlay_em.a); ALBEDO = color.rgb; ROUGHNESS = value * roughness; EMISSION = emission; SPECULAR = 0.5 * inversesqrt(specular_contribution); // Build normal map from bump map float h_center = texture(gunk_normal_map, uvt).r; float h_right = texture(gunk_normal_map, uvt + vec3(1.0 / pixellation, 0.0, 0.0)).r; float h_down = texture(gunk_normal_map, uvt + vec3(0.0, 1.0 / pixellation, 0.0)).r; float dx = (h_right - h_center) * bump_strength; float dy = (h_down - h_center) * 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_MAP * 2.0 - 1.0); ALBEDO += fresnel_glow(world_normal, VIEW); }