// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
namespace Stride.Rendering.Lights
{
    /// <summary>
    /// Defines a group of point lights
    /// </summary>
    shader LightPointGroup<int TMaxLightCount> : DirectLightGroupPerDraw, LightPoint
    {
        cbuffer PerDraw.Lighting
        {
            PointLightData Lights[TMaxLightCount];
        }

        override int GetMaxLightCount()
        {
            return TMaxLightCount;
        }

        /// <summary>
        /// Compute the light color/direction for the specified index within this group
        /// </summary>
        override void PrepareDirectLightCore(int lightIndex)
        {
            // TODO: Workaraound for SPIR-V compiler. Revert later
            PointLightDataInternal data;
            data.PositionWS = Lights[lightIndex].PositionWS;
            data.InvSquareRadius = Lights[lightIndex].InvSquareRadius;
            data.Color = Lights[lightIndex].Color;

            ProcessLight(data);
        }

        override float ComputeAttenuation(float3 position, int lightIndex)
        {
            // TODO: Workaraound for SPIR-V compiler. Revert later
            PointLightDataInternal data;
            data.PositionWS = Lights[lightIndex].PositionWS;
            data.InvSquareRadius = Lights[lightIndex].InvSquareRadius;

            float3 lightVectorNorm;
            return ComputeAttenuation(data, position, lightVectorNorm);
        }
    };
}
