Unity- Photosphere Photo Viewer for Google Cardboard
Asked Answered
C

2

9

I am trying to build a Photosphere-like application with Unity3D and use it along with Google cardboard.

I need to load different panoramic view photos and be able to view them stereoscopically, by using the Cardboard goggles.

I am having problem to use the pano images and render it into stereoscopic view in Unity.

Any suggestions will be gratefully received.

Crean answered 10/6, 2015 at 6:46 Comment(2)
Your question needs improvement. You didnt show any effort of your own, or an attempted solution that failed. Please see the sites FAQ to understand what are our standards that have to be met by questions.Irresolute
New to Stackoverflow and unity. I'd comment but I don't have enough rep. So, I followed exactly what you wrote down and I'm having a hard time trying to toggle through different skyboxes (materials). I messed around with GazeInputModule, but I don't really get it. What I want to do is: - look around stereoscopic environment - if paused for more than 1 or 2 seconds, button to toggle environment (skybox material) shows up. - use gaze or trigger of cardboard to go to next slide. Sorry I'm coming in so late to the party. Hoping you can help me. Thank you!!Livelong
P
24

Simplest solution that I can give to you:

A. Install your Unity Pro with Android Pro plugins, setup Cardboard SDK For Unity, install Android Build tools and SDK.

B Setup Skybox

  1. Get a stereoscopic panorama image (Might take a while to load the image as it is a high resolution image).

  2. In Unity, import the image, change the Texture Type to Cubemap. Select the Mapping as Cylindrical (Lat and Long).

  3. Create a Material, change the Shader to Skybox/Cubemap.

  4. Assign the texture to the material.

  5. In Unity 5 Pro topbar, select Window -> Ligthing, drag the material to the Skybox property. In this step you can do it programmatically. Combine these steps with the Cardboard assets and game objects. Voila, you've made a VR panorama stereoscopic Cardboard app! The whole setup is just take out your five minutes(excluding setup your tools :D).

If you're familiar with Unity, you know exactly what to do on my instructions. If you stuck at somewhere in my steps, feel free to ask me. Happy coding :)

Extra tips: You can make the large textures files into Asset Bundles, act like a dynamic content which is stored in the server. Your app is just simply a small-size empty app. When app launches, request and download the asset bundles from server then manipulate the textures. :)

Super extra tip: Don't forget to generate asset bundles under Android Build Settings. If not, your textures will be corrupted when the bundle is downloaded to Android phones.

Prevailing answered 13/6, 2015 at 16:56 Comment(20)
This is exactly what I needed, as I am also new to unity. Could you give any advice on how to change the material/texture? On tap of the screen, I want to change the image used in the skybox. I added a new game object and detecting the tap, but do not know how to change the image. Ideally I want to download that image, but I can't even figure out what I need to script to make that change happen with the resources I added to the project.Apanage
Good question. Skybox only accept materials. This might need abit work. What I do is I created a prefab (gameobject), a material for each texture.Prevailing
Select the game object, in top panel, Component->Mesh->MeshRenderer. The reason why I did this is because I want to use its materials component to store the material which is holding my texture, and later I can access it by using coding, something like gameObject.sharedMaterial[0]; So, one game object and one material for each texture. Now I found out that there's Component->Rendering->Skybox, which maybe you can use its material component to hold your material, and assign the Skybox directly.Prevailing
GameObjects and Materials size files are very small(few KBs) and they're just acting like containers storing informations like shaders info, classes and components in one place. So one game object and one material for each texture is not expensive. Besides, your game object can store more info like json string, so you can display extra information like room name, squarefoot etc... Lastly, you can make the gameobject into prefab, so you can store it as asset bundles.Prevailing
@Feliz The issue is that we do not know what image will be used, so we need to download it at runtime. I would love to create a bunch of materials and ship it in the app, but that does not fit our requirements.Apanage
@JasonHocker Yes this is what AssetBundles come in handy. You group the material, textures(images) and game objects altogether and generate it as one asset bundles binary, and store into your server and use HTTP request in your Unity app to download them. This whole process is just like DLC in games, where you see the downloading loading progress when you launch the game.Prevailing
Thanks @Felix. But our app is more of a photo viewer, which will be configured by non technical users, so our app needs to be able to change what it shows without needing a developer who can bundle those assets together.Apanage
@JasonHocker Yes the downside of Unity is you have to use Unity to create the asset Bundles.. This is very annoying. 5 months ago I tried to create a web application which I can let non-tech user to simply upload images and generate bundles but failed because converting images to textures only applicable by using UnityEditor framework, which means I can do image-to-texture conversion by programmatically ONLY on Unity Editor (Unity treat this process as debug mode), so I can't build a web tool for users to upload images and the application to handle the conversion.Prevailing
@JasonHocker My process : App launch -> Download latest app data from server in json format and parse the data (webserver Rest request) -> request again for downloading asset bundles. For generating app data(json) I created a web tool for non-tech people to use. So everytime when user launch the Unity app, it will check the latest data by using eTag header. Perhaps you can check the Unity forum to see the latest updates on this issue from time to time, or talk to the tech support team for better business solutions.Prevailing
@JasonHocker Unity is mainly a game engine, they treat the asset bundle thingy as generating DLC for games, which is supposedly and only can be done by the dev team... If your non-tech users are mainly your staffs(IT support/marketing), perhaps you can simplify the process and educate them to generate the asset bundles.Prevailing
@JasonHocker I just think of a thought. Set your Unity Editor in local server. Create a web tool that can access your server computer and manipulate the Unity to generate Asset Bundles. (Similar process to fire tests automation by using Jenkins in server computer and upload the app automatically to app store). Downside is this whole thingy might consume some time/human power for setup and development.Prevailing
What if the image isn't a photoshpere? Our images are more panoramic than a photosphere. How would I adjust? We are coming our app against the Google Camera app. The blur they use would be fine by us.Apanage
panoramic image ! = panorama 3D image. You need to understand the type of panoramic images that is used on VR.Prevailing
I understand that, but those are some of the images I'm being given. Wanted to see if there was any best suggestions. I'm thinking of putting it in the inside of a cylinder but then I lost the top and bottom.Apanage
@Felix - Apologies, I'm very late to this party, but I'm struggling here. I've built 2d apps in unity, but cannot fathom how to do the bit where you say "Combine these steps with the Cardboard assets and game objects." I've been looking up and down for Cardboard Tutorials. I've got a couple of panoramas, stereoscopic, but I can't for the life of me work out how to get them actually into the app. I drag the cardboardmain prefab into the editor, remove the existing camera, but nothing happens. Just empty viewports.Zephyr
@Felix no worries. I continued to battle away and got it working. I went back and did some basic reading and it was all pretty easy once I wrapped my head around how CardboardMain actually works. Thank you so much for replying though!Zephyr
@Felix how can you change texture type to "Cubemap" programmatically?Barong
@SauravBajracharya I can say it's 50:50. You can do it in debug mode but you can't when you need to publish your game. Go and look for TextureImporter, but it's inherited from Editor class, means it can be only accessed in editor, not after you compile your project. [Thanks for reminder as I need to edit answer above :].Prevailing
@SauravBajracharya If it's dynamic source, make it as Asset Bundles and put inside your server, and let your device download it from your app when it is launched.Prevailing
@Felix That's my exact problem. It works in the editor only. I have 100's of images that are fetched at runtime (one image at a time). So, i think i'd need a more dynamic solution that Unity Editor script. Anyway, thank you for replying.Barong
I
1

Make a sphere, write a shader so that it is not back culled and it can be seen from the inside. Use the pano image as a texture on the sphere. Place a VR camera rig in the center of the sphere. If you want true stereo, create two such spheres with separate textures for the left and right eye. Place the spheres at the lcoations of the cameras in the rig. Use layer culling so that each camera only sees the proper sphere.

Irresolute answered 10/6, 2015 at 8:26 Comment(2)
You don't have to do all these steps since you have Google Cardboard SDK for Unity. Simply setup your skybox by using stereoscopic panorama images and merge with the Cardboard assets and you can achieve the desired outcome. Setup own stereoscopic cameras might need you to write scipts for adjustment on distortion correction, fixing gyroscope rotation, tiling and offset of left and right spheres... and everything is already handled by the SDK. :DPrevailing
@Felix Well, by the VR camera rig i meant the CardboardMain prefab, should have been explicit. Didn't think about skyboxes tho, good poit! :)Irresolute

© 2022 - 2024 — McMap. All rights reserved.