// 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>
    /// Outputs CoC and linear depth.
    /// Expects as input:
    /// - Texture0: the raw depth-buffer used to render the original scene
    /// </summary>
    shader CoCLinearDepthShader : ImageEffectShader, Camera, CircleOfConfusion
    {

        stage override float4 Shading()
        {
            // Linearizes the depth for view space
            float depth = Texture0.Sample(Sampler, streams.TexCoord).x;
            float linearDepth = ZProjection.y / (depth - ZProjection.x);

            // Debug: use this to visualize with a color in the [0, 1] range
            // color = 1.0 - linearDepth / FarClipPlane;

            // Calculates the CoC based on the linearized depth
            float CoC = getCoCFactor(linearDepth);

            return float4(CoC, linearDepth, 0.0, 0.0);
        }
    };
}
