Fixed grunk mask edge softening

This commit is contained in:
Rob Kelly 2025-09-03 15:19:06 -06:00
parent 61fb827435
commit acf5e8fec2
10 changed files with 241 additions and 38 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,98 @@
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 float time_scale = 1.0;
uniform float edge_bleed = 0.25;
uniform sampler2D gunk_mask;
uniform highp sampler3D gunk_noise;
uniform highp sampler3D gunk_normal_map;
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;
vec3 fresnel_glow(vec3 normal, vec3 view) {
float normal_angle = dot(normalize(normal), normalize(view));
return pow((1.0 - clamp(normal_angle, 0.0, 1.0)), 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;
}
float bump_sample(vec2 uv, vec3 uvt, float dx, float dy) {
vec2 offset = vec2(dx / pixellation, dy / pixellation);
float height = texture(gunk_normal_map, 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() {
vec2 local_uv = floor(UV * uv_scale * pixellation) / pixellation;
float local_time = floor(TIME * time_scale * time_pixellation) / time_pixellation;
// 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 = 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;
ALBEDO = 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);
// Hardish edge
//float mask = texture(gunk_mask, UV).r;
//ALPHA = hardstep(1.0 - mask + edge_bleed);
}

View File

@ -0,0 +1 @@
uid://b6yhubgom14f7

View File

@ -56,11 +56,6 @@ 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;

View File

@ -46,6 +46,13 @@ float hardstep(float value) {
return 0.5 * tanh( (20.0 * x - 10.0) * inversesqrt(x - x * x) ) + 0.5;
}
float bump_sample(vec2 uv, vec3 uvt, float dx, float dy) {
vec2 offset = vec2(dx / pixellation, dy / pixellation);
float height = texture(gunk_normal_map, 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() {
vec2 local_uv = floor(UV * uv_scale * pixellation) / pixellation;
float local_time = floor(TIME * time_scale * time_pixellation) / time_pixellation;
@ -71,26 +78,20 @@ void fragment() {
EMISSION = emission;
SPECULAR = 0.5 * inversesqrt(specular_contribution);
float mask = texture(gunk_mask, UV).r;
float edge_soften = smoothstep(1.0, 0.0, mask);
// 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));
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;
// soften edges
NORMAL_MAP *= edge_soften;
// add fresnel
vec3 world_normal = mat3(TANGENT, BINORMAL, NORMAL) * (NORMAL_MAP * 2.0 - 1.0);
ALBEDO += fresnel_glow(world_normal, VIEW);
// Hardish edge
float mask = texture(gunk_mask, UV).r;
ALPHA = hardstep(1.0 - mask + edge_bleed);
}

View File

@ -52,13 +52,18 @@ shader = ExtResource("4_q7kpl")
shader_parameter/color_1 = Color(0, 0.03, 0.1, 1)
shader_parameter/color_2 = Color(0, 0.1, 0.3, 1)
shader_parameter/emission_color = Color(0.25, 0.88, 1, 1)
shader_parameter/fresnel_color = Color(0.25, 0.88, 1, 1)
shader_parameter/pixellation = 128.0
shader_parameter/time_pixellation = 30.0
shader_parameter/roughness = 0.15
shader_parameter/specular_contribution = 0.8
shader_parameter/emission_strength = 0.02
shader_parameter/normal_scale = 1.0
shader_parameter/fresnel_power = 4.0
shader_parameter/fresnel_intensity = 0.0
shader_parameter/bump_strength = 10.0
shader_parameter/uv_scale = Vector2(2, 2)
shader_parameter/pan_speed = Vector2(0, 0)
shader_parameter/time_scale = 0.2
shader_parameter/gunk_noise = SubResource("NoiseTexture3D_2roq2")
shader_parameter/gunk_normal_map = SubResource("NoiseTexture3D_fk1xc")
@ -116,13 +121,18 @@ shader = ExtResource("4_q7kpl")
shader_parameter/color_1 = Color(0, 0.03, 0.1, 1)
shader_parameter/color_2 = Color(0, 0.1, 0.3, 1)
shader_parameter/emission_color = Color(0.66, 0.943333, 1, 1)
shader_parameter/fresnel_color = Color(0.25, 0.88, 1, 1)
shader_parameter/pixellation = 128.0
shader_parameter/time_pixellation = 30.0
shader_parameter/roughness = 0.15
shader_parameter/specular_contribution = 0.8
shader_parameter/emission_strength = 0.2
shader_parameter/normal_scale = 1.0
shader_parameter/fresnel_power = 4.0
shader_parameter/fresnel_intensity = 0.0
shader_parameter/bump_strength = 10.0
shader_parameter/uv_scale = Vector2(2, 2)
shader_parameter/pan_speed = Vector2(0, 0)
shader_parameter/time_scale = 0.2
shader_parameter/gunk_noise = SubResource("NoiseTexture3D_pp7wn")
shader_parameter/gunk_normal_map = SubResource("NoiseTexture3D_c5snp")

View File

@ -4,7 +4,7 @@
[ext_resource type="Resource" uid="uid://tgac5tnfx56r" path="res://src/world/world_manager.tres" id="2_5kmgb"]
[ext_resource type="PackedScene" uid="uid://byvjsvavbg5xe" path="res://src/ui/menus/pause_menu/pause_menu.tscn" id="2_6fy3g"]
[ext_resource type="Resource" uid="uid://0i72bf8ip1lx" path="res://src/world/spook_manager.tres" id="3_l0av5"]
[ext_resource type="PackedScene" uid="uid://dc4tts6342cuj" path="res://levels/prop_test/prop_test.tscn" id="4_5kmgb"]
[ext_resource type="PackedScene" uid="uid://b8rv6dg4tgaeb" path="res://levels/mechanic_test/mechanic_test.tscn" id="4_5kmgb"]
[ext_resource type="PackedScene" uid="uid://c0uitm5cg88h1" path="res://src/ui/menus/kill_screen/kill_screen.tscn" id="6_l0av5"]
[ext_resource type="PackedScene" uid="uid://brknr57xc2cp0" path="res://src/ui/elements/save_icon/save_icon.tscn" id="7_5kmgb"]