// 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.Skyboxes
{
    shader SkyboxShaderBase : SpriteBase, SkyboxStream
    {
        stage float Intensity;
        stage float4x4 ProjectionInverse;
        stage float4x4 ViewInverse;
        stage float4x4 SkyMatrix;

        override stage void VSMain()
        {
            base.VSMain();
            var screenPosition = streams.ShadingPosition / streams.ShadingPosition.w;
            var position = float4(screenPosition.x, screenPosition.y, 1.0f, 1.0f);
            var directionVS = mul(position, ProjectionInverse).xyz;
            var directionWS = mul(float4(directionVS,0), ViewInverse).xyz;
            streams.skyboxViewDirection = mul(directionWS, (float3x3)SkyMatrix);
        }
    };
}
