/*
 * 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 <viewsrg.srgi>
#include <scenesrg.srgi>

ShaderResourceGroupSemantic SRG_PerGroup
{
    FrequencyId = 0;
};

struct MaterialInfo
{
    float4 m_color;
};

ShaderResourceGroup MaterialGroupSrg : SRG_PerGroup
{
    MaterialInfo m_materials[10];
}

rootconstant float4x4 s_objectMatrix;
rootconstant uint s_materialIndex;

struct VSInput
{
    float3 m_position : POSITION;
    float3 m_normal: NORMAL;
};

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

VSOutput MainVS(VSInput vsInput)
{
    VSOutput OUT;
    OUT.m_position = mul(mul(ViewSrg::m_viewProjectionMatrix, s_objectMatrix), float4(vsInput.m_position, 1.0));
    float3 normal = mul(s_objectMatrix, float4(vsInput.m_normal, 0.0)).xyz;
    float intensity = saturate(dot(normalize(normal), normalize(float3(-1.0, -1.0, -1.0)))); 
    OUT.m_color = saturate(MaterialGroupSrg::m_materials[s_materialIndex].m_color * intensity);
    return OUT;
}

struct PSOutput
{
    float4 m_diffuse : SV_Target0;
    float4 m_specular : SV_Target1;
};

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