Constructing a panoramic skybox

By default, Unity Scenes start with a ground plane, horizon line, sky, and Sun. However, these are not individual GameObjects. Instead, it is a panoramic texture mapped to the inside of a cube and we call it a skybox. The skybox is drawn in the background behind all other objects and rotates to match the current camera's orientation. When done correctly, the skybox creates an immersive environment within the scene.

Skyboxes are materials created from combining six photographs, each at 90° from each other or by capturing a single 360° equirectangular panoramic image. The six-photo method, known as a Cubemap, can be created by shooting images from a single position in each direction; up, right, left, front, back, and down. Equirectangular images are created by capturing or stitching together images into a 3D projection:

Figure 3.5: Cubemap (left) versus Equirectangular (right) image comparison

An equirectangular panoramic image is a projection where the verticals remain vertical, and the horizon becomes a straight line across the middle of the image. Figure 3.5 shows how the coordinates in the image relate linearly to pan and tilt angles in the real world. The poles are located at the top and bottom edge and are stretched to the entire width of the image. Areas near the poles are stretched horizontally. In Figure 3.6, we can see how this arrangement is applied to a panoramic image:

Figure 3.6: Coordinate system in an equirectangular panoramic image

The equirectangular projection is the default output format of many rotating panoramic camera. However, even still images captured via DSLR or smartphone can be edited to meet our needs. One important factor of the capture process is that the images cover a full 360° horizontally and 180° vertically resulting in a final aspect ratio of 2:1. Before applying your own images to this project, be sure the file's height and width values are between 1024x512 and 8192×4096.

The internet is home to hundreds of repositories for viewing and downloading these types of images. We have included a few here for this tutorial, but feel free to create or search for images that fit the theme of your project. For example, Figure 3.7 is the result of a simple Google search on the term equirectangular images:

Figure 3.7: Image wrapped to match equirectangular projection

If you are using your own image, it should be imported into the Unity project and stored in the GalleryImages/Background folder before continuing:

  1. Select an image from Project/GalleryImages/Backgrounds  directory.

The Backgrounds directory contains sample equirectangular images to be used as backgrounds for our virtual gallery. Feel free to import your own panoramic images to customize the project. When using your own images for the scene background, you need to make sure they fit the 2:1 ratio requirement.

  1. Change the Texture Shape from 2D to Cube in the Inspector panel.
  2. Click the Apply button to accept the change.
  3. Create a new material named Backdrop and move it to the Materials folder.
  4. Change the Shader for Backdrop from Standard to Skybox | Cubemap:
Figure 3.8: Setting the shader for the new material to Skybox | Cubemap
  1. With the material still selected, click the Select button inside of the Cubemap icon preview. Select Backdrop from the selection box to set the skybox.

With the new skybox created, we can now assign it to the scene:

  1. Choose Window | Lightning | Settings to open the Lighting panel.
  2. Click the Skybox Material selection target to access the scene's skyboxes.
  3. Double-click Backdrop to apply our skybox to the scene.

The Backdrop skybox is now displayed in both the Scene and Game windows. Right-click and drag around the Scene window to preview our environment. With the skybox in place, we can now move on to creating a VR camera:

  1. Save your scene and Unity project.
  2. Use File | Save Scene to create WIP_3:
Figure 3.9: 1_Art image used as a skybox
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.125.7