xxxxxxxxxx
51
precision highp float;
uniform sampler2D p_tex;
uniform sampler2D s_tex;
const float N = 600.;
uniform int iFrame;
uniform float dt;
const vec2 speed_offset = vec2(0.5, 0.5);
const float boundary_offset = 0.05;
void main() {
vec2 uv = gl_FragCoord.xy / vec2(N, 1.);
// Initial conditions
if(iFrame < 10) {
vec2 s = vec2(0.05, 0.2);
gl_FragColor = vec4(s + speed_offset, 0., 1.);
return;
}
vec2 p = texture2D(p_tex, uv).xy;
vec2 s = texture2D(s_tex, uv).xy - speed_offset;
// Collisions
for(float i = 0.; i < N; ++i) {
vec2 p_j = texture2D(p_tex, vec2(i/N, 0.5)).xy;
//if(abs(i/N - uv.x) < 0.001) continue;
vec2 dir = p - p_j;
float r = dot(dir, dir);
if(r < 0.08 && r > 0.00000001) {
s += 0.00000001*(dir/(r*r))*dt;
}
}
s *= 0.99;
// Wall collisions
if(p.y > 1. - boundary_offset || p.y < boundary_offset) {
s.y *= -1.;
}
if(p.x > 1. - boundary_offset || p.x < boundary_offset) {
s.x *= -1.;
}
gl_FragColor = vec4(s + speed_offset, 0., 1.);
}