Panorama production and application

Contents of this experiment:

Use unity software to create a panorama display program, summarize and refine five methods of introducing panoramas in unity, and analyze the advantages and disadvantages of each method. The final program allows you to view the panorama effects achieved by different methods through buttons.

Experimental methods and experimental results:

  • Panorama material acquisition
  1. How to get it
  1. Download free materials from professional picture material websites
  2. Render virtual images with modeling tools
  3. Take pictures yourself with your mobile phone or panoramic camera

Affected by the epidemic, I chose method (1) to obtain materials. The process is as follows:

1.1 Choose a picture collection website

Here I choose "Panoramic Network" panoramic gallery - a high-quality photo gallery and high-definition photo website

  1. Panorama selection

When searching for panorama materials this time, I found that there are two types of panoramas found online.

2.1 One is the wide view (as shown below), which only expresses as much of the picture as possible and cannot be used in panorama playback software.

2.2 One is a 360-degree panorama, which must be a rectangular image with a width and height ratio of 2:1 (as shown below) and an equirectangular projection (that is, the top and bottom of the image are stretched)

  • Making a panorama display in unity

1. Clarify the contents of the panorama.

1.1How to describe a panorama in unity

The middle layer is clear, the upper and lower sections are strongly stretched, and the picture has the characteristics of warp and weft. The API in Unity writes:

Translated, it means: latitude and longitude, sometimes also called cylindrical. Panorama images often use this layout.

2. Clarify the two projections, that is, the two ways of displaying the panorama

2.1 spherical panoramas spherical panorama

It can be represented by a rectangular image that surrounds 360 degrees in the horizontal direction and 180 degrees in the vertical direction, which is what we usually see as a panorama. (As shown below). They contain light data from all directions, so such a map can be projected onto a sphere.

2.2cubemap/cubic format.

As shown in the picture below, it divides the picture into six sides of a cube to show the panorama.

3 Several ways to display panorama in unity

3.1 Directly apply the panorama (a rectangular image with a width and height ratio of 2:1, stretched upper and lower segments) to a sphere, and add a shader that inverts the texture.

3.1.1 Specific steps

First move the camera to coordinates (0, 0, 0)

Add a sphere with coordinates (0, 0, 0) and set Scale to (5, 5, 5)

Drag the panorama into the project

Drag the panorama onto the sphere

Create a new shader and add the following code. The purpose is to change the texture to be displayed inside the sphere.

Change the sphere's shader to the newly created shader

Create a new script so that when the left mouse button is pressed, the camera can rotate with it

3.1.2 Experimental results

In Game mode, the camera moves with the mouse and you can see the entire scene

But there are some flaws:

Distortions can be seen at the user's feet and top.

3.1.3 Conclusion analysis of this method

3.1.3.1 The reason for the distortion: Unity’s own sphere has a small number of segments, which will cause the panorama to bend (most obvious at the wall position and the top and bottom). Equirectangular images(i.e. panoramas)are stretched in the "latitude" direction. This is why there is a lot of data redundancy near the poles. When reducing image size in the editor, the effective texture resolution decreases as expected - exceptnear the ends (bottom and top). Sobe radial artifactsat both endswhen viewed in the panorama viewer(Consequently, equirectangular projection is only suitable for environments where texture distortion at the top and bottom of the simulated sphere is negligible.)

3.1.3.2 Just paste the image on the surface of the sphere and reverse it through the shader. This is limited by the pixels of the image and the effect will be blurry.

3.2 Convert the panorama to cubemap format as a skybox

3.2.1 Specific steps

Drag the panorama into the project

Adjust various properties of the dragged panorama. The Max Size is set according to your own panorama. and click the Apply button.

 

Create a new material ball

Change the Shader of the modified material ball to Cubemap

Then use the panorama with the properties we changed above as the cubemap here

Then select Window/ R endering / Lighting  Settings and assign the material ball from the previous step to the sky box.

(Note: The steps to add scripts to the camera are skipped here. For specific steps and script code, please refer to method 1)

3.2.2 Experimental results

In Game mode, the camera moves with the mouse and you can see the entire scene

 

And there is no distortion at the bottom and top

 

3.2.3 Conclusion analysis of this method

This method converts the panorama into cubemap format, uses Unity's built -in Skybox feature, and renders the image through the Skybox material .

 

3.3 Convert the panorama into six pictures through software (the six pictures are the six sides of the cube) to serve as a sky box

3.3.1 Specific steps

Open the following website to get the converted pictures, and save the six pictures to your computer.

http://www.development.net.cn/

Drag six pictures into the project

Guess you like

Origin blog.csdn.net/qq_44874004/article/details/131594425