// 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
{
    /// <summary>
    /// Material displacement map
    /// </summary>
    shader MaterialSurfaceDisplacement<MemberName TPosition, MemberName TNormal, bool TScaleNormal> : IMaterialSurface, MaterialDisplacementStream, PositionStream, NormalStream, Transformation
    {
        override void Compute()
        {
            float3 scaledNormal = streams.TNormal;
            if(TScaleNormal)
            {
                scaledNormal *= WorldScale;
            }

            streams.TPosition = float4(streams.TPosition.xyz + streams.matDisplacement * scaledNormal, streams.TPosition.w);
        }
    };
}
