From the feedback I receive for my developer blog posts I get to help a lot of new Unity3d VR developers get started. And one question I get asked a lot is about how to display panorama images.
I thought I’d write up a quick post about some ways you can incorporate those into Unity3d.
One common way is to create a 3d mesh of a sphere, and map a panoramic texture to the inside of it. However, an alternative way is to use Unity’s Skybox feature and render your image via a skybox material.
Firstly, you need to get a panoramic image…
Obtain a Panorama
One common format is the cylindrical projection (or more correctly an Equirectangular ) image. it’s a single rectangular image that wraps 360 degrees horizontally and 180 degrees vertically. It looks like this:
You can capture these types of images with a camera such as a Ricoh Theta S
Another common type of panorama is a cube map. The cube map has been a common way of creating skyboxes for games:
Many popular panorama creation software tools can output in cube map format.
One great tool I love for creating artificial space scapes is Spacescape which can output cube maps.
Use Unity’s SkyBox feature
So as I said above probably your first inclination is to assume you need a spherical mesh to map the image onto. But actually, even though I would say that is the most flexible way, you can use Unity3d’s built in skybox feature. The benefits of this is that you don’t need any meshes or to even write any code at all. You can quickly add this to your scene. The drawbacks is that Unity will typically create a larger texture making your app size larger.
OK, but lets assume we’ll use a skybox.
Step 1. Drag your image into Unity
If you don’t already have an image, download this one.
Step 2. Set the texture import settings to match the type of panoramic projection:
Firstly select Advanced (not cubemap – even if you have a cubemap).
Then, for cylindrical choose the mapping as “Latitude-Longitude Layout (Cylindrical).
And set your texture size as 4096 (larger then 4096 will fail to render on the GearVR):
If you have a cubemap single image, the choose the mapping as “6 Frames Layout (Cubic Environment)”.
If you have a cubemap comprised of 6 separate images, then for each one import as a standard texture but importantly set the Wrap mode to “clamp” to avoid seam lines.
Step 3.Create a Material for the texture
Create a new material., and for the shader choose “skybox/cubemap” and drag your texture onto the material.
If you are using 6 seperate images, the for the shader choose “skybox/6 sided” and drag each image onto the matching property.
Step 4. Add the Material as the Scene’s Skybox
Open the Scene’s Lighting settings (via the menu Window -> Lighting -> Scene tab)
At the top, under Environmental Lighting, drag the material onto the Skybox property:
Step 5. Done !
Set the project to VR mode (in Player Settings) and hit play in the Editor. You will now have a great panorama image to view !
Below is a unity package with a demonstration scene:
Skybox.unitypackage
March 21, 2016 at 7:19 am
Thanks for the guide! I was just looking for something like that Spacescape tool the other day, but couldn’t find anything and settled for playing Diablo all week instead of making something.
Looks like you’ve given me an excuse to get back to work..
March 21, 2016 at 5:48 pm
Great write up Peter!
I’d been wondering why my skybox quality was quite low, so thanks for the details on texture size. I had been under the impression that you had to use cubemaps with 6 images, so the settings above are great.
I’m going to do a few 3d tests with sterescopic images, so would love to see a part 2 to this in the future, i’ll send my results.
Keep the great tutes coming!
Regards,
Ryan
June 30, 2016 at 7:26 am
Wow, so THAT is how you get a clean skybox in Unity… I have been trying SO HARD to get my panoramas made in VUE to render properly with GI and all it took was turning convolution to NONE. And the file format is HDR. Thanks so much for this information. Now I hope it gets put into the manual for future versions of Unity
July 5, 2016 at 4:28 pm
Hi,
The quality of output is very good. But what If I use more number of 360 images. I am creating a virtual tour so i have nearly 25 images.
The output apk size is too heavy of around 300 mb.
Any way to reduce the file size apk.
July 5, 2016 at 9:50 pm
Hi Murali, I would not recommend this method for more then a couple of panoramas as the size is prohibitive. You are better creating a inward facing sphere and render a texture (or multiple) panorama image on to it. That is quite simple to do, obtain or generate your own sphere with say 5000 faces. Then UV map a single (or multiple) textures to it depending on how high resolution your images are, as typically 4096×2048 may be the limit on some hardware (eg: GearVR). Then simply swap the texture when needed with sphere.GetComponent().material.mainTexture = newPanoTexture;
Peter
July 6, 2016 at 3:55 am
Yes I tried with texture in inverted sphere but the quality is not good as in using skybox 360 cubemap texture
July 6, 2016 at 3:57 am
Another question. Is it possible to put a home button in a scene UI text which rotates along with head rotation do that home button is available all the time whichever direction I rotate.
Thanks
July 21, 2016 at 11:48 pm
Have you tried a panel with those elements nested within the camera object?
July 22, 2016 at 12:16 am
Which elements do you mean?
July 22, 2016 at 12:19 am
The home button Murali mentioned. If the panel is nested to the cam it will rotate with it.
July 22, 2016 at 12:31 am
oh yes, good suggestion!
July 26, 2016 at 11:57 pm
Hi,
this tutorial is great! Tried it with your sample image and it works very well.
A quick question though. What is the height of your camera (on a tripod) that took the sample image? I am curious to know and would like to follow it.
Thank you for your help!
July 28, 2016 at 4:08 pm
Thanks for sharing this Peter. Very useful!
I have a question though, how do I if I want to make the scene interactive in Unity3D? like in the above if I want to click on certain sections of walls/floors say and be able to display some information.
Could you guide me on this.
Thanks.
June 17, 2017 at 10:42 pm
I have a question though, how do I if I want to make the scene interactive in Unity3D? like in the above if I want to click on certain sections of walls/floors say and be able to display some information.
Could you guide me on this.
Thanks.
June 23, 2017 at 9:32 am
Hi Moni.
If you know the scene when you are building your app, then you can simplay add UI Canvas elements in world-space positioned where you want them. Then use the event system to allow the user to trigger them and open new scenes.
If you don’t know the scene in advance, like you are loading a set of panoramas for a floorplan from the file storage or web, then there is no built-in way with Unity to do this. But you could find one on the Asset Store, or just make your own by, for example, having a text file with a list of trigger points on the panorama (say lat, lon, radius) and if the user clicks in one of those then you handle it.
July 3, 2017 at 2:53 pm
I have created about 5 minutes of 360 pano video using Unity and it looks great in a 360 pano player on my PC and in my Android all-in-one VR device. What I need to do is create a 360 pano video player for Android in Unity so that I can add in my interactions and not just watch a video. I am hoping that I can do this in Unity.
July 30, 2016 at 2:43 am
alright awesome! I appreciate your reply. thank you for your help.