FaceRig

FaceRig

Not enough ratings
Adding custom cube backgrounds
By coldacid
In this guide, I'll explain how to convert a panoramic image into a cube map texture that you can use as a custom cube backdrop in FaceRig.
   
Award
Favorite
Favorited
Unfavorite
Getting started
The first thing you'll need is a panoramic image, preferably in equirectilinear projection. For this guide, I've been working with "Square in front of skyscraper"[hdrmaps.com], a freebie from HDRMaps.com. If you have regular photos or panoramic images made by phone camera apps, you should use something like Photosynth or PanoTools to stitch them together into an equirectilinear panorama before continuing with this guide.

Generating cube faces in Blender
The first step of our process is to generate the faces of our cube map from the original panoramic image. If you're using an HDR panorama and you've paid out for HDRShop, you should be able to use that to create face images or a vertical cross image that can be sliced into faces, but if you're like me a free option is far more preferable. So we'll use the open-source modelling program Blender and a custom .blend file made for this purpose to split up our panorama.

To start off, download the https://aerotwist.com/static/tutorials/create-your-own-environment-maps/environment.zip file from the Aerotwist tutorial on making environment maps[aerotwist.com] and unzip it somewhere. There are two files inside, environment.blend and environment.jpg. Open up environment.blend, and Blender should start off looking like this:


The environment.blend file is set up to generate six PNG files from the image used as the texture of the Sphere object you can see in the outliner (top of the right sidebar). If you're using an HDR panorama, you'll want to change from PNG to Radiance HDR in the Output section of the Render Properties, and perhaps change RGB to RGBA:


Now, let's set our panorama image as the Sphere texture. I resize the height and width of the Outliner panel to make life a bit easier, but all you need to do is expand the outline under Sphere until the Texture node appears. Once it does, select it and then click on the Texture button in the Properties panel underneath (that's the checkerboard in the row of buttons at the top of the Properties panel). Blender should now look something like this:

In the Image section of the Properties panel, click the folder icon for the image property (i.e. "environment.jpg" without the two slashes). This will bring up a file system navigator; move to the directory with your panoramic image in it, then double-click on the panorama file's name to select it as the texture image. Once it's selected and you can see part of the image in the preview box in the Properties panel, we can move on to actually rendering the faces of our cube.

To do this, we need to switch back to Render Properties. Click the camera icon in the button bar at the top of the Properties panel to return, and then click the "Animation" button in the Render section of the panel. Blender will then render out six images, which get saved in the same directory as environment.blend as 0001.png, 0002.png, 0003.png, 0004.png, 0005.png, and 0006.png (or .hdr if you changed the output format). There's now one final task before this step is complete.

Each individual face image represents a direction on a particular axis, and to make life easier when setting up the faces for conversion into a cubemap texture, we want to rename these numbered images to match those axis directions. You should rename the files as follows:

Original Name
New Name
0001.png
z-pos.png
0002.png
x-neg.png
0003.png
z-neg.png
0004.png
x-pos.png
0005.png
y-neg.png
0006.png
y-pos.png

At this point, we've gone from our original panorama image to these:



By the way, you might have noticed that there are odd-coloured dots in the centre of the Y-axis images. If you want, you can airbrush them out before continuing on.
Creating the cubemap texture
Once the face images are generated, it's time to turn them into a cubemap texture that FaceRig can use as a custom backdrop. For this, we use a tool originally created by AMD called CubeMapGen[developer.amd.com]. I use a modified version by Sébastien Lagarde[seblagarde.wordpress.com] which adds a number of processing options not found in the original app. If you're working with HDR panoramas, I'd highly suggest using the modified version instead of AMD's original.

When you start CubeMapGen, it looks like this:

If you're using the modified version, it's somewhat different; the load/save and display settings panels are on the left hand side of the window, and there's a new "CosinePower" filter type available. Unless you like spending a lot of time waiting, it's best to change that to Disc (the default in the original CubeMapGen).

Apart from the settings panels, what you see is a sphere that reflects the (currently invisible) skybox around it. By default, the skybox faces are all solid primary and secondary RGB colours. Let's go ahead and make that skybox visible by checking the appropriate box in the display settings panel.

With the skybox now visible, we'll tell CubeMapGen the size and format we want for our final cubemap. Near the bottom of the filter panel, there is a dropdown for Output Cube Size. By default, this is 128. Instead, it should be the same as the length of our generated faces, i.e. 1024. Next, we want to set the Output Cube Format in the output panel to "float16 RGBA". Even if your panorama isn't an HDR image, this is the format that FaceRig expects for cubemaps.

If you're using Modified CubeMapGen it should now look like this:


Now we can start replacing the "color cube" faces with the face images generated in the previous step. If you're using ModifiedCubeMapGen, move the load/save panel up by some 50 or so pixels (the ~ button in the panel header lets you move it). Unfortunately the cube face dropdown ends up being overlapped by the display panel, whereas in the original app it doesn't.

Remember how we renamed the face images in the last step? That's to make it easier to select the correct files when setting the faces in CubeMapGen. For each face image, we need to select the correct face in the load/save panel, then select the correct image after clicking the "Load CubeMap Face" button (or pressing the F key). The faces are named X+, X-, Y+, Y-, Z+, and Z- and can be quickly selected by the regular keyboard number keys 1-6 (the numpad keys won't work for this).

The first face selected might result in this message box (or similar) popping up:
If that's the case, select "Yes".

Once your first face is selected, the other faces go black as we're no longer using the "color cube" default cubemap. Don't worry about that; just continue going through each of the faces you can choose in the "Select Cube Face" dropdown, and loading the appropriate image for each face.

Once you've set all the faces, click and hold on the sphere and move the mouse around to change your viewing position inside the skybox. This will give you an idea of how it'll look inside FaceRig before saving. If the sphere takes up more space than you like, you can use the mousewheel to move away from it and see more of the skybox itself.


Finally, click the "Save CubeMap (.dds)" button to create the final cubemap texture. You'll want to save the file in your "Documents\Holotech\FaceRig\AdditionalData\Backgrounds" directory.
Using the cubemap in FaceRig
Now that we have our cubemap texture, the last step is to put it to use. After opening up FaceRig, switch to Advanced UI and then open the Environments dialog. In the gallery, choose "Background Custom Cube" (it's the one with the same thumbnail as this guide). Then, switch over to the Customization tab, and choose the "Backdrop" sub-tab under it if it isn't already selected. Finally, open up the "Custom Backdrop" section and click the folder button to get the open file dialog.

By default, FaceRig has the BMP file type selected in the dialog. But since we created a DDS cubemap texture file instead, select "DDS (*.dds)" from the file type dropdown. Now, navigate to your "Documents\Holotech\FaceRig\AdditionalData\Backgrounds" directory, and choose your new background image.

Voila! Welcome to your new environment.