#include "RayTypes.h"

RWStructuredBuffer<SphereRay> Output : register(u0, space1);

cbuffer UBO : register(b0, space2)
{
    int4 ubo_size : packoffset(c0);
    int spheresCount : packoffset(c1.x);
    int4 skybox_size : packoffset(c2);
};

[numthreads(64, 1, 1)]
void main(uint3 GlobalInvocationID : SV_DispatchThreadID)
{
    uint n = GlobalInvocationID.x;

    int2 r;
    r.y = n / skybox_size.x;
    r.x = n - r.y * skybox_size.x;

    float3 heading;
    heading.x = (r.x / (float) skybox_size.x);
    heading.y = (r.y / (float) skybox_size.y);

    heading = UVtoOctahedron(heading.xy);
    heading = normalize(heading);

    SphereRay sr = (SphereRay) 0;
    sr.Heading.xyz = heading;
    sr.Position.xyz = float3(0, -4, 3);

    Output[n] = sr;
}
