// 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.
shader UIEffectShader<bool TSRgb> : ShaderBase, Texturing
{
    // -------------------------------------
    // streams
    // -------------------------------------
    stage stream float4 Position : POSITION;
    stage stream float4 Color : COLOR;
    stage stream float Swizzle : BATCH_SWIZZLE;
            
    // -------------------------------------
    // VertexShader
    // -------------------------------------
    stage override void VSMain()
    {
        streams.ShadingPosition = streams.Position;
        if (TSRgb)
        {
            streams.Color = ColorUtility.ToLinear(streams.Color);
        }
    }
        
    // Shading of the sprite
    stage override void PSMain()
    {
        streams.ColorTarget = Shading();
    }

    stage float4 Shading()
    {
        float4 sampledColor = Texture0.Sample(Sampler, streams.TexCoord);
        float4 swizzledColor = streams.Swizzle == 0? sampledColor: sampledColor.rrrr;

        return swizzledColor * streams.Color;
    }
};
