#ifndef LIGHT_GLSL_
#define LIGHT_GLSL_

#include "worldFrameData.glsl"

struct Cluster
{
    uint offset;
    uint count;
};

struct LightSource
{
    uvec4 sourceVoxelAndRadius;
    vec4 colorAndVariance;
};

struct LightScope
{
    uvec4 minScope;
    uvec4 maxScope;
};

uint computeDepthSlice(float z)
{
    float logN = log(0.1);
    float logF = log(uFrameData.farZ);

    float norm = (log(z) - logN) / (logF - logN);
    float sliceF = norm * float(GLSL_LIGHT_DEPTH_SLICES);

    return uint(clamp(floor(sliceF), 0.0, float(GLSL_LIGHT_DEPTH_SLICES - 1)));
}

float coneAngleFromSpecular(float specular)
{
    return radians(10.0) * (1.0 - specular);
}

float shininessFromConeAngle(float coneAngle)
{
    return 1.0 / max(coneAngle * coneAngle, 1e-4);
}

float shininessFromSpecular(float specular)
{
    return shininessFromConeAngle(coneAngleFromSpecular(specular));
}

#endif