/*
 * 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 "IndirectRendering.azsli"

struct VSInput
{
    float3 m_position : POSITION;
    uint m_instanceId : BLENDINDICES0;
};

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

rootconstant uint g_instanceId;

option bool o_useRootConstants = false;

VSOutput MainVS(VSInput vsInput)
{
    VSOutput OUT;
    uint instanceId;
    if (o_useRootConstants)
    {
        instanceId = g_instanceId;
    }
    else
    {
        instanceId = vsInput.m_instanceId;
    }
    float4 position = float4(TransformInstancePos(vsInput.m_position, IndirectSceneSrg::m_instancesData[instanceId]), 1.0);
    OUT.m_position = mul(IndirectSceneSrg::m_matrix, position);
    float intensity = saturate((4.0f - OUT.m_position.z) / 2.0f);
    OUT.m_color = float4(IndirectSceneSrg::m_instancesData[instanceId].m_color.xyz * intensity, 1.0f);
    return OUT;
}

struct PSOutput
{
    float4 m_color : SV_Target0;
};

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