Wednesday, August 14, 2019

Skysphere to Skybox Texture Conversion


I am working on a hobby project and implemented a skybox, no big deal. Now I bought (licensed) a few really nice sky textures. Unfortunately the textures are projected for a skysphere.


I could implement a skysphere handling/rendering, but I figure rendering a box is way more efficient. (That may actually not matter on modern devcies though.) So I decided to transform the textures into 6 textures for a skybox.


My hodge podge solution to convert the textures is I create a scene in blender and render out the appropriate 6 views. If you ask google that is aproptatly the common sollution.


It there a tool that can do the conversion in a more automated way?




Answer



Note, that there is no pixel-to-pixel projection (one pixel can map into several pixels etc).


You should implement a geometric ray/cube intersection. It sounds complicated, but it is very easy. Choose a pixel on sphere map. From that pixel, you compute azimuth and elevation. Compute unit-length 3D vector, pointing from the center of the sphere to your pixel. Now scale that vector, so the largest coordinate is 1. Now you have coordinates on cube, so put your pixel color onto that coordinate in cube.


It would be better to do it backwards - request a pixel on cube and then look for that pixel in sphere map, so you don't have "empty spaces" in your cube map.


If you are looking for a tool, here is a discussion about it http://forum.quest3d.com/index.php?topic=46542.0


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...