Reorganized gunk shader

This commit is contained in:
Rob Kelly 2025-09-03 20:42:15 -06:00
parent 3dc0a0985a
commit 0420a7a465
4 changed files with 64 additions and 32 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,33 +2,41 @@ shader_type spatial;
render_mode depth_prepass_alpha; render_mode depth_prepass_alpha;
group_uniforms gunk_material; group_uniforms gunk_material;
uniform highp sampler3D gunk_noise;
uniform vec3 color_1: source_color = vec3(0.0, 0.03, 0.1); 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 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 emission_color: source_color = vec3(0.25, 0.88, 1.0);
uniform vec3 fresnel_color: source_color = vec3(1.0);
uniform sampler2D fresnel_gradient;
// 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 pixellation = 128.0; uniform float pixellation = 128.0;
uniform float time_pixellation = 30.0; uniform float time_pixellation = 30.0;
uniform float roughness: hint_range(0.0, 1.0) = 0.15; uniform float roughness: hint_range(0.0, 1.0) = 0.15;
uniform float specular_contribution = 0.8; uniform float specular_contribution = 0.8;
uniform float emission_strength = 0.05; uniform float emission_strength = 0.05;
uniform float fresnel_power = 4.0;
uniform float fresnel_intensity = 0.0;
uniform float bump_strength = 1.0; uniform float bump_strength = 1.0;
// Used ONLY by the gunk, does not affect the gunk mask. group_uniforms gunk_mask;
uniform vec2 uv_scale = vec2(1.0);
uniform float time_scale = 1.0;
uniform float edge_bleed = 0.25; uniform float edge_bleed = 0.25;
uniform sampler2D gunk_mask; uniform sampler2D gunk_mask;
uniform highp sampler3D gunk_noise; group_uniforms fresnel;
uniform highp sampler3D gunk_normal_map; uniform vec3 fresnel_color: source_color = vec3(1.0);
uniform sampler2D fresnel_gradient;
uniform float fresnel_power = 4.0;
uniform float fresnel_intensity = 0.0;
group_uniforms iridescence;
uniform vec3 iridescence_color: source_color = vec3(1.0);
uniform sampler2D iridescence_gradient;
uniform float iridescence_power = 4.0;
uniform float iridescence_intensity = 0.0;
group_uniforms overlay; group_uniforms overlay;
uniform sampler2D overlay_albedo: hint_default_transparent, filter_nearest; uniform sampler2D overlay_albedo: hint_default_transparent, filter_nearest;
@ -36,10 +44,17 @@ uniform sampler2D overlay_emission: hint_default_transparent, filter_nearest;
uniform float overlay_emission_scale = 1.0; uniform float overlay_emission_scale = 1.0;
vec3 fresnel_glow(vec3 normal, vec3 view) { vec3 rim_glow(
vec3 normal,
vec3 view,
sampler2D gradient,
vec3 color,
float power,
float intensity
) {
float normal_angle = clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0); float normal_angle = clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0);
vec3 color = texture(fresnel_gradient, vec2(normal_angle, 0.0)).rgb * fresnel_color; vec3 base_color = texture(gradient, vec2(normal_angle, 0.0)).rgb * color;
return pow((1.0 - normal_angle), fresnel_power) * color * fresnel_intensity; return pow((1.0 - normal_angle), power) * base_color * intensity;
} }
float hardstep(float value) { float hardstep(float value) {
@ -49,7 +64,7 @@ float hardstep(float value) {
float bump_sample(vec2 uv, vec3 uvt, float dx, float dy) { float bump_sample(vec2 uv, vec3 uvt, float dx, float dy) {
vec2 offset = vec2(dx / pixellation, dy / pixellation); vec2 offset = vec2(dx / pixellation, dy / pixellation);
float height = texture(gunk_normal_map, uvt + vec3(offset, 0.0)).r; float height = texture(gunk_noise, uvt + vec3(offset, 0.0)).r;
float mask = texture(gunk_mask, uv + offset / uv_scale).r; float mask = texture(gunk_mask, uv + offset / uv_scale).r;
return height * smoothstep(1.0, 0.0, mask); return height * smoothstep(1.0, 0.0, mask);
} }
@ -90,7 +105,24 @@ void fragment() {
// add fresnel // add fresnel
vec3 world_normal = mat3(TANGENT, BINORMAL, NORMAL) * (NORMAL_MAP * 2.0 - 1.0); vec3 world_normal = mat3(TANGENT, BINORMAL, NORMAL) * (NORMAL_MAP * 2.0 - 1.0);
ALBEDO += fresnel_glow(world_normal, VIEW); 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 // Hardish edge
float mask = texture(gunk_mask, UV).r; float mask = texture(gunk_mask, UV).r;

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="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="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="Resource" uid="uid://0i72bf8ip1lx" path="res://src/world/spook_manager.tres" id="3_l0av5"]
[ext_resource type="PackedScene" uid="uid://700gr7k3gqlf" path="res://levels/grunkbeast_test/visual_test/visual_test.tscn" id="4_5kmgb"] [ext_resource type="PackedScene" uid="uid://dc4tts6342cuj" path="res://levels/prop_test/prop_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://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"] [ext_resource type="PackedScene" uid="uid://brknr57xc2cp0" path="res://src/ui/elements/save_icon/save_icon.tscn" id="7_5kmgb"]