cooking even fancier water shader

This commit is contained in:
Lilith Schier 2026-09-01 21:45:23 +02:00
parent a72bf3107a
commit 8eb5a6131f
10 changed files with 125 additions and 46 deletions

View file

@ -48,7 +48,7 @@ public sealed partial class WaterArea : Polygon2D
boundingRect.Size = boundingRect.Size with { Y = boundingRect.Size.Y * FillLevel };
var material = (ShaderMaterial)Material;
material.SetShaderParameter("top_border", ToGlobal(boundingRect.Position).Y);
material.SetShaderParameter("top_border", Mathf.Round(ToGlobal(boundingRect.Position).Y));
if (_collisionShape2D?.Shape is not ConvexPolygonShape2D convexPolygonShape) return;

View file

@ -3,7 +3,6 @@
[ext_resource type="Script" uid="uid://cjnisd5qmc15u" path="res://src/Game.cs" id="1_kc8ui"]
[ext_resource type="PackedScene" uid="uid://bosbrhc3oprau" path="res://src/creatures/birb/birb.tscn" id="2_fc0e3"]
[ext_resource type="PackedScene" uid="uid://ce2k04khaub8n" path="res://src/player/player.tscn" id="2_feb5d"]
[ext_resource type="Texture2D" uid="uid://bmvc4miepnt6k" path="res://src/level/background.png" id="2_y2hwx"]
[ext_resource type="Texture2D" uid="uid://ccsdy0nrbcbv2" path="res://src/level/rain.png" id="3_cdx1q"]
[ext_resource type="Script" uid="uid://cbf6cfj3awmbw" path="res://src/level/Rain.cs" id="4_4bcji"]
[ext_resource type="Theme" uid="uid://bybov1cpwtf7p" path="res://src/base_theme.tres" id="5_bs6l1"]
@ -12,6 +11,14 @@
[ext_resource type="Shader" uid="uid://dxyevul4ilojm" path="res://src/level/water.gdshader" id="9_y2hwx"]
[ext_resource type="PackedScene" uid="uid://llohfwmma2hv" path="res://src/ui/player_hud.tscn" id="11_y2hwx"]
[sub_resource type="Gradient" id="Gradient_uktfx"]
offsets = PackedFloat32Array(0)
colors = PackedColorArray(1, 1, 1, 1)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_y2hwx"]
gradient = SubResource("Gradient_uktfx")
width = 1
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_wqvko"]
texture = ExtResource("7_y2hwx")
0:0/0 = 0
@ -124,6 +131,7 @@ texture = ExtResource("7_y2hwx")
5:5/0/physics_layer_0/polygon_0/points = PackedVector2Array(8, 0, 8, 8, -8, 8, -8, -8)
6:5/0 = 0
6:5/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, 0, 8, 8, -8, 8)
5:4/0 = 0
[sub_resource type="TileSet" id="TileSet_mwb40"]
occlusion_layer_0/light_mask = 1
@ -141,18 +149,42 @@ custom_data_layer_0/name = "damage"
custom_data_layer_0/type = 3
sources/2 = SubResource("TileSetAtlasSource_wqvko")
[sub_resource type="ShaderMaterial" id="ShaderMaterial_uktfx"]
resource_local_to_scene = true
shader = ExtResource("9_y2hwx")
shader_parameter/flow = Vector2(0, 0)
shader_parameter/diffuse_color = Color(0.2632127, 0.30750123, 0.12779748, 1)
shader_parameter/transmission_color = Color(0.675, 0.816, 0.875, 1)
shader_parameter/highlights = Color(1, 1, 1, 0.4)
shader_parameter/top_light = Color(0.7403722, 0.85137874, 0.9053034, 1)
shader_parameter/light_attenuation = 0.42
shader_parameter/top_border = -11.0
shader_parameter/top_ribbon_depth = 1.0
shader_parameter/top_ribbon_color = Color(0.4, 0.4, 0.4, 1)
shader_parameter/depth_band_size = 0.25
[sub_resource type="ShaderMaterial" id="ShaderMaterial_y2hwx"]
resource_local_to_scene = true
shader = ExtResource("9_y2hwx")
shader_parameter/flow = Vector2(0, 0)
shader_parameter/diffuse_color = Color(1, 1, 1, 0.9)
shader_parameter/highlights = Color(1, 1, 1, 0.2)
shader_parameter/top_light = Vector3(1, 1, 1)
shader_parameter/light_attenuation = 1.5
shader_parameter/absorption_color = Color(0.9, 0.016, 0.004, 1)
shader_parameter/top_border = 0.0
shader_parameter/diffuse_color = Color(0, 0, 0, 1)
shader_parameter/transmission_color = Color(0.675, 0.816, 0.875, 1)
shader_parameter/highlights = Color(1, 1, 1, 0.4)
shader_parameter/top_light = Color(1, 1, 1, 1)
shader_parameter/light_attenuation = 0.42
shader_parameter/top_border = -160.0
shader_parameter/top_ribbon_depth = 1.0
shader_parameter/top_ribbon_color = Color(1, 1, 1, 0.7)
shader_parameter/top_ribbon_color = Color(0.4, 0.4, 0.4, 1)
shader_parameter/depth_band_size = 0.25
[sub_resource type="Gradient" id="Gradient_244u8"]
colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_uktfx"]
gradient = SubResource("Gradient_244u8")
fill = 1
fill_from = Vector2(0.50213677, 0.50641024)
fill_to = Vector2(1, 0.5363248)
[node name="Game" type="Node2D" unique_id=1186062666]
script = ExtResource("1_kc8ui")
@ -168,8 +200,9 @@ height = 1.0
[node name="Background" type="Node2D" parent="World" unique_id=2097726518]
[node name="Sky" type="Sprite2D" parent="World/Background" unique_id=1511807768]
self_modulate = Color(0.40812656, 0.55740446, 0.6709966, 1)
texture_repeat = 2
texture = ExtResource("2_y2hwx")
texture = SubResource("GradientTexture1D_y2hwx")
region_enabled = true
region_rect = Rect2(0, 0, 10000, 10000)
metadata/_edit_lock_ = true
@ -199,25 +232,20 @@ Movement = Vector2(-4, 250)
metadata/_edit_lock_ = true
[node name="TileMapLayer" type="TileMapLayer" parent="World/Background" unique_id=462402070]
tile_map_data = PackedByteArray("AADp//3/AgABAAIAAADq//3/AgAAAAIAAADr//3/AgABAAIAAADs//3/AgABAAIAAADt//3/AgABAAIAAADu//3/AgABAAIAAADv//3/AgABAAIAAADw//3/AgAAAAIAAADx//3/AgABAAIAAADy//3/AgABAAIAAADq//z/AgAAAAEAAADw//z/AgAAAAEAAADo//3/AgABAAIAAADn//3/AgABAAIAAADm//3/AgABAAIAAADl//3/AgAAAAIAAADk//3/AgABAAIAAADj//3/AgABAAIAAADi//3/AgABAAIAAADl//z/AgAAAAEAAADi//v/AgABAAAAAADj//v/AgABAAAAAADk//v/AgABAAAAAADl//v/AgAAAAAAAADm//v/AgABAAAAAADn//v/AgABAAAAAADo//v/AgABAAAAAADp//v/AgABAAAAAADq//v/AgAAAAAAAADr//v/AgABAAAAAADs//v/AgABAAAAAADt//v/AgABAAAAAADu//v/AgABAAAAAADv//v/AgABAAAAAADw//v/AgAAAAAAAADx//v/AgABAAAAAAA=")
tile_map_data = PackedByteArray("AADp//3/AgABAAIAAADq//3/AgAAAAIAAADr//3/AgABAAIAAADs//3/AgABAAIAAADt//3/AgABAAIAAADu//3/AgABAAIAAADv//3/AgABAAIAAADw//3/AgAAAAIAAADx//3/AgABAAIAAADy//3/AgABAAIAAADq//z/AgAAAAEAAADw//z/AgAAAAEAAADo//3/AgABAAIAAADn//3/AgABAAIAAADm//3/AgABAAIAAADl//3/AgAAAAIAAADk//3/AgABAAIAAADj//3/AgABAAIAAADi//3/AgABAAIAAADl//z/AgAAAAEAAADi//v/AgABAAAAAADj//v/AgABAAAAAADk//v/AgABAAAAAADl//v/AgAAAAAAAADm//v/AgABAAAAAADn//v/AgABAAAAAADo//v/AgABAAAAAADp//v/AgABAAAAAADq//v/AgAAAAAAAADr//v/AgABAAAAAADs//v/AgABAAAAAADt//v/AgABAAAAAADu//v/AgABAAAAAADv//v/AgABAAAAAADw//v/AgAAAAAAAADx//v/AgABAAAAAADZ/wAAAgAFAAQAAADZ/wEAAgAFAAQAAADa/wAAAgAFAAQAAADa/wEAAgAFAAQAAADb/wAAAgAFAAQAAADb/wEAAgAFAAQAAADc/wAAAgAFAAQAAADc/wEAAgAFAAQAAADd/wAAAgAFAAQAAADd/wEAAgAFAAQAAADe/wAAAgAFAAQAAADe/wEAAgAFAAQAAADf/wAAAgAFAAQAAADf/wEAAgAFAAQAAADg/wAAAgAFAAQAAADg/wEAAgAFAAQAAADh/wAAAgAFAAQAAADh/wEAAgAFAAQAAADi/wAAAgAFAAQAAADi/wEAAgAFAAQAAADj/wAAAgAFAAQAAADj/wEAAgAFAAQAAADk/wAAAgAFAAQAAADk/wEAAgAFAAQAAADl/wAAAgAFAAQAAADl/wEAAgAFAAQAAADm/wAAAgAFAAQAAADm/wEAAgAFAAQAAADn/wAAAgAFAAQAAADn/wEAAgAFAAQAAADo/wAAAgAFAAQAAADo/wEAAgAFAAQAAADZ////AgAFAAQAAADa////AgAFAAQAAADb////AgAFAAQAAADc////AgAFAAQAAADd////AgAFAAQAAADe////AgAFAAQAAADf////AgAFAAQAAADg////AgAFAAQAAADh////AgAFAAQAAADi////AgAFAAQAAADj////AgAFAAQAAADk////AgAFAAQAAADl////AgAFAAQAAADm////AgAFAAQAAADn////AgAFAAQAAADo////AgAFAAQAAAA=")
tile_set = SubResource("TileSet_mwb40")
collision_visibility_mode = 2
[node name="Entities" type="Node2D" parent="World" unique_id=1592804921]
[node name="Player" parent="World/Entities" unique_id=500011307 instance=ExtResource("2_feb5d")]
position = Vector2(-401, -31)
position = Vector2(-832, -112)
[node name="Birb" parent="World/Entities" unique_id=428810294 instance=ExtResource("2_fc0e3")]
position = Vector2(16, 32)
[node name="Overlay" type="Node2D" parent="World" unique_id=59734162]
[node name="WaterArea" parent="World/Overlay" unique_id=469119063 instance=ExtResource("8_uktfx")]
material = SubResource("ShaderMaterial_y2hwx")
position = Vector2(-624, 0)
polygon = PackedVector2Array(0, 0, 256, 0, 256, 32, 0, 32)
[node name="Rain4" type="Sprite2D" parent="World/Overlay" unique_id=940148613]
physics_interpolation_mode = 2
visible = false
@ -237,6 +265,22 @@ tile_map_data = PackedByteArray("AAAYAAsAAgACAAUAAAAYAAoAAgACAAUAAAAYAAkAAgACAAU
tile_set = SubResource("TileSet_mwb40")
collision_visibility_mode = 2
[node name="WaterArea" parent="World/Overlay" unique_id=469119063 instance=ExtResource("8_uktfx")]
material = SubResource("ShaderMaterial_uktfx")
position = Vector2(-624, -16)
polygon = PackedVector2Array(0, 0, 256, 0, 256, 48, 0, 48)
FillLevel = 0.896
[node name="WaterArea2" parent="World/Overlay" unique_id=1559568859 instance=ExtResource("8_uktfx")]
material = SubResource("ShaderMaterial_y2hwx")
position = Vector2(-928, -160)
polygon = PackedVector2Array(-672, 0, 256, 0, 256, 5392, -1584, 5216)
[node name="PointLight2D" type="PointLight2D" parent="World/Overlay" unique_id=1486868699]
position = Vector2(-944, -96)
texture = SubResource("GradientTexture2D_uktfx")
texture_scale = 3.37
[node name="CanvasModulate" type="CanvasModulate" parent="World" unique_id=1975411321]
color = Color(0, 0, 0, 1)

BIN
src/level/tiles.aseprite (Stored with Git LFS)

Binary file not shown.

BIN
src/level/tiles.png (Stored with Git LFS)

Binary file not shown.

View file

@ -1,21 +1,26 @@
shader_type canvas_item;
render_mode blend_mix;
render_mode blend_disabled;
uniform vec2 flow;
uniform vec4 diffuse_color : source_color = vec4(1.0, 1.0, 1.0, 0.9);
uniform vec4 highlights : source_color = vec4(vec3(1.0), 0.2);
uniform vec3 top_light = vec3(1.0);
uniform float light_attenuation = 1.5;
uniform vec3 absorption_color : source_color = vec3(0.9, 0.016, 0.004);
/** Color that is scattered by particles and the like. */
uniform vec3 diffuse_color : source_color = vec3(0.0);
/** The color that doesn't get absorbed and pierces deeper. */
uniform vec3 transmission_color : source_color = vec3(0.675, 0.816, 0.875);
uniform vec4 highlights : source_color = vec4(vec3(1.0), 0.4);
uniform vec3 top_light : source_color = vec3(1.0);
uniform float light_attenuation = 0.42;
uniform float top_border;
uniform float top_ribbon_depth = 1.0;
uniform vec4 top_ribbon_color : source_color = vec4(vec3(1.0), 0.7);
const float depth_band_size = 0.6;
uniform vec3 top_ribbon_color : source_color = vec3(0.4);
uniform float depth_band_size = 0.25;
uniform sampler2D screen : hint_screen_texture, repeat_disable, filter_nearest;
varying vec2 world_position;
varying float depth;
varying vec4 behind_color;
#include "res://src/shaders/noise3D.gdshaderinc"
#include "res://src/shaders/vertex_fun.gdshaderinc"
void vertex() {
world_position = (MODEL_MATRIX * vec4(VERTEX, 0.0, 1.0)).xy;
@ -41,15 +46,20 @@ void fragment() {
if (depth < 0.0) {
COLOR = vec4(0.0);
} else {
float ribboned_depth = exp(round(log(depth) / depth_band_size) * depth_band_size);
vec3 light = top_light * exp(-light_attenuation*absorption_color*ribboned_depth);
float light_intensity = (light.r + light.g + light.b) / 3.0;
float extra_transparency = sqrt(light_intensity) * 0.9;
vec3 raw_color = diffuse_color.rgb * light;
float ribboned_depth = exp(round(log(depth) * light_attenuation / depth_band_size) * depth_band_size);
behind_color = textureLod(screen, SCREEN_UV + round(wobble(world_position / vec2(512.0, 64.0), 0.3, 2.0, 2) * vec2(1.0, 0.25)) * SCREEN_PIXEL_SIZE, 0.0);
vec3 actual_light = top_light * exp(-light_attenuation*(1.0-transmission_color + diffuse_color.rgb)*ribboned_depth);
vec3 scattered_light = actual_light * diffuse_color;
float scatter_alpha = max(scattered_light.r, max(scattered_light.g, scattered_light.b));
vec3 raw_color = actual_light;
raw_color = mix(raw_color.rgb, highlights.rgb, x*highlights.a);
COLOR = vec4(raw_color, diffuse_color.a * (1.0-extra_transparency));
COLOR = vec4(behind_color.rgb * actual_light + scattered_light, 1.0);
if (depth < top_ribbon_depth) {
COLOR = vec4(mix(COLOR.rgb, top_ribbon_color.rgb, top_ribbon_color.a), clamp(top_ribbon_color.a, COLOR.a, 1.0));
COLOR.rgb += top_ribbon_color.rgb;
}
}
}
void light() {
LIGHT = behind_color * 0.5;
}

View file

@ -7,10 +7,14 @@
resource_local_to_scene = true
shader = ExtResource("1_vkr3x")
shader_parameter/flow = Vector2(0, 0)
shader_parameter/water = Color(0.31764707, 0.5921569, 0.6431373, 0.64705884)
shader_parameter/highlights = Color(0.51546186, 0.75253254, 0.7743172, 1)
shader_parameter/diffuse_color = Color(1, 1, 1, 0.9)
shader_parameter/highlights = Color(1, 1, 1, 0.4)
shader_parameter/top_light = Color(1, 1, 1, 1)
shader_parameter/light_attenuation = 1.5
shader_parameter/absorption_color = Color(0.09, 0.01, 0.004, 1)
shader_parameter/top_border = 0.0
shader_parameter/light_band_size = 8.0
shader_parameter/top_ribbon_depth = 1.0
shader_parameter/top_ribbon_color = Color(1, 1, 1, 0.7)
[node name="WaterArea" type="Polygon2D" unique_id=469119063]
material = SubResource("ShaderMaterial_7iiff")

View file

@ -5,6 +5,15 @@
[ext_resource type="Script" uid="uid://ce3atuwxo8fvb" path="res://src/combat/Hurtbox.cs" id="4_5f2sf"]
[ext_resource type="Script" uid="uid://b4k42r866lkut" path="res://src/combat/Hitbox.cs" id="4_244u8"]
[sub_resource type="Gradient" id="Gradient_244u8"]
colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1)
[sub_resource type="GradientTexture2D" id="GradientTexture2D_2j2mp"]
gradient = SubResource("Gradient_244u8")
fill = 1
fill_from = Vector2(0.50213677, 0.50641024)
fill_to = Vector2(1, 0.5363248)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_jiejy"]
size = Vector2(8, 28)
@ -351,6 +360,12 @@ floor_max_angle = 0.87441
floor_snap_length = 3.0
script = ExtResource("1_244u8")
[node name="PointLight2D" type="PointLight2D" parent="." unique_id=60527513]
visible = false
position = Vector2(0, -13)
texture = SubResource("GradientTexture2D_2j2mp")
texture_scale = 3.37
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=84142517]
visible = false
position = Vector2(0, -14)
@ -447,6 +462,7 @@ debug_color = Color(0.99430805, 0, 0.2314094, 0.41960785)
[node name="SubmersedSensor" type="Area2D" parent="." unique_id=1595680866]
unique_name_in_owner = true
visible = false
collision_layer = 0
collision_mask = 32

View file

@ -1,10 +1,15 @@
#include "res://src/shaders/noise3D.gdshaderinc"
vec2 wobble(vec2 p, float f, float a) {
vec2 wobble(vec2 p, float f, float a, int o) {
float t = TIME * f;
vec2 offset = vec2(
snoise(vec3(p / 64.0, t)),
snoise(vec3(p / 64.0, -t))
);
vec2 offset = vec2(0.0);
{
float mult = 1.0;
for (int i = 0; i < o; i++) {
offset += vec2(snoise(vec3(p * mult, t)),snoise(vec3(p * mult, -t))) / mult;
mult *= 2.0;
}
}
return a * offset;
}

View file

@ -12,7 +12,7 @@ uniform float amplitude = 1.0;
#include "res://src/shaders/vertex_fun.gdshaderinc"
void vertex() {
VERTEX += wobble(VERTEX, frequency, amplitude);
VERTEX += wobble(VERTEX / 64.0, frequency, amplitude, 1);
}
void fragment() {

View file

@ -6,5 +6,5 @@ uniform float amplitude = 1.0;
#include "res://src/shaders/vertex_fun.gdshaderinc"
void vertex() {
VERTEX += wobble(VERTEX, frequency, amplitude);
VERTEX += wobble(VERTEX / 64.0, frequency, amplitude, 1);
}