#ifndef GALAXY_GLSL_
#define GALAXY_GLSL_

#include "simplex.glsl"

float galaxySampleBand(vec3 dir, float extent, float sharpness, float size)
{
    vec3 galaxyNormal  = normalize(vec3(0.0, 0.0, -1.0));
    vec3 galaxyForward = normalize(cross(galaxyNormal, vec3(1.0, 0.0, 0.0)));

    float d = abs(dot(dir, galaxyNormal));
    float band = pow(max(0.0, 1.0 - d), sharpness);

    float alongAngle = acos(clamp(dot(dir, galaxyForward), -1.0, 1.0));
    float lengthFalloff = smoothstep(size, 0.0, alongAngle);

    band *= lengthFalloff;

    return band;
}

vec3 galaxySample(vec3 dir, float extent)
{
    return vec3(0.05, 0.3, 0.05) * galaxySampleBand(dir, extent, 3.7, 2.0) + 
        vec3(0.25) * galaxySampleBand(dir, extent, 6.35, 1.45);
}

#endif