# How do I convert a cube map to an equirectangular projection?

I have a cube map texture showing a surrounding area, which I want to pass to a program that only works with latitude/longitude maps.

How can I do this?

In other words, I need to turn this:

…into this (I think it's additionally rotated -90° over the x axis):

• You're saying you want to transform a cube map texture to fit on the inside of a sphere instead of the inside of a cube? – MichaelHouse Jul 16 '12 at 13:24
• yes, just how HDR shop does – Sambatyon Jul 16 '12 at 13:32
• Are you looking for an algorithm, library or software? – msell Jan 5 '15 at 21:32

With rect_coordinate ranging from -1 to 1 and assuming sin/cos functions take radian as inputs, for each pixel in the rectangular texture do:

color CubeToRectangle(vec2 rect_coordinate)
{
vec3 cube_map_coordinate;

cube_map_coordinate.x = cos(rect_coordinate.x * PI * 2) * cos(rect_coordinate.y * PI);
cube_map_coordinate.y = sin(rect_coordinate.y * PI);
cube_map_coordinate.z = sin(rect_coordinate.x * PI * 2) * cos(rect_coordinate.y * PI);