struct Output
{
    float4 Color : TEXCOORD0;
    float3 WorldNormal : TEXCOORD1;
    float3 WorldPosition : TEXCOORD2;
    float4 Position : SV_Position;
};

#include "RootConstants.hlsl"

Output main(uint vertexIndex : SV_VertexID)
{
    Output output;

    ByteAddressBuffer buffer = ResourceDescriptorHeap[BufferIndex];

    uint stride = 40;
    uint offset = vertexIndex * stride;

    float3 pos = asfloat(buffer.Load3(offset));
    float3 normal = asfloat(buffer.Load3(offset + 12));
    float4 col = asfloat(buffer.Load4(offset + 24));

    // Fetch Model Matrix
    StructuredBuffer<TransformData> transformsBuffer = ResourceDescriptorHeap[TransformsBufferIndex];
    float4x4 Model = transformsBuffer[MeshIndex].Model;

    float4 worldPos = mul(Model, float4(pos, 1.0f));
    output.Position = mul(ViewProjection, worldPos);
    output.Color = col;
    output.WorldPosition = worldPos.xyz;
    
    float3 worldNormal = mul((float3x3)Model, normal);
    output.WorldNormal = worldNormal;
    return output;
}
