// 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 SkyboxShaderTexture : SkyboxShaderBase, Math
    {
        stage Texture2D Texture;

        override stage float4 Shading()
        {
            var samplingDir = normalize(streams.skyboxViewDirection);
			var samplingDirSquare = float3(samplingDir.x*samplingDir.x, samplingDir.y*samplingDir.y, samplingDir.z*samplingDir.z);
			var u = atan2(-samplingDir.z, -samplingDir.x)/(2*Math.PI) + 0.5;
			var v = atan2(-samplingDir.y, length(samplingDir.xz))/Math.PI + 0.5;

#if STRIDE_GRAPHICS_PROFILE >= GRAPHICS_PROFILE_LEVEL_10_0
            var color = Texture.SampleLevel(LinearSampler, float2(u, v), 0).rgb;
#else
            var color = Texture.Sample(LinearSampler, float2(u, v)).rgb;
#endif
            return float4(color * Intensity, 1.0);
        }
    };
}
