#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
{
    float3 pos_attr [[attribute(0)]];
    float2 uv_attr [[attribute(1)]];
    float2 vector_offset_attr [[attribute(2)]];
    float2 vector_shift_attr [[attribute(3)]];
};

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

