#ifndef STARS_GLSL_
#define STARS_GLSL_

#include "common.glsl"

layout(
    set = GLSL_TERRAIN_SKYBOX_DESCRIPTOR_SET,
    binding = GLSL_SKYBOX_STAR_NOISE_INDEX
) uniform samplerCube uStarNoiseSampler;

struct Star
{
    vec3 centerDir;
    float size;
    float colorNoise;
};

Star starGenerate(uint index)
{
    float relSize = unitFromHash(hash(index ^ 0xdf3455ea));
    float size = mix(0.2, 0.4, pow(relSize, 15.0));

    float phi = unitFromHash(hash(index ^ 0x4df312dd)) * 2.0 * 3.1415;
    float z = unitFromHash(hash(index ^ 0x3da1f6d3)) * 2.0 - 1.0;

    float r = sqrt(max(0.0, 1.0 - z*z));

    float colorNoise = 0.0;
    if (unitFromHash(hash(index ^ 0x5d1fb4c7)) < 0.5)
    {
        colorNoise = noiseFromHash(hash(index ^ 0x3fa68abc));
    }

    vec3 dir = vec3(
        r * cos(phi),
        z,
        r * sin(phi)
    );

    return Star(dir, size, colorNoise);
}

#endif