2021-11-16 15:15:36 +00:00
|
|
|
#version 310 es
|
|
|
|
|
2022-01-28 22:36:58 +00:00
|
|
|
layout(location = 0) in vec2 a_particlePos_1;
|
|
|
|
layout(location = 1) in vec2 a_particleVel_1;
|
|
|
|
layout(location = 2) in vec2 a_pos_1;
|
2021-11-16 15:15:36 +00:00
|
|
|
struct Particle {
|
|
|
|
vec2 pos;
|
|
|
|
vec2 vel;
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-12-09 15:45:03 +00:00
|
|
|
struct SimParams {
|
|
|
|
float deltaT;
|
|
|
|
float rule1Distance;
|
|
|
|
float rule2Distance;
|
|
|
|
float rule3Distance;
|
|
|
|
float rule1Scale;
|
|
|
|
float rule2Scale;
|
|
|
|
float rule3Scale;
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-12-09 15:45:03 +00:00
|
|
|
struct Particles {
|
|
|
|
Particle particles[5];
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2022-01-28 22:36:58 +00:00
|
|
|
vec4 vert_main(vec2 a_particlePos, vec2 a_particleVel, vec2 a_pos) {
|
|
|
|
float angle = -(atan(a_particleVel.x, a_particleVel.y));
|
|
|
|
vec2 pos = vec2(((a_pos.x * cos(angle)) - (a_pos.y * sin(angle))), ((a_pos.x * sin(angle)) + (a_pos.y * cos(angle))));
|
|
|
|
return vec4((pos + a_particlePos), 0.0f, 1.0f);
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-11-16 15:15:36 +00:00
|
|
|
void main() {
|
2022-04-22 21:25:02 +00:00
|
|
|
gl_PointSize = 1.0;
|
2022-01-28 22:36:58 +00:00
|
|
|
vec4 inner_result = vert_main(a_particlePos_1, a_particleVel_1, a_pos_1);
|
|
|
|
gl_Position = inner_result;
|
|
|
|
gl_Position.y = -(gl_Position.y);
|
|
|
|
gl_Position.z = ((2.0f * gl_Position.z) - gl_Position.w);
|
|
|
|
return;
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|
|
|
|
#version 310 es
|
|
|
|
precision mediump float;
|
|
|
|
|
2022-01-28 22:36:58 +00:00
|
|
|
layout(location = 0) out vec4 value;
|
2021-11-16 15:15:36 +00:00
|
|
|
struct Particle {
|
|
|
|
vec2 pos;
|
|
|
|
vec2 vel;
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-12-09 15:45:03 +00:00
|
|
|
struct SimParams {
|
|
|
|
float deltaT;
|
|
|
|
float rule1Distance;
|
|
|
|
float rule2Distance;
|
|
|
|
float rule3Distance;
|
|
|
|
float rule1Scale;
|
|
|
|
float rule2Scale;
|
|
|
|
float rule3Scale;
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-12-09 15:45:03 +00:00
|
|
|
struct Particles {
|
|
|
|
Particle particles[5];
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2022-01-28 22:36:58 +00:00
|
|
|
vec4 frag_main() {
|
2022-06-01 01:11:59 +00:00
|
|
|
return vec4(1.0f);
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2021-11-16 15:15:36 +00:00
|
|
|
void main() {
|
2022-01-28 22:36:58 +00:00
|
|
|
vec4 inner_result = frag_main();
|
|
|
|
value = inner_result;
|
|
|
|
return;
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|
|
|
|
#version 310 es
|
|
|
|
|
|
|
|
struct Particle {
|
|
|
|
vec2 pos;
|
|
|
|
vec2 vel;
|
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2022-11-02 02:25:38 +00:00
|
|
|
struct SimParams {
|
2021-11-16 15:15:36 +00:00
|
|
|
float deltaT;
|
|
|
|
float rule1Distance;
|
|
|
|
float rule2Distance;
|
|
|
|
float rule3Distance;
|
|
|
|
float rule1Scale;
|
|
|
|
float rule2Scale;
|
|
|
|
float rule3Scale;
|
2022-09-13 19:48:51 +00:00
|
|
|
uint pad;
|
2022-11-02 02:25:38 +00:00
|
|
|
};
|
2022-01-26 16:48:55 +00:00
|
|
|
|
2022-11-02 02:25:38 +00:00
|
|
|
struct Particles {
|
2021-11-16 15:15:36 +00:00
|
|
|
Particle particles[5];
|
2022-11-02 02:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
layout(binding = 0, std140) uniform params_block_ubo {
|
|
|
|
SimParams inner;
|
|
|
|
} params;
|
|
|
|
|
|
|
|
layout(binding = 1, std430) buffer particlesA_block_ssbo {
|
|
|
|
Particles inner;
|
2021-11-16 15:15:36 +00:00
|
|
|
} particlesA;
|
2022-09-02 19:19:10 +00:00
|
|
|
|
2022-11-02 02:25:38 +00:00
|
|
|
layout(binding = 2, std430) buffer particlesA_block_ssbo_1 {
|
|
|
|
Particles inner;
|
2021-11-16 15:15:36 +00:00
|
|
|
} particlesB;
|
2022-09-02 19:19:10 +00:00
|
|
|
|
2022-01-28 22:36:58 +00:00
|
|
|
void comp_main(uvec3 tint_symbol) {
|
2021-11-16 15:15:36 +00:00
|
|
|
uint index = tint_symbol.x;
|
|
|
|
if ((index >= 5u)) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
vec2 vPos = particlesA.inner.particles[index].pos;
|
|
|
|
vec2 vVel = particlesA.inner.particles[index].vel;
|
2022-06-01 01:11:59 +00:00
|
|
|
vec2 cMass = vec2(0.0f);
|
|
|
|
vec2 cVel = vec2(0.0f);
|
|
|
|
vec2 colVel = vec2(0.0f);
|
2021-11-16 15:15:36 +00:00
|
|
|
int cMassCount = 0;
|
|
|
|
int cVelCount = 0;
|
|
|
|
vec2 pos = vec2(0.0f, 0.0f);
|
|
|
|
vec2 vel = vec2(0.0f, 0.0f);
|
|
|
|
{
|
|
|
|
for(uint i = 0u; (i < 5u); i = (i + 1u)) {
|
|
|
|
if ((i == index)) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
pos = particlesA.inner.particles[i].pos.xy;
|
|
|
|
vel = particlesA.inner.particles[i].vel.xy;
|
|
|
|
if ((distance(pos, vPos) < params.inner.rule1Distance)) {
|
2021-11-16 15:15:36 +00:00
|
|
|
cMass = (cMass + pos);
|
|
|
|
cMassCount = (cMassCount + 1);
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
if ((distance(pos, vPos) < params.inner.rule2Distance)) {
|
2021-11-16 15:15:36 +00:00
|
|
|
colVel = (colVel - (pos - vPos));
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
if ((distance(pos, vPos) < params.inner.rule3Distance)) {
|
2021-11-16 15:15:36 +00:00
|
|
|
cVel = (cVel + vel);
|
|
|
|
cVelCount = (cVelCount + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((cMassCount > 0)) {
|
|
|
|
cMass = ((cMass / vec2(float(cMassCount), float(cMassCount))) - vPos);
|
|
|
|
}
|
|
|
|
if ((cVelCount > 0)) {
|
|
|
|
cVel = (cVel / vec2(float(cVelCount), float(cVelCount)));
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
vVel = (((vVel + (cMass * params.inner.rule1Scale)) + (colVel * params.inner.rule2Scale)) + (cVel * params.inner.rule3Scale));
|
2023-03-02 21:28:45 +00:00
|
|
|
vVel = (normalize(vVel) * clamp(length(vVel), 0.0f, 0.10000000149011611938f));
|
2022-11-02 02:25:38 +00:00
|
|
|
vPos = (vPos + (vVel * params.inner.deltaT));
|
2021-11-16 15:15:36 +00:00
|
|
|
if ((vPos.x < -1.0f)) {
|
|
|
|
vPos.x = 1.0f;
|
|
|
|
}
|
|
|
|
if ((vPos.x > 1.0f)) {
|
|
|
|
vPos.x = -1.0f;
|
|
|
|
}
|
|
|
|
if ((vPos.y < -1.0f)) {
|
|
|
|
vPos.y = 1.0f;
|
|
|
|
}
|
|
|
|
if ((vPos.y > 1.0f)) {
|
|
|
|
vPos.y = -1.0f;
|
|
|
|
}
|
2022-11-02 02:25:38 +00:00
|
|
|
particlesB.inner.particles[index].pos = vPos;
|
|
|
|
particlesB.inner.particles[index].vel = vVel;
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
|
|
|
void main() {
|
2022-01-28 22:36:58 +00:00
|
|
|
comp_main(gl_GlobalInvocationID);
|
|
|
|
return;
|
2021-11-16 15:15:36 +00:00
|
|
|
}
|