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

using namespace metal;

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

struct VertexIn
{
    float2 pos_attr [[attribute(0)]];
    float2 uv_attr [[attribute(1)]];
    float2 vector_offset_attr [[attribute(2)]];
};

vertex VertexOut vertexShader(VertexIn in [[stage_in]], constant float4x4& modelview_unif [[buffer(1)]], constant float& edge_width_multiplier [[buffer(2)]], constant float4x4& proj_unif [[buffer(3)]], constant float2& tex_scale_unif [[buffer(4)]], constant float2& tex_offset_unif [[buffer(5)]], constant float& texture_x_divisor [[buffer(6)]], constant float& texture_x_offset [[buffer(7)]])
{
    VertexOut out = {};
    float4 pos = modelview_unif * float4(float3(in.pos_attr, 0.0) + float3(in.vector_offset_attr * edge_width_multiplier, 0.0), 1.0);
    out.gl_Position = proj_unif * pos;
    out.uv = (in.uv_attr * tex_scale_unif) + tex_offset_unif;
    out.uv = float2((out.uv.x / texture_x_divisor) + texture_x_offset, out.uv.y);
    out.eyedist = -pos.z;
    return out;
}

