// 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.Shadows
{
    /// <summary>
    /// Creates shadow map for variance shadow mapping.
    /// </summary>
    shader ShadowMapCasterVsm : ShadowMapCasterBase
    {
        /// --------------------------------------------------------------------------------
        /// Pixel Shader
        /// --------------------------------------------------------------------------------
        override stage void PSMain()
        {
            float depth = streams.ShadingPosition.z;

            // Compute partial derivatives of depth.
            float dx = ddx(depth);
            float dy = ddy(depth);
            // Compute second moment over the pixel extents.
            streams.ColorTarget = float4(depth, depth * depth + 0.25*(dx*dx + dy*dy), 0, 0);
        }
    };
}
