GPT is reall good at generating comments and fixing spelling error

This commit is contained in:
2025-12-23 13:28:51 -06:00
parent 9f1555d6e0
commit 9735df3ecb
11 changed files with 917 additions and 355 deletions

View File

@@ -0,0 +1,14 @@
#version 300 es
precision highp float;
in vec3 vColor;
in float vAlpha;
in vec2 vQuadCoord;
out vec4 fragColor;
void main() {
float dist = length(vQuadCoord);
float falloff = smoothstep(1.0, 0.5, dist);
fragColor = vec4(vColor, vAlpha * falloff);
}

View File

@@ -0,0 +1,82 @@
#version 300 es
precision highp float;
in vec2 quadVertex;
in vec2 particleID;
in float trailIndex;
uniform sampler2D stateTexture;
uniform float time;
uniform vec2 resolution;
out vec3 vColor;
out float vAlpha;
out vec2 vQuadCoord;
const float PI = 3.14159265359;
const float r_min = 0.002;
const float r_max = 0.008;
const float sigmoid_k = 20.0;
const float sigmoid_s0 = 0.15;
float sigmoid(float x) {
return 1.0 / (1.0 + exp(-sigmoid_k * (x - sigmoid_s0)));
}
float velocityToRadius(vec2 vel) {
float speed = length(vel);
return r_min + (r_max - r_min) * sigmoid(speed);
}
float streamFunction(vec2 q, float t) {
float x = q.x, y = q.y;
float phi1 = 0.5*t, phi2 = 0.3*t, phi3 = 0.4*t;
float r = length(q - vec2(0.5));
return 0.3*sin(2.0*PI*x + phi1)*sin(2.0*PI*y)
+ 0.25*sin(3.0*PI*x)*sin(3.0*PI*y + phi2)
+ 0.2*sin(4.0*PI*r + phi3)
+ 0.15*(x - 0.5)*(y - 0.5)*sin(0.5*t);
}
float computeVorticity(vec2 q, float t) {
const float h = 0.001;
float psi_c = streamFunction(q, t);
float psi_r = streamFunction(vec2(q.x + h, q.y), t);
float psi_l = streamFunction(vec2(q.x - h, q.y), t);
float psi_u = streamFunction(vec2(q.x, q.y + h), t);
float psi_d = streamFunction(vec2(q.x, q.y - h), t);
float d2psi_dx2 = (psi_r - 2.0*psi_c + psi_l) / (h*h);
float d2psi_dy2 = (psi_u - 2.0*psi_c + psi_d) / (h*h);
return -(d2psi_dx2 + d2psi_dy2);
}
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0/3.0, 1.0/3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
void main() {
vec2 texCoord = (particleID + 0.5) / 16.0;
vec4 state = texture(stateTexture, texCoord);
vec2 pos = state.rg;
vec2 vel = state.ba;
float radius = velocityToRadius(vel);
vec2 aspectRatio = vec2(resolution.y / resolution.x, 1.0);
vec2 screenPos = (pos * 2.0 - 1.0) * aspectRatio;
vec2 offset = quadVertex * radius * aspectRatio;
gl_Position = vec4(screenPos + offset, 0.0, 1.0);
float vorticity = computeVorticity(pos, time);
float hue = mod((vorticity + 3.0) / 6.0, 1.0);
vColor = hsv2rgb(vec3(hue, 0.8, 0.9));
vAlpha = (1.0 - trailIndex / 20.0) * 0.6;
vQuadCoord = quadVertex;
}

View File

@@ -0,0 +1,62 @@
#version 300 es
precision highp float;
in vec2 vTexCoord;
out vec4 fragColor;
uniform sampler2D stateTexture;
uniform float time;
uniform float dt;
const float PI = 3.14159265359;
const float alpha = 0.1;
const float beta = 0.05;
const float k = 2.0;
float streamFunction(vec2 q, float t) {
float x = q.x, y = q.y;
float phi1 = 0.5*t, phi2 = 0.3*t, phi3 = 0.4*t;
float r = length(q - vec2(0.5));
return 0.3*sin(2.0*PI*x + phi1)*sin(2.0*PI*y)
+ 0.25*sin(3.0*PI*x)*sin(3.0*PI*y + phi2)
+ 0.2*sin(4.0*PI*r + phi3)
+ 0.15*(x - 0.5)*(y - 0.5)*sin(0.5*t);
}
float dPsi_dx(vec2 q, float t) {
const float h = 0.001;
return (streamFunction(vec2(q.x + h, q.y), t) -
streamFunction(vec2(q.x - h, q.y), t)) / (2.0 * h);
}
float dPsi_dy(vec2 q, float t) {
const float h = 0.001;
return (streamFunction(vec2(q.x, q.y + h), t) -
streamFunction(vec2(q.x, q.y - h), t)) / (2.0 * h);
}
vec2 derivative(vec2 q, float t) {
vec2 vel = vec2(dPsi_dy(q, t), -dPsi_dx(q, t));
vec2 center_offset = q - vec2(0.5);
vec2 F_boundary = -4.0 * k * vec2(
pow(center_offset.x, 3.0),
pow(center_offset.y, 3.0)
);
return (1.0 - alpha) * vel + beta * F_boundary;
}
void main() {
vec4 state = texture(stateTexture, vTexCoord);
vec2 pos = state.rg;
// RK4 integration
vec2 k1 = derivative(pos, time);
vec2 k2 = derivative(pos + 0.5*dt*k1, time + 0.5*dt);
vec2 k3 = derivative(pos + 0.5*dt*k2, time + 0.5*dt);
vec2 k4 = derivative(pos + dt*k3, time + dt);
vec2 newPos = pos + (dt / 6.0) * (k1 + 2.0*k2 + 2.0*k3 + k4);
vec2 vel = (k1 + 2.0*k2 + 2.0*k3 + k4) / 6.0;
fragColor = vec4(newPos, vel);
}

View File

@@ -0,0 +1,11 @@
#version 300 es
precision highp float;
in vec2 position; // Fullscreen quad vertices
out vec2 vTexCoord;
void main() {
vTexCoord = position * 0.5 + 0.5; // [-1,1] -> [0,1]
gl_Position = vec4(position, 0.0, 1.0);
}