// 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.Materials
{
    shader MaterialPixelShadingStream : MaterialPixelStream, LightStream
    {
        // Output of shading a material surface
        stage stream float3 shadingColor;

        // Output of the shading color alpha
        stage stream float  shadingColorAlpha;

        // Half vector (sum of normalWS + lightDirectionWS)
        stage stream float3 H;

        // normal dot half vector
        stage stream float NdotH;

        // light dot half vector
        stage stream float LdotH;

        // view dot half vector
        stage stream float VdotH;

        override void ResetStream()
        {
            base.ResetStream();
            streams.shadingColorAlpha = 1.0f;
        }

        // Computes material attributes per light
        stage void PrepareMaterialPerDirectLight()
        {
            // TODO: This is not plug-n-play
            // Used by microfacet
            streams.H = normalize(streams.viewWS + streams.lightDirectionWS);
            streams.NdotH = saturate(dot(streams.normalWS, streams.H));
            streams.LdotH = saturate(dot(streams.lightDirectionWS, streams.H));
            streams.VdotH = streams.LdotH;
        }
    };
}

