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:

cube map texture

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

equirectangular texture

  • \$\begingroup\$ 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? \$\endgroup\$ – MichaelHouse Jul 16 '12 at 13:24
  • \$\begingroup\$ yes, just how HDR shop does \$\endgroup\$ – Sambatyon Jul 16 '12 at 13:32
  • \$\begingroup\$ Are you looking for an algorithm, library or software? \$\endgroup\$ – 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);

    return CubeMapTextureRead(cube_map_coordinate);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.