// 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.Images
{
    /// <summary>
    /// The Drago tonemap operator.
    /// </summary>
    internal shader ToneMapDragoOperatorShader : ToneMapCommonOperatorShader
    {
        float DragoBias = 0.5f;

        override float4 Compute(float4 color)
        {
            float pixelLuminance = LuminanceUtils.Luma(color);
            float toneMappedLuminance = log10(1 + pixelLuminance);
            toneMappedLuminance /= log10(1 + WhiteLevel);
            toneMappedLuminance /= log10(2 + 8 * ((pixelLuminance / WhiteLevel) * log10(DragoBias) / log10(0.5f)));
            return toneMappedLuminance * pow(color / pixelLuminance, LuminanceSaturation); 
        }
    };
}
