UI and other changes

This commit is contained in:
Forrest 2026-10-07 13:41:38 -04:00
parent 87b5c11fcf
commit 215e24e246
79 changed files with 70023 additions and 2201 deletions

View file

@ -0,0 +1,114 @@
shader_type spatial;
render_mode unshaded;
// MIT License. Made by Leo Peltola
// Inspired by https://threejs.org/examples/webgl_postprocessing_pixel.html
//
// Drawn by ToonLook on a 2 x 2 quad that vertex() pins to the screen (it never culls, so one quad
// outlines whatever camera is current). Needs the Forward+ renderer (the normal-roughness
// buffer). The material draws first among the transparent things, so the effects drawn over the
// farm (zone tints, beams, flames, rings) aren't outlined or painted over.
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap;
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
uniform sampler2D NORMAL_TEXTURE : hint_normal_roughness_texture, filter_nearest;
uniform bool shadows_enabled = true;
uniform bool highlights_enabled = true;
uniform float shadow_strength : hint_range(0.0, 1.0, 0.01) = 0.4;
uniform float highlight_strength : hint_range(0.0, 1.0, 0.01) = 0.1;
uniform vec3 highlight_color : source_color = vec3(1.);
uniform vec3 shadow_color : source_color = vec3(0.0);
varying mat4 model_view_matrix;
float getDepth(vec2 screen_uv, sampler2D depth_texture, mat4 inv_projection_matrix){
// Credit: https://godotshaders.com/shader/depth-modulated-pixel-outline-in-screen-space/
float raw_depth = texture(depth_texture, screen_uv)[0];
vec3 normalized_device_coordinates = vec3(screen_uv * 2.0 - 1.0, raw_depth);
vec4 view_space = inv_projection_matrix * vec4(normalized_device_coordinates, 1.0);
view_space.xyz /= view_space.w;
return -view_space.z;
}
vec3 getPos(float depth, mat4 mvm, mat4 ipm, vec2 suv, mat4 wm, mat4 icm){
vec4 pos = inverse(mvm) * ipm * vec4((suv * 2.0 - 1.0), depth * 2.0 - 1.0, 1.0);
pos.xyz /= (pos.w+0.0001*(1.-abs(sign(pos.w))));
return (pos*icm).xyz+wm[3].xyz;
}
float normalIndicator(vec3 normalEdgeBias, vec3 baseNormal, vec3 newNormal, float depth_diff){
// Credit: https://threejs.org/examples/webgl_postprocessing_pixel.html
float normalDiff = dot(baseNormal - newNormal, normalEdgeBias);
float normalIndicator = clamp(smoothstep(-.01, .01, normalDiff), 0.0, 1.0);
float depthIndicator = clamp(sign(depth_diff * .25 + .0025), 0.0, 1.0);
return (1.0 - dot(baseNormal, newNormal)) * depthIndicator * normalIndicator;
}
void vertex(){
// Full screen, at the near plane (reverse Z), for any camera.
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
model_view_matrix = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
}
void fragment() {
vec2 e = vec2(1./VIEWPORT_SIZE.xy);
// Shadows
float depth_diff = 0.0;
float neg_depth_diff = .5;
if (shadows_enabled) {
float depth = getDepth(SCREEN_UV, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
float du = getDepth(SCREEN_UV+vec2(0., -1.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
float dr = getDepth(SCREEN_UV+vec2(1., 0.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
float dd = getDepth(SCREEN_UV+vec2(0., 1.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
float dl = getDepth(SCREEN_UV+vec2(-1., 0.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
depth_diff += clamp(du - depth, 0., 1.);
depth_diff += clamp(dd - depth, 0., 1.);
depth_diff += clamp(dr - depth, 0., 1.);
depth_diff += clamp(dl - depth, 0., 1.);
neg_depth_diff += depth - du;
neg_depth_diff += depth - dd;
neg_depth_diff += depth - dr;
neg_depth_diff += depth - dl;
neg_depth_diff = clamp(neg_depth_diff, 0., 1.);
neg_depth_diff = clamp(smoothstep(0.5, 0.5, neg_depth_diff)*10., 0., 1.);
depth_diff = smoothstep(0.2, 0.3, depth_diff);
// ALBEDO = vec3(neg_depth_diff);
}
// Highlights
float normal_diff = 0.;
if (highlights_enabled) {
vec3 normal = texture(NORMAL_TEXTURE, SCREEN_UV).rgb * 2.0 - 1.0;
vec3 nu = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(0., -1.)*e).rgb * 2.0 - 1.0;
vec3 nr = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(1., 0.)*e).rgb * 2.0 - 1.0;
vec3 nd = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(0., 1.)*e).rgb * 2.0 - 1.0;
vec3 nl = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(-1., 0.)*e).rgb * 2.0 - 1.0;
vec3 normal_edge_bias = (vec3(1., 1., 1.));
normal_diff += normalIndicator(normal_edge_bias, normal, nu, depth_diff);
normal_diff += normalIndicator(normal_edge_bias, normal, nr, depth_diff);
normal_diff += normalIndicator(normal_edge_bias, normal, nd, depth_diff);
normal_diff += normalIndicator(normal_edge_bias, normal, nl, depth_diff);
normal_diff = smoothstep(0.2, 0.8, normal_diff);
normal_diff = clamp(normal_diff-neg_depth_diff, 0., 1.);
// ALBEDO = vec3(normal_diff);
}
vec3 original_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
vec3 final_highlight_color = mix(original_color, highlight_color, highlight_strength);
vec3 final_shadow_color = mix(original_color, shadow_color, shadow_strength);
vec3 final = original_color;
if (highlights_enabled) {
final = mix(final, final_highlight_color, normal_diff);
}
if (shadows_enabled) {
final = mix(final, final_shadow_color, depth_diff);
}
ALBEDO = final;
float alpha_mask = depth_diff * float(shadows_enabled) + normal_diff * float(highlights_enabled);
ALPHA = clamp((alpha_mask) * 5., 0., 1.);
}

View file

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

View file

@ -1,11 +1,13 @@
shader_type spatial;
// Shared enemy material (one MultiMesh batch), from the prototype's bird shader: wings (local
// |x|) flap with a per-enemy phase from INSTANCE_CUSTOM.r, and a hit flashes the enemy white
// through INSTANCE_CUSTOM.g (1 on the hit, fading). Rim light keeps the near-black crow
// readable against the grass and crops, and night_glow (set by DayNight) adds a faint purple glow
// at night.
// through INSTANCE_CUSTOM.g (1 on the hit, fading). Lit like the rest of the farm
// (toon_light.gdshaderinc), whose rim light keeps the near-black crow readable against the grass
// and crops, and night_glow (set by DayNight) adds a faint purple glow at night.
render_mode cull_disabled;
#include "res://game/resources/toon_light.gdshaderinc"
uniform vec3 base_color : source_color = vec3(0.07, 0.07, 0.09);
uniform float flap_speed = 11.0;
uniform float flap_amount = 0.55;
@ -25,6 +27,4 @@ void fragment() {
EMISSION = vec3(1.0, 0.9, 0.8) * flash * 0.6 + vec3(0.5, 0.28, 0.75) * night_glow * 0.35;
ROUGHNESS = 0.55;
SPECULAR = 0.4;
RIM = 0.8;
RIM_TINT = 0.3;
}

View file

@ -0,0 +1,4 @@
shader_type spatial;
// Toon material (ToonLook): see toon_surface.gdshaderinc and toon_light.gdshaderinc.
#include "res://game/resources/toon_surface.gdshaderinc"

View file

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

View file

@ -0,0 +1,6 @@
shader_type spatial;
// Toon material (ToonLook) for double-sided source materials, e.g. the ithappy farm pack's: see
// toon_surface.gdshaderinc and toon_light.gdshaderinc.
render_mode cull_disabled;
#include "res://game/resources/toon_surface.gdshaderinc"

View file

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

View file

@ -0,0 +1,90 @@
// Toon lighting, shared by toon.gdshader (ToonLook's converted materials) and the enemy shaders
// (thief.gdshader, ufo.gdshader): diffuse light cut into bands, a hard specular spot, and a rim
// light. The Godot 3 toon shader ported to Godot 4: source_color hints, ATTENUATION is a float,
// PI is built in, and LIGHT_COLOR already carries the PI that the "/ PI" divides back out. Omni
// and spot lights fade their rim with distance (a directional light's rim stays whole), and the
// specular and rim powers clamp their base so back faces and grazing angles can't go negative.
uniform bool clamp_diffuse_to_max = false;
uniform int cuts : hint_range(1, 8) = 3;
uniform float wrap : hint_range(-2.0f, 2.0f) = 0.0f;
uniform float steepness : hint_range(1.0f, 8.0f) = 1.0f;
uniform bool use_attenuation = true;
uniform bool use_specular = true;
uniform float specular_strength : hint_range(0.0f, 1.0f) = 1.0f;
uniform float specular_shininess : hint_range(0.0f, 32.0f) = 16.0f;
uniform sampler2D specular_map : source_color;
uniform bool use_rim = true;
uniform float rim_width : hint_range(0.0f, 16.0f) = 8.0f;
uniform vec4 rim_color : source_color = vec4(1.0f);
uniform bool use_ramp = false;
uniform sampler2D ramp : source_color;
uniform bool use_borders = false;
uniform float border_width = 0.01f;
float split_specular(float specular) {
return step(0.5f, specular);
}
void light() {
// Attenuation.
float attenuation = 1.0f;
if (use_attenuation) {
attenuation = ATTENUATION;
}
// Diffuse lighting.
float NdotL = dot(NORMAL, LIGHT);
float diffuse_amount = NdotL + (attenuation - 1.0) + wrap;
diffuse_amount *= steepness;
float cuts_inv = 1.0f / float(cuts);
float diffuse_stepped = clamp(diffuse_amount + mod(1.0f - diffuse_amount, cuts_inv), 0.0f, 1.0f);
// Calculate borders.
float border = 0.0f;
if (use_borders) {
float corr_border_width = length(cross(NORMAL, LIGHT)) * border_width * steepness;
border = step(diffuse_stepped - corr_border_width, diffuse_amount)
- step(1.0 - corr_border_width, diffuse_amount);
}
// Apply diffuse result to different styles.
vec3 diffuse = ALBEDO.rgb * LIGHT_COLOR / PI;
if (use_ramp) {
diffuse *= texture(ramp, vec2(diffuse_stepped * (1.0f - border), 0.0f)).rgb;
} else {
diffuse *= diffuse_stepped * (1.0f - border);
}
if (clamp_diffuse_to_max) {
// Clamp diffuse to max for multiple light sources.
DIFFUSE_LIGHT = max(DIFFUSE_LIGHT, diffuse);
} else {
DIFFUSE_LIGHT += diffuse;
}
// Specular lighting.
if (use_specular) {
vec3 H = normalize(LIGHT + VIEW);
float NdotH = max(dot(NORMAL, H), 0.0f);
float specular_amount = pow(NdotH, specular_shininess * specular_shininess)
* texture(specular_map, UV).r
* attenuation;
specular_amount = split_specular(specular_amount);
SPECULAR_LIGHT += specular_strength * specular_amount * LIGHT_COLOR;
}
// Simple rim lighting.
if (use_rim) {
float NdotV = dot(NORMAL, VIEW);
float rim_light = pow(clamp(1.0 - NdotV, 0.0f, 1.0f), rim_width);
float rim_fade = LIGHT_IS_DIRECTIONAL ? 1.0f : attenuation;
DIFFUSE_LIGHT += rim_light * rim_fade * rim_color.rgb * rim_color.a * LIGHT_COLOR / PI;
}
}

View file

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

View file

@ -0,0 +1,23 @@
// The surface half of ToonLook's converted materials (toon.gdshader, toon_double_sided.gdshader):
// albedo color times albedo texture (times the vertex color when the source material used it),
// lit by toon_light.gdshaderinc. ToonLook copies these from each StandardMaterial3D it replaces.
uniform vec4 albedo : source_color = vec4(1.0f);
uniform sampler2D albedo_texture : source_color, filter_linear_mipmap, repeat_enable;
uniform bool use_vertex_color = false;
uniform vec3 uv1_scale = vec3(1.0f);
uniform vec3 uv1_offset = vec3(0.0f);
#include "res://game/resources/toon_light.gdshaderinc"
void vertex() {
UV = UV * uv1_scale.xy + uv1_offset.xy;
}
void fragment() {
vec3 color = albedo.rgb * texture(albedo_texture, UV).rgb;
if (use_vertex_color) {
color *= COLOR.rgb;
}
ALBEDO = color;
}

View file

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

View file

@ -3,9 +3,12 @@ shader_type spatial;
// EnemySystem.build_ufo_mesh(): each part's color comes from the vertex COLOR, and its glow and
// metalness from UV (x, y). No flap: the saucer turns slowly about its axis and bobs a little,
// with a per-enemy phase from INSTANCE_CUSTOM.r, and the rim lights (glow 1) pulse in a chase
// around the ring. As in thief.gdshader, a hit flashes it white through INSTANCE_CUSTOM.g (1 on
// the hit, fading), a rim light keeps it readable, and night_glow (set by DayNight) adds a faint
// purple glow at night; the lights and the dome glow brighter in the dark.
// around the ring. As in thief.gdshader, it's lit like the rest of the farm
// (toon_light.gdshaderinc), a hit flashes it white through INSTANCE_CUSTOM.g (1 on the hit,
// fading), and night_glow (set by DayNight) adds a faint purple glow at night; the lights and the
// dome glow brighter in the dark.
#include "res://game/resources/toon_light.gdshaderinc"
uniform float spin_speed = 1.2;
uniform float bob_amount = 0.05;
@ -43,6 +46,4 @@ void fragment() {
// The night's purple sits on the hull; the glowing parts keep their own color.
EMISSION = base * glow * glow_energy * (1.0 + night_glow) + vec3(1.0, 0.9, 0.8) * f * 0.6
+ vec3(0.5, 0.28, 0.75) * night_glow * 0.35 * (1.0 - glow);
RIM = 0.6;
RIM_TINT = 0.4;
}