Moves stuff around, made a main menu and scene mgr

This commit is contained in:
Dan Baker 2025-07-03 14:08:39 +01:00
parent b2e3a3957b
commit 6c023a60a6
37 changed files with 888 additions and 214 deletions

View file

@ -0,0 +1,59 @@
shader_type spatial;
render_mode cull_disabled, diffuse_toon, specular_schlick_ggx;
// Nice Shader by @_Malido ^^
uniform vec3 top_color: source_color;
uniform vec3 bottom_color: source_color;
uniform float ambient_occlusion_factor: hint_range(0.0, 1.0, 0.01) = 0.3;
uniform float specular_strength: hint_range(0.0, 1.0, 0.01) = 0.4;
uniform float player_displacement_strength: hint_range(0.0, 1.0, 0.01) = 0.4;
uniform float player_displacement_size: hint_range(0.0, 2.0, 0.01) = 1.0;
global uniform vec3 wind_direction; // Use a negative y component to give it an extra touch (For displacement effect and noise scroll direction)
global uniform float wind_strength;
uniform sampler2D wind_noise; // Periln FBM Noise looks Best
global uniform float wind_noise_size; // high values dont work well
global uniform float wind_noise_speed;
// Instance the Player Position through a GDScript in the _physics_process
global uniform vec3 player_position;
void vertex() {
vec3 world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
vec3 wind_texture = texture(wind_noise, world_position.xz * wind_noise_size + normalize(-wind_direction.xz) * (TIME + UV.y / 2.5) * wind_noise_speed).rgb;
vec3 wind_vector = (vec4(wind_texture * normalize(wind_direction) * wind_strength, 0.0) * MODEL_MATRIX).xyz;
float player_height = smoothstep(1.0, 0.0, length(player_position.y - world_position.y + 0.3));
vec3 push_direction = vec3(world_position - player_position) * vec3(1 , -0.3 ,1);
float player_position_factor = smoothstep(player_displacement_size, 0.0, length(push_direction));
vec3 player_push_vector = (vec4(normalize(push_direction), 0.0) * MODEL_MATRIX).xyz;
// Apply Player Position displacement
VERTEX += player_push_vector * (1.0 - UV.y) * player_position_factor * player_displacement_strength * player_height;
// Apply Wind displacement linearly
VERTEX += wind_vector * (1.0 - UV.y) * (1.0 - player_position_factor * 0.7);
// A new normal correction, which aligns the normals of the mesh facing upwards no matter the original direction.
NORMAL = vec3(0.0, 1.0, 0.0);
}
void fragment() {
vec3 color = mix(bottom_color, top_color, 1.0 - UV.y);
// Add fake ambient occlusion by darkening the base of the mesh
float ao_fallof = pow(UV.y, 5.0);
vec3 ao_color = bottom_color * (1.0 - ambient_occlusion_factor);
ALBEDO = mix(color, ao_color, ao_fallof);
ROUGHNESS = 0.4;
// Increase the Specular with Grass Height
SPECULAR *= (1.0 - UV.y) * specular_strength;
// Just removing some funny shading
if (!FRONT_FACING) {
NORMAL = -NORMAL;
}
}

View file

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

View file

@ -0,0 +1,23 @@
shader_type spatial;
uniform vec4 base_color : source_color = vec4(0.2, 0.6, 0.1, 1.0);
uniform vec4 variation_color : source_color = vec4(0.4, 0.8, 0.2, 1.0);
uniform float gradient_height : hint_range(0.1, 5.0) = 2.0;
uniform float gradient_offset : hint_range(-2.0, 2.0) = 0.0;
varying vec3 world_position;
void vertex() {
world_position = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz;
}
void fragment() {
// Use world Y position instead of UV
float gradient_factor = (world_position.y + gradient_offset) / gradient_height;
gradient_factor = clamp(gradient_factor, 0.0, 1.0);
vec3 final_color = mix(base_color.rgb, variation_color.rgb, gradient_factor);
ALBEDO = final_color;
ROUGHNESS = 0.8;
METALLIC = 0.0;
}

View file

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

View file

@ -1,90 +1,13 @@
shader_type spatial;
render_mode unshaded;
render_mode cull_front, unshaded;
uniform sampler2D screen_texture : source_color, hint_screen_texture, filter_nearest;
uniform sampler2D depth_texture : source_color, hint_depth_texture, filter_nearest;
uniform sampler2D normal_texture : source_color, hint_normal_roughness_texture, filter_nearest;
uniform float depth_threshold : hint_range(0, 1) = 0.05;
uniform float reverse_depth_threshold : hint_range(0, 1) = 0.25;
uniform float normal_threshold : hint_range(0, 1) = 0.6;
uniform float darken_amount : hint_range(0, 1, 0.01) = 0.3;
uniform float lighten_amount : hint_range(0, 10, 0.01) = 1.5;
uniform vec3 normal_edge_bias = vec3(1, 1, 1);
global uniform vec3 light_direction;
float get_depth(vec2 screen_uv, mat4 inv_projection_matrix) {
float depth = texture(depth_texture, screen_uv).r;
vec3 ndc = vec3(screen_uv * 2.0 - 1.0, depth);
vec4 view = inv_projection_matrix * vec4(ndc, 1.0);
view.xyz /= view.w;
return -view.z;
}
uniform vec3 color : source_color = vec3(0,0,0);
uniform float thickness : hint_range(0.0, 1.0, 0.01) = 0.01;
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
VERTEX += thickness*NORMAL;
}
void fragment() {
float depth = get_depth(SCREEN_UV, INV_PROJECTION_MATRIX);
vec3 normal = texture(normal_texture, SCREEN_UV).xyz * 2.0 - 1.0;
vec2 texel_size = 1.0 / VIEWPORT_SIZE.xy;
vec2 uvs[4];
uvs[0] = vec2(SCREEN_UV.x, min(1.0 - 0.001, SCREEN_UV.y + texel_size.y));
uvs[1] = vec2(SCREEN_UV.x, max(0.0, SCREEN_UV.y - texel_size.y));
uvs[2] = vec2(min(1.0 - 0.001, SCREEN_UV.x + texel_size.x), SCREEN_UV.y);
uvs[3] = vec2(max(0.0, SCREEN_UV.x - texel_size.x), SCREEN_UV.y);
float depth_diff = 0.0;
float depth_diff_reversed = 0.0;
float nearest_depth = depth;
vec2 nearest_uv = SCREEN_UV;
float normal_sum = 0.0;
for (int i = 0; i < 4; i++) {
float d = get_depth(uvs[i], INV_PROJECTION_MATRIX);
depth_diff += depth - d;
depth_diff_reversed += d - depth;
if (d < nearest_depth) {
nearest_depth = d;
nearest_uv = uvs[i];
}
vec3 n = texture(normal_texture, uvs[i]).xyz * 2.0 - 1.0;
vec3 normal_diff = normal - n;
// Edge pixels should yield to the normal closest to the bias direction
float normal_bias_diff = dot(normal_diff, normal_edge_bias);
float normal_indicator = smoothstep(-0.01, 0.01, normal_bias_diff);
normal_sum += dot(normal_diff, normal_diff) * normal_indicator;
}
float depth_edge = step(depth_threshold, depth_diff);
// The reverse depth sum produces depth lines inside of the object, but they don't look as nice as the normal depth_diff
// Instead, we can use this value to mask the normal edge along the outside of the object
float reverse_depth_edge = step(reverse_depth_threshold, depth_diff_reversed);
float indicator = sqrt(normal_sum);
float normal_edge = step(normal_threshold, indicator - reverse_depth_edge);
vec3 original = texture(screen_texture, SCREEN_UV).rgb;
vec3 nearest = texture(screen_texture, nearest_uv).rgb;
mat3 view_to_world_normal_mat = mat3(
INV_VIEW_MATRIX[0].xyz,
INV_VIEW_MATRIX[1].xyz,
INV_VIEW_MATRIX[2].xyz
);
float ld = dot((view_to_world_normal_mat * normal), normalize(light_direction));
vec3 depth_col = nearest * darken_amount;
vec3 normal_col = original * (ld > 0.0 ? darken_amount : lighten_amount);
vec3 edge_mix = mix(normal_col, depth_col, depth_edge);
ALBEDO = mix(original, edge_mix, (depth_edge > 0.0 ? depth_edge : normal_edge));
ALBEDO = color;
}

View file

@ -1 +1 @@
uid://bsemnmdracd4m
uid://c67ldhbce6ro7

View file

@ -0,0 +1,90 @@
shader_type spatial;
render_mode unshaded;
uniform sampler2D screen_texture : source_color, hint_screen_texture, filter_nearest;
uniform sampler2D depth_texture : source_color, hint_depth_texture, filter_nearest;
uniform sampler2D normal_texture : source_color, hint_normal_roughness_texture, filter_nearest;
uniform float depth_threshold : hint_range(0, 1) = 0.05;
uniform float reverse_depth_threshold : hint_range(0, 1) = 0.25;
uniform float normal_threshold : hint_range(0, 1) = 0.6;
uniform float darken_amount : hint_range(0, 1, 0.01) = 0.3;
uniform float lighten_amount : hint_range(0, 10, 0.01) = 1.5;
uniform vec3 normal_edge_bias = vec3(1, 1, 1);
global uniform vec3 light_direction;
float get_depth(vec2 screen_uv, mat4 inv_projection_matrix) {
float depth = texture(depth_texture, screen_uv).r;
vec3 ndc = vec3(screen_uv * 2.0 - 1.0, depth);
vec4 view = inv_projection_matrix * vec4(ndc, 1.0);
view.xyz /= view.w;
return -view.z;
}
void vertex() {
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
}
void fragment() {
float depth = get_depth(SCREEN_UV, INV_PROJECTION_MATRIX);
vec3 normal = texture(normal_texture, SCREEN_UV).xyz * 2.0 - 1.0;
vec2 texel_size = 1.0 / VIEWPORT_SIZE.xy;
vec2 uvs[4];
uvs[0] = vec2(SCREEN_UV.x, min(1.0 - 0.001, SCREEN_UV.y + texel_size.y));
uvs[1] = vec2(SCREEN_UV.x, max(0.0, SCREEN_UV.y - texel_size.y));
uvs[2] = vec2(min(1.0 - 0.001, SCREEN_UV.x + texel_size.x), SCREEN_UV.y);
uvs[3] = vec2(max(0.0, SCREEN_UV.x - texel_size.x), SCREEN_UV.y);
float depth_diff = 0.0;
float depth_diff_reversed = 0.0;
float nearest_depth = depth;
vec2 nearest_uv = SCREEN_UV;
float normal_sum = 0.0;
for (int i = 0; i < 4; i++) {
float d = get_depth(uvs[i], INV_PROJECTION_MATRIX);
depth_diff += depth - d;
depth_diff_reversed += d - depth;
if (d < nearest_depth) {
nearest_depth = d;
nearest_uv = uvs[i];
}
vec3 n = texture(normal_texture, uvs[i]).xyz * 2.0 - 1.0;
vec3 normal_diff = normal - n;
// Edge pixels should yield to the normal closest to the bias direction
float normal_bias_diff = dot(normal_diff, normal_edge_bias);
float normal_indicator = smoothstep(-0.01, 0.01, normal_bias_diff);
normal_sum += dot(normal_diff, normal_diff) * normal_indicator;
}
float depth_edge = step(depth_threshold, depth_diff);
// The reverse depth sum produces depth lines inside of the object, but they don't look as nice as the normal depth_diff
// Instead, we can use this value to mask the normal edge along the outside of the object
float reverse_depth_edge = step(reverse_depth_threshold, depth_diff_reversed);
float indicator = sqrt(normal_sum);
float normal_edge = step(normal_threshold, indicator - reverse_depth_edge);
vec3 original = texture(screen_texture, SCREEN_UV).rgb;
vec3 nearest = texture(screen_texture, nearest_uv).rgb;
mat3 view_to_world_normal_mat = mat3(
INV_VIEW_MATRIX[0].xyz,
INV_VIEW_MATRIX[1].xyz,
INV_VIEW_MATRIX[2].xyz
);
float ld = dot((view_to_world_normal_mat * normal), normalize(light_direction));
vec3 depth_col = nearest * darken_amount;
vec3 normal_col = original * (ld > 0.0 ? darken_amount : lighten_amount);
vec3 edge_mix = mix(normal_col, depth_col, depth_edge);
ALBEDO = mix(original, edge_mix, (depth_edge > 0.0 ? depth_edge : normal_edge));
}

View file

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