#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct VertexOut
{
    float4 color [[user(locn0)]];
    float eyedist [[user(locn1)]];
    float4 gl_Position [[position]];
};

struct VertexIn
{
    float3 pos_attr [[attribute(0)]];
    float4 color_attr [[attribute(1)]];
};

vertex VertexOut vertexShader(VertexIn in [[stage_in]], constant float4x4& modelview_unif [[buffer(1)]], constant float4x4& proj_unif [[buffer(2)]])
{
    VertexOut out = {};
    float4 pos = modelview_unif * float4(in.pos_attr, 1.0);
    out.gl_Position = proj_unif * pos;
    out.color = in.color_attr;
    out.eyedist = -pos.z;
    return out;
}

