Creating fisheye image sequences with Unity3DWritten by Paul Bourke, Contributions from Nick Oliver
Sample: unityfisheyesample.zip, built in Unity V5
The following are notes related to the creation of fisheye frames from the Unity game engine. There are other documents here describing the real-time generation of dome content from Unity, the theme here is using the engine to create fisheye frames that might then be saved and used for movie playback, although the technique has wider application. There are two approaches: simply creating the required visual field and then using external tools to create the fisheye (or spherical image), or creating the fisheye image within Unity itself. Both cases require a means of saving camera views to a file (see script at the end of this document). The relative merits and limitations of each approach will be also be discussed.Saving individual camera images
The basic approach to both techniques is to replace the single camera in Unity with a multicamera rig. The multiple cameras are arranged in the same fashion as one might choose for cubemaps, that is, each is orthogonal to it's neighbours and with a 90 x 90 degree FOV. If render-to-texture is available (Unity Pro version pre version 5) then each camera view can be rendered to a texture that is then saved. The resulting images are combined with post production tools such as cube2dome.Creating fisheye directly
The fisheye can be created directly in Unity by taking each of the camera textures and applying them to a mesh (vertex coordinates and texture coordinates) precisely crafted to create a fisheye. For the minimum case of a 180 degree fisheye only 4 cameras are required, the obj file that will combined these to form a fisheye is given here (180x4.zip). Unlike the more common camera arrangement where the "front" camera is aligned with the center of one of the cube faces, here the front camera is pointing half way along the edge between the left and right camera. The textures for a 5 camera rig to create a 180 degree fisheye is given here (180x5.zip)
A 4 camera and 5 camera rig is included in the sample project.
The key components / flows for the right camera are illustrated below, see the sample project. The right camera renders to a texture, that texture is applied to the mesh section that performs the geometry correction, a final orthographic camera captures the view comprising of just the 5 mesh sections. The geometry to achieve this is placed on a layer by itself, invisible to the scene camera rig. All textures use the unlit texture shader although a diffuse shader could be used with a directional light source on the texture layer to provide some brightness control.
The following example is created from a project of the Cyrus temple in Iran, all 6 camera views are created, the following script saves the texture images: TextureDump.js.zip, it can be readily used to create a frame along each position of a scripted smooth path.
Using "cube2dome" and the following command line, the fisheye below is created. This reveals the strength of the 6 camera approach in that the angle of the camera rig in Unity is not important, any of the infinity of possible fisheye angles can be created in post production.
cube2dome -a 2 -vt 60 %c0.tga