Leaving this here for myself:
static const float PI = 3.14159265f;
// assumes p is a point on unit sphere
float2 sphere2mapUV_Equirectangular(float3 p)
atan2(p.x, -p.z) / (2 * PI) + .5,
p.y * .5 + .5
float2 sphere2mapUV_EqualArea(float3 p)
(atan2(p.x, -p.z) / PI + 1) / 2,
asin(p.y) / PI + .5
I added links to example images in case you need a visual reference for checking which projection your map is made with.
float2 uv = sphere2map(normalize(position));
That assumes position is in model space.
In case you're using this in vertex shader the
position might already be normalized, so normalization could be skipped.
Your sphere model will usually have center at
float3(0,0,0), but if that's not the case you'll have to subtract the