#version 310 es

layout(location = 0) in vec2 vert_main_loc0_Input;
layout(location = 1) in vec2 vert_main_loc1_Input;
layout(location = 2) in vec2 vert_main_loc2_Input;
vec4 vert_main_inner(vec2 a_particlePos, vec2 a_particleVel, vec2 a_pos) {
  float angle = -(atan(a_particleVel[0u], a_particleVel[1u]));
  float v = (a_pos[0u] * cos(angle));
  float v_1 = (v - (a_pos[1u] * sin(angle)));
  float v_2 = (a_pos[0u] * sin(angle));
  vec2 pos = vec2(v_1, (v_2 + (a_pos[1u] * cos(angle))));
  return vec4((pos + a_particlePos), 0.0f, 1.0f);
}
void main() {
  gl_Position = vert_main_inner(vert_main_loc0_Input, vert_main_loc1_Input, vert_main_loc2_Input);
  gl_Position[1u] = -(gl_Position.y);
  gl_Position[2u] = ((2.0f * gl_Position.z) - gl_Position.w);
  gl_PointSize = 1.0f;
}
#version 310 es
precision highp float;
precision highp int;

layout(location = 0) out vec4 frag_main_loc0_Output;
vec4 frag_main_inner() {
  return vec4(1.0f);
}
void main() {
  frag_main_loc0_Output = frag_main_inner();
}
#version 310 es


struct SimParams {
  float deltaT;
  float rule1Distance;
  float rule2Distance;
  float rule3Distance;
  float rule1Scale;
  float rule2Scale;
  float rule3Scale;
};

struct Particle {
  vec2 pos;
  vec2 vel;
};

struct Particles {
  Particle particles[5];
};

layout(binding = 0, std140)
uniform tint_symbol_2_1_ubo {
  SimParams tint_symbol_1;
} v;
layout(binding = 1, std430)
buffer tint_symbol_4_1_ssbo {
  Particles tint_symbol_3;
} v_1;
layout(binding = 2, std430)
buffer tint_symbol_6_1_ssbo {
  Particles tint_symbol_5;
} v_2;
void comp_main_inner(uvec3 tint_symbol) {
  uint index = tint_symbol[0u];
  if ((index >= 5u)) {
    return;
  }
  uint v_3 = index;
  vec2 vPos = v_1.tint_symbol_3.particles[v_3].pos;
  uint v_4 = index;
  vec2 vVel = v_1.tint_symbol_3.particles[v_4].vel;
  vec2 cMass = vec2(0.0f);
  vec2 cVel = vec2(0.0f);
  vec2 colVel = vec2(0.0f);
  int cMassCount = 0;
  int cVelCount = 0;
  vec2 pos = vec2(0.0f);
  vec2 vel = vec2(0.0f);
  {
    uint i = 0u;
    while(true) {
      if ((i < 5u)) {
      } else {
        break;
      }
      if ((i == index)) {
        {
          i = (i + 1u);
        }
        continue;
      }
      uint v_5 = i;
      pos = v_1.tint_symbol_3.particles[v_5].pos.xy;
      uint v_6 = i;
      vel = v_1.tint_symbol_3.particles[v_6].vel.xy;
      float v_7 = distance(pos, vPos);
      if ((v_7 < v.tint_symbol_1.rule1Distance)) {
        cMass = (cMass + pos);
        cMassCount = (cMassCount + 1);
      }
      float v_8 = distance(pos, vPos);
      if ((v_8 < v.tint_symbol_1.rule2Distance)) {
        colVel = (colVel - (pos - vPos));
      }
      float v_9 = distance(pos, vPos);
      if ((v_9 < v.tint_symbol_1.rule3Distance)) {
        cVel = (cVel + vel);
        cVelCount = (cVelCount + 1);
      }
      {
        i = (i + 1u);
      }
      continue;
    }
  }
  if ((cMassCount > 0)) {
    vec2 v_10 = cMass;
    float v_11 = float(cMassCount);
    vec2 v_12 = (v_10 / vec2(v_11, float(cMassCount)));
    cMass = (v_12 - vPos);
  }
  if ((cVelCount > 0)) {
    vec2 v_13 = cVel;
    float v_14 = float(cVelCount);
    cVel = (v_13 / vec2(v_14, float(cVelCount)));
  }
  vVel = (((vVel + (cMass * v.tint_symbol_1.rule1Scale)) + (colVel * v.tint_symbol_1.rule2Scale)) + (cVel * v.tint_symbol_1.rule3Scale));
  vec2 v_15 = normalize(vVel);
  vVel = (v_15 * clamp(length(vVel), 0.0f, 0.10000000149011611938f));
  vPos = (vPos + (vVel * v.tint_symbol_1.deltaT));
  if ((vPos.x < -1.0f)) {
    vPos[0u] = 1.0f;
  }
  if ((vPos.x > 1.0f)) {
    vPos[0u] = -1.0f;
  }
  if ((vPos.y < -1.0f)) {
    vPos[1u] = 1.0f;
  }
  if ((vPos.y > 1.0f)) {
    vPos[1u] = -1.0f;
  }
  uint v_16 = index;
  v_2.tint_symbol_5.particles[v_16].pos = vPos;
  uint v_17 = index;
  v_2.tint_symbol_5.particles[v_17].vel = vVel;
}
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void main() {
  comp_main_inner(gl_GlobalInvocationID);
}
