#ifndef ENV_REFLECTION_INCLUDED
#define ENV_REFLECTION_INCLUDED

#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/ImageBasedLighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

void EnvReflection_float(float3 NormalWS, float3 ViewDirWS, float Smoothness, float Occlusion, out float3 Out)
{
    float3 N = normalize(NormalWS);
    float3 V = normalize(ViewDirWS);

    float perceptualRoughness = 1.0 - saturate(Smoothness);
    float3 R = reflect(-V, N);

    float mip = PerceptualRoughnessToMipmapLevel(perceptualRoughness);

    // This requires reflections to be enabled in URP (probe/skybox)
    half4 encoded = SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, R, mip);
    half3 env = DecodeHDREnvironment(encoded, unity_SpecCube0_HDR);

    Out = env * saturate(Occlusion);
}

#endif