#version 460
layout(location = 0) in vec3 a_pos;
layout(location = 1) in vec4 a_color;
layout(location = 2) in vec3 a_normal;

layout(location = 0) out vec4 v_color;
layout(location = 1) out float depth;
layout(location = 2) out vec3 v_normal_vs;  // view-space normal

layout(std140, set = 1, binding = 0) uniform UniformBlock {
  mat4  model;
  mat4  view;
  mat4  projection;
  mat4  inv_view;
  mat4  inv_projection;
  vec4 time_padded;
  vec4  cam_pos;
};

void main() {
    vec4 view_pos = view * model * vec4(a_pos, 1.0);
    depth = -view_pos.z / 1000.0;
    gl_Position = projection * view_pos;
    v_color = a_color;

    // For uniform scale this shortcut is fine:
    mat3 normal_mat = mat3(transpose(inverse(view * model)));
    v_normal_vs = normalize(normal_mat * a_normal);
}
