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

using namespace metal;

struct Globals
{
    float4x4 uMVP;
    float4x4 uModel;
    packed_float3 uCamPos;
    float uLight;
    packed_float3 uFog;
    float uFogStart;
    float uFogEnd;
    float4 uTint;
    float uFlash;
    int uDynLightCount;
    float4 uDynLightPosRadius0;
    float4 uDynLightPosRadius1;
    float4 uDynLightPosRadius2;
    float4 uDynLightPosRadius3;
    float4 uDynLightColor0;
    float4 uDynLightColor1;
    float4 uDynLightColor2;
    float4 uDynLightColor3;
};

struct main0_out
{
    float3 vNormal [[user(locn0)]];
    float4 vColor [[user(locn1)]];
    float vDist [[user(locn2)]];
    float3 vWorld [[user(locn3)]];
    float4 gl_Position [[position]];
};

struct main0_in
{
    float3 aPos [[attribute(0)]];
    float3 aNormal [[attribute(1)]];
    float4 aColor [[attribute(2)]];
};

vertex main0_out main0(main0_in in [[stage_in]], constant Globals& _15 [[buffer(0)]])
{
    main0_out out = {};
    float4 wp = _15.uModel * float4(in.aPos, 1.0);
    out.vNormal = float3x3(_15.uModel[0].xyz, _15.uModel[1].xyz, _15.uModel[2].xyz) * in.aNormal;
    out.vColor = in.aColor;
    out.vDist = length(wp.xyz - float3(_15.uCamPos));
    out.vWorld = wp.xyz;
    out.gl_Position = _15.uMVP * float4(in.aPos, 1.0);
    out.gl_Position.z = (out.gl_Position.z + out.gl_Position.w) * 0.5;
    return out;
}

