feat: add wake, rose, terrain, pathfinding, gameover, clouds, enemy shooting, variable bird speed refactor: some things

This commit is contained in:
2026-09-19 13:17:46 +02:00
parent c80b4887e9
commit a2ffb45fc5
49 changed files with 3002 additions and 1178 deletions
+69
View File
@@ -0,0 +1,69 @@
#version 330
in vec2 fragWorldPos;
out vec4 finalColor;
uniform float time;
uniform float cloudScale = 0.018;
uniform vec2 driftDirection = vec2(1.0, 0.35);
uniform float driftSpeed = 4.0;
uniform float coverage = 0.99;
uniform float softness = 0.12;
uniform vec4 cloudColor = vec4(1.0, 1.0, 1.0, 0.8);
uniform bool isShadowPass = false;
uniform vec2 shadowWorldOffset = vec2(48.0, 72.0);
uniform vec4 shadowColor = vec4(0.0, 0.05, 0.1, 0.35);
vec2 pixelizeCoordinates(vec2 coordinates)
{
return floor(coordinates);
}
float hash(vec2 p)
{
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float valueNoise(vec2 p)
{
vec2 i = floor(p);
vec2 f = fract(p);
float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}
float cloudField(vec2 p)
{
float value = 0.0;
float amplitude = 0.5;
for (int i = 0; i < 4; i++) {
value += amplitude * valueNoise(p);
p *= 2.0;
amplitude *= 0.5;
}
return value;
}
void main()
{
vec2 worldPos = fragWorldPos;
if (isShadowPass) {
worldPos -= shadowWorldOffset;
}
vec2 pixelized = pixelizeCoordinates(worldPos);
vec2 drift = normalize(driftDirection) * time * driftSpeed;
float density = cloudField((pixelized + drift) * cloudScale);
float mask = smoothstep(coverage - softness, coverage + softness, density);
vec4 layerColor = isShadowPass ? shadowColor : cloudColor;
finalColor = vec4(layerColor.rgb, layerColor.a * mask);
}
+14
View File
@@ -0,0 +1,14 @@
#version 330
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
out vec2 fragWorldPos;
uniform mat4 mvp;
void main()
{
fragWorldPos = vertexPosition.xy;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}
+45
View File
@@ -0,0 +1,45 @@
#version 330
uniform sampler2D texture0;
uniform vec2 resolution;
uniform float time;
// Screen-space UV of the sun — kept off in a corner like a low sun rather
// than dead center, so the rays read as directional light rather than a
// starburst sitting on top of the view. This shader samples the already-
// rendered scene texture (RenderPostFX draws it via a source rect with a
// negative height to correct raylib's render-texture V-flip for texture0
// itself), but fragTexCoord's V still runs top-of-screen=0 in that same
// flipped sense — so a Y near 0 here actually lands near the BOTTOM of
// what's on screen; 0.88 is what puts the sun near the top.
uniform vec2 sunScreenPos = vec2(0.82, 0.88);
uniform float rayCount = 10.0;
uniform float raySharpness = 3.0;
uniform float rayStrength = 0.35;
uniform float raySpeed = 0.03;
in vec2 fragTexCoord;
out vec4 finalColor;
void main()
{
vec2 uv = fragTexCoord;
vec4 baseColor = texture(texture0, uv);
// Cheap screen-space light shafts: no scene depth/occlusion to sample,
// so this fakes them as angular streaks radiating from the sun position
// that fade out with distance, rather than true raymarched shafts.
vec2 aspectFix = vec2(resolution.x / resolution.y, 1.0);
vec2 toSun = (uv - sunScreenPos) * aspectFix;
float dist = length(toSun);
float angle = atan(toSun.y, toSun.x);
float streaks = sin(angle * rayCount + time * raySpeed) * 0.5 + 0.5;
streaks = pow(streaks, raySharpness);
float falloff = clamp(1.0 - dist * 0.9, 0.0, 1.0);
falloff *= falloff;
vec3 rayColor = vec3(1.0, 0.92, 0.75) * streaks * falloff * rayStrength;
finalColor = vec4(baseColor.rgb + rayColor, baseColor.a);
}
+53
View File
@@ -0,0 +1,53 @@
#version 330
in vec2 fragTexCoord;
in vec2 fragWorldPos;
out vec4 finalColor;
uniform sampler2D texture0;
uniform float time;
uniform vec4 foamColor = vec4(0.96, 0.99, 1.0, 1.0);
uniform float foamAnimSpeed = 1.6;
uniform float foamNoiseScale = 0.55;
float hash(vec2 p)
{
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float valueNoise(vec2 p)
{
vec2 i = floor(p);
vec2 f = fract(p);
float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}
void main()
{
vec4 tex = texture(texture0, fragTexCoord);
if (tex.a >= 0.999) {
finalColor = tex;
return;
}
if (tex.a <= 0.001) {
discard;
}
vec2 pixelized = floor(fragWorldPos);
float n1 = valueNoise(pixelized * foamNoiseScale + vec2(time * foamAnimSpeed, 0.0));
float n2 = valueNoise(pixelized * foamNoiseScale * 2.1 - vec2(0.0, time * foamAnimSpeed * 0.7));
float churn = n1 * 0.6 + n2 * 0.4;
float mask = tex.a * smoothstep(0.2, 0.7, churn + tex.a * 0.6);
finalColor = vec4(foamColor.rgb, foamColor.a * mask);
}
+16
View File
@@ -0,0 +1,16 @@
#version 330
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
out vec2 fragTexCoord;
out vec2 fragWorldPos;
uniform mat4 mvp;
void main()
{
fragTexCoord = vertexTexCoord;
fragWorldPos = vertexPosition.xy;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}
+79
View File
@@ -0,0 +1,79 @@
#version 330
in vec2 fragWorldPos;
out vec4 finalColor;
uniform float time;
#define TRAIL_POINTS 12
uniform vec2 trailPoints[TRAIL_POINTS];
uniform float trailAges[TRAIL_POINTS];
uniform int trailCount;
uniform float wakeIntensity;
uniform vec4 foamColor = vec4(0.96, 0.99, 1.0, 1.0);
uniform float wakeHalfWidthStart = 2.0;
uniform float wakeHalfWidthEnd = 7.0;
uniform float foamNoiseScale = 0.5;
uniform float foamAnimSpeed = 2.4;
float hash(vec2 p)
{
p = fract(p * vec2(123.34, 456.21));
p += dot(p, p + 45.32);
return fract(p.x * p.y);
}
float valueNoise(vec2 p)
{
vec2 i = floor(p);
vec2 f = fract(p);
float a = hash(i);
float b = hash(i + vec2(1.0, 0.0));
float c = hash(i + vec2(0.0, 1.0));
float d = hash(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
}
float segmentDistance(vec2 p, vec2 a, vec2 b, out float segT)
{
vec2 ab = b - a;
float lenSq = dot(ab, ab);
segT = lenSq > 0.0001 ? clamp(dot(p - a, ab) / lenSq, 0.0, 1.0) : 0.0;
vec2 closest = a + ab * segT;
return length(p - closest);
}
void main()
{
if (trailCount < 2) discard;
float bestDist = 1e9;
float bestAge = 0.0;
for (int i = 0; i < TRAIL_POINTS - 1; i++) {
if (i >= trailCount - 1) break;
float segT;
float d = segmentDistance(fragWorldPos, trailPoints[i], trailPoints[i + 1], segT);
if (d < bestDist) {
bestDist = d;
bestAge = mix(trailAges[i], trailAges[i + 1], segT);
}
}
float halfWidth = mix(wakeHalfWidthStart, wakeHalfWidthEnd, bestAge);
if (bestDist > halfWidth) discard;
float edgeFade = 1.0 - smoothstep(halfWidth * 0.55, halfWidth, bestDist);
float ageFade = 1.0 - bestAge;
float envelope = edgeFade * ageFade;
vec2 pixelized = floor(fragWorldPos);
float n = valueNoise(pixelized * foamNoiseScale + vec2(time * foamAnimSpeed, 0.0));
float churn = mix(0.55, 1.0, n);
float speedScale = mix(0.65, 1.0, wakeIntensity);
float mask = envelope * churn * speedScale;
finalColor = vec4(foamColor.rgb, foamColor.a * mask);
}
+14
View File
@@ -0,0 +1,14 @@
#version 330
in vec3 vertexPosition;
in vec2 vertexTexCoord;
in vec4 vertexColor;
out vec2 fragWorldPos;
uniform mat4 mvp;
void main()
{
fragWorldPos = vertexPosition.xy;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}
+9 -23
View File
@@ -1,17 +1,12 @@
#version 330
// -----------------------------
// Inputs
in vec2 fragTexCoord;
in vec4 fragColor;
in vec2 fragWorldPos;
// -----------------------------
// Outputs
out vec4 finalColor;
// -----------------------------
// Uniforms
uniform sampler2D texture0; // main texture
uniform sampler2D texture0;
uniform sampler2D waterDepthGradient;
uniform sampler2D causticTexture;
uniform sampler2D causticHighlightTexture;
@@ -24,6 +19,7 @@ uniform sampler2D foamTexture;
uniform float aspectRatio = 1.0;
uniform float pixelization = 2048.0;
uniform float noiseCoordinateScale = 2048.0;
uniform vec4 causticColor = vec4(0.455, 0.773, 0.765, 1.0);
uniform vec4 causticHighlightColor = vec4(0.741, 0.894, 0.898, 1.0);
@@ -46,9 +42,6 @@ uniform float generalTransparency = 1.0;
uniform float time;
// -----------------------------
// Helper functions
vec2 blendSubtract_vec2(vec2 base, vec2 blend, float opacity)
{
vec2 result = base - blend;
@@ -80,9 +73,6 @@ vec2 applyAspectRatio(vec2 coordinates)
return vec2(coordinates.x, coordinates.y * aspectRatio);
}
// -----------------------------
// Shader layers
vec4 caustics(vec2 pixelizedCoordinates)
{
vec4 causticNoise = texture(causticNoiseTexture, time * causticSpeed + pixelizedCoordinates);
@@ -111,27 +101,23 @@ vec4 foam(vec2 pixelizedCoordinates, vec4 mainTexColor)
return vec4(colorizedFoam.rgb, colorizedFoam.a * intensity);
}
// -----------------------------
// Main fragment
void main()
{
vec2 pixelizedCoordinates = pixelizeCoordinates(applyAspectRatio(fragTexCoord));
vec2 pixelizedCoordinates = pixelizeCoordinates(fragWorldPos / noiseCoordinateScale);
vec4 mainTex = texture(texture0, fragTexCoord);
vec4 depthBasedWaterColor = texture(waterDepthGradient, vec2(1.0 - mainTex.b, 1.0));
vec4 finalCaustics = caustics(pixelizedCoordinates);
vec4 finalCaustics = caustics(pixelizedCoordinates);
vec4 finalSpecular = specular(pixelizedCoordinates);
vec4 finalFoam = foam(pixelizedCoordinates, mainTex);
vec4 waterWithCausticLayer = mix(depthBasedWaterColor, finalCaustics, finalCaustics.a);
vec4 waterWithCausticAndSpecularLayer = mix(waterWithCausticLayer, finalSpecular, ceil(finalCaustics.a) * finalSpecular.a);
vec4 waterWithCausticAndSpecularAndFoamLayer = mix(waterWithCausticAndSpecularLayer, finalFoam, finalFoam.a);
float outline = mainTex.a * mainTex.r;
vec4 finalOutlineColor = outline * outlineColor;
vec4 finalRGBColor = mix(waterWithCausticAndSpecularAndFoamLayer, finalOutlineColor, outline);
finalColor = vec4(finalRGBColor.rgb, mainTex.b * generalTransparency);
}
+2 -1
View File
@@ -5,6 +5,7 @@ in vec4 vertexColor;
out vec2 fragTexCoord;
out vec4 fragColor;
out vec2 fragWorldPos;
uniform mat4 mvp;
@@ -12,6 +13,6 @@ void main()
{
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
fragWorldPos = vertexPosition.xy;
gl_Position = mvp * vec4(vertexPosition, 1.0);
}