Panorama picture to Cubemap algorithm

700 views Asked by At

I'm running in a problem. I would like to create an application that allows people to watch their panorama photos taken with their phone in a skybox view.

For that, I need to slice the photo into a cubeMap. I searched hard the internet to find an algorithm but I didn't find anything (that I could understand).

There are some programs that are doing a skyboxes from a panorama pictures, but I don't know their algorithm :/

1

There are 1 answers

0
Nico Schertler On

The easy way is to keep the image in its original format and to use a sky cylinder instead of a sky box. Then you can apply texture coordinates according to the height and angle of the vertex and you're done.

If you want to use a sky box, you could calculate the correct texture coordinates in the pixel shader with:

u = atan(fragWorldPosX - cameraWorldPosX, fragWorldPosZ - cameraWorldPosZ) * scale1;
v = 0.5 + (fragWorldPosY - cameraWorldPosY) * scale2;

Where scale1 and scale2 are parameters that specify the picture's horizontal and vertical field of view.

In neither the cylinder nor the box you need the top or bottom surface.