As part of my work for Igalia I wanted to do some environment mapping. I was able to find plenty of high quality .hdr images online but I couldn’t find any (OSS) tool to convert them to cubemap images. Then, Nuclear (John Tsiombikas) gave me the solution: he wrote a minimal tool that does the job quickly and produces high quality cube maps.
So, here’s a short “how to” create cubemaps on Linux using his “cubemapper” program in combination with other OSS tools:
Install pfstools pfsview
Install the cubemapper dependencies:
git clone https://github.com/jtsiomb/libimago.git make sudo make install
git clone https://github.com/jtsiomb/gph-math.git make sudo make install
Get the cubemapper code from here: cubemapper-0.1.tar.gz
tar xzvf cubemapper-0.1.tar.gz cd cubemapper-01/ make sudo make install
Create the cubemaps:
Before we begin, we can check our hdr images using pfsview like that:
pfsin foobar_in.hdr | pfsview
Sometimes the image is too big and we might need to resize it (if it’s really really big pfsview might crash).
Resize can be done by running:
pfsin foobar_in.hdr | pfssize --maxy 2048 | pfsout foobar_out.hdr
(You can replace 2048 or maxy with another value)
After resizing to something more reasonable / suitable for our app, we can use the cubemapper to create the cubemap images:
With this command we should see something like that:
Pressing c will save the cubemap images in the current directory.
We can now show a cubemap made by the images we just saved, just to make sure that there aren’t any artifacts, by pressing space:
Exiting the program, we can see that the current directory contains 6 new .hdr files:
cubemap_px.hdr, cubemap_py.hdr cubemap_pz.hdr,
cubemap_nx.hdr, cubemap_ny.hdr, cubemap_nz.hdr
(one for each cubemap direction).
These 6 images can now be used as textures for cube mapping with OpenGL.
Cubemapper works also with other types of images (e.g. jpg, png).
Note: The initial .hdr panorama I used on this post is from: http://noemotionhdrs.net/hdrday.html