/*
 * Copyright (c) Contributors to the Open 3D Engine Project.
 * For complete copyright and license terms please see the LICENSE at the root of this distribution.
 *
 * SPDX-License-Identifier: Apache-2.0 OR MIT
 *
 */

 #include <Atom/Features/SrgSemantics.azsli>

struct InstanceInfo
{
    column_major float4x4 m_matrix;
    float4 m_colorMultiplier;
};

struct InstanceData
{
    InstanceInfo m_instancesInfo[30];
};

ShaderResourceGroup TriangleSrg : SRG_PerObject
{
    ConstantBuffer<InstanceData> m_trianglesCB;
}

struct VSInput
{
    float3 m_position : POSITION;
    float4 m_color : COLOR0;
    uint m_instanceIndex : SV_InstanceID;
};

struct VSOutput
{
    float4 m_position : SV_Position;
    float4 m_color : COLOR0;
};

VSOutput MainVS(const VSInput vsInput)
{
    VSOutput OUT;
    
    const InstanceInfo triangleInstanceInfo = TriangleSrg::m_trianglesCB.m_instancesInfo[vsInput.m_instanceIndex];
    
    OUT.m_position = mul(float4(vsInput.m_position, 1.0f),triangleInstanceInfo.m_matrix);
    OUT.m_color = vsInput.m_color * triangleInstanceInfo.m_colorMultiplier;
    
    return OUT;
}

struct PSOutput
{
    float4 m_color : SV_Target0;
};

PSOutput MainPS(VSOutput vsOutput)
{
    PSOutput OUT;
    OUT.m_color = vsOutput.m_color;
    return OUT;
}
