
/*
 * 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
 *
 */

#pragma once

#include <viewsrg.srgi>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultObjectSrg.azsli>
#include <Atom/RPI/Assets/ShaderLib/Atom/RPI/TangentSpace.azsli>

struct VertexInput
{
    float3 m_position : POSITION;
    float3 m_normal : NORMAL;
    float4 m_tangent : TANGENT;
    float3 m_bitangent : BITANGENT;
    float2 m_uv : UV0;
};

struct VertexOutput
{
    float4 m_position : SV_Position;
    float3 m_normal : NORMAL;
    float3 m_tangent : TANGENT;
    float3 m_bitangent : BITANGENT;
    float2 m_uv : UV0;
    float3 m_view : VIEW;
};

VertexOutput CommonVS(VertexInput input)
{
    float4x4 objectToWorld = ObjectSrg::GetWorldMatrix();
    float3x3 objectToWorldIT = ObjectSrg::GetWorldMatrixInverseTranspose();

    VertexOutput output;
    float3 worldPosition = mul(objectToWorld, float4(input.m_position, 1)).xyz;
    output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));

    output.m_uv = input.m_uv;
        
    output.m_view = worldPosition - ViewSrg::m_worldPosition;
    
    ConstructTBN(input.m_normal, input.m_tangent, input.m_bitangent, objectToWorld, objectToWorldIT, output.m_normal, output.m_tangent, output.m_bitangent);

    return output;
}
