Unity- Photosphere Photo Viewer for Google Cardboard - unity3d

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.

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
Get a stereoscopic panorama image (Might take a while to load the image as it is a high resolution image).
In Unity, import the image, change the Texture Type to Cubemap. Select the Mapping as Cylindrical (Lat and Long).
Create a Material, change the Shader to Skybox/Cubemap.
Assign the texture to the material.
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.

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.

Related

Unity - World canvas not seen in build executable

I am working on a moba game in unity, with photon and i use world canvas to display the player life. In the edit mode, i can play without any problem, but in build exe, i can't see the world space canvas. i tried using other cameras, the only way i can see those canvases is to set a camera to render target and display the render result in a raw image. Here are the settings:
Is this an unity bug? I am using the lightweight render pipeline from unity 2018.1.3. Or am I doing something wrong?
I fixed it by using 2D sprites

Unity gear VR reticle pointer shows double when focusing on close objects

I'm developing a VR app in Unity for the Samsung Gear VR and I'm trying to implement a pointer so the user can interact with the objects in the scene. When you look at distant objects it looks fine, but when you focus on close objects (which is highly needed for the app mechanics) the pointer appears to be duplicated, so you need to center the desired object in the middle of the points :P
What I've tried
-Using the GvrReticlePointer that comes with the GoogleVR package for cardboard
-Creating my own pointer by adding a canvas to the main camera with an image in the center
-Changing some of the Camera settings like field of view, stereo separation, etc.
-Configure my phone via a QR code http://imgur.com/fVrNrQk
Steps to reproduce (With canvas added to camera)
1.- Create a simple scene with a few objects to look at in Unity
2.- Set build settings for android
3.- Configure player settings to enable "Virtiual Reality Supported"
4.- Add Oculus as Virtual Reality SDK
5.- Set package name and minimum API level
6.- Add a canvas to the camera
7.- Add an image to the canvas, a cross will do the job
Observations
I'm using Unity 5.6.0b10 since google cardboard's site recommends using this version for the GoogleVR package. And I'm using the Samsung Gear VR with a Samsung Galaxy S6 edge + phone.
Solved
Apparently this is a well documented issue called voluntary Diplopia, and it's a human bug not a software one (read here, Unity's documentation, section The Reticle Interaction in VR).
The problem is trying to put the reticle at a fixed point in the user interface, like traditional 3D games. When looking at closer objects in VR this is going to cause this seeing double problem.
The solution is to position the reticle at the point in the 3D space the user is looking at. If he's looking closer, the reticle is drawn closer. Of course now you also have to scale the reticle accordingly, so the users can see it the same size no matter where they're looking at.
Unity also provides some example scripts about this, you can find them in the assets store, is called VR Samples.
Now I have performance issues (I'm working on mobile platforms): sometimes, when you turn your head fast you can see the reticle where it was drawn before. But looks way better than the double reticle version.

Vuforia recognition of hand painted marker

I have blank sheet and I want to do AR model to this sheet. I have idea do it with painted marker. For example: cross, square or something easy marker which you can paint to sheet. So how can i do it??? I use unity.
Here you want a simple marker so some simple options are:
ARToolkit Simple markers like Hiro KanZI marker (it's an open source and completely free AR Library):
http://artoolkit.org/documentation/doku.php?id=3_Marker_Training:marker_multi
Using Vuforia, you can try "Frame Marker". Vuforia provides more than 500 simple designs. You can paint it or stick it on your sheet:
https://developer.vuforia.com/library/articles/Training/Frame-Markers-Guide
FYI: Vuforia and Artoolkit for both Unity packages are available for free. You just have to import it into your Unity project.
I am writing from memory, so it might not be entirely correct.
Decide what marker you want to use.
Draw it on paper. Note, however, that the Vuforia SDK identifies points of interest in a target image (most often that is corners), so the more detailed a photo, the more points of interest, which is why their samples use high resolution images of e.g. lots of little stones. Drawing something like a square, cross, or some other simplistic marker, does not work very well.
Take a photo of it and transfer it to your computer.
Download Vuforia's Augmented Reality SDK for Unity.
Register on the Vuforia website and add your photo as an Image Target. Then save/download the database unity package they create for you from your image.
Also get a licence key.
In a blank Unity scene, import the SDK.
Add an AR camera prefab.
Add an image target prefab.
Import the downloaded database package (containing your uploaded image).
On the image target inspector, change the behaviour to use your image as the image target.
On the AR camera inspector, add your licence key, and specify the image target database.
Create or import some 3D model / primitive. Make it a child of the image target, and position it to sit on top of the image target.
Make sure the AR camera is looking at the image target.
Build the project and run the project, that's about it.
There should be many tutorials online, just google for something like vuforia augmented reality tutorial

Sphere not rendering in Unity for Google Cardboard

I was following this blog post on how to implement 360 degree video in Unity. At the end, I used ffmpeg to split the video into individual frames as recommended. I also set the first frame as the texture for each material on each sphere. The end result looks like this
bad sphere
The big problem though is that once I build and run it on my phone or just play the scene itself, the sphere simply fails to render. Could this be caused by the texture being the first frame? Or am I making some other sort of error? Many thanks.
Movies in Unity are usually rendered as textures on objects. On mobile the issue becomes that the device only wants to display video in a video player, so the Unity class MovieTexture is not supported.
I am having success circumventing this, and successfully rendering 360-video on the inside of a sphere using a Unity plug-in from the Unity Asset Store called, Easy Movie Texture.
For working on a Mac, here's what I did:
Download the Easy Movie Texture plug-in from the Unity Asset Store
Open the Demo Sphere demo scene from Assets/EasyMovieTexture/Scene
Create a new (empty) Prefab to your project, and drag the Sphere GameObject from the Demo Sphere scene onto the Prefab.
Reopen your Cardboard scene and drag the new videosphere prefab into your hierarchy.
Open your source 360-video in Quicktime
File -> Export -> 720p
Change file extension from '.mov' to '.mp4'
Drag your new mp4 file into your projects Assets/Streaming Assets directory. Note: don't import through the menu system, as this will force Unity to convert to OGG.
On the "Media Player Ctrl" script component of your videosphere GameObject, locate the "Str_File_Name" field and provide the FULL filename of your newly exported video file. Make sure to include the extension as part of the string, "mymovie.mp4".
Pretty sure that's everything. Hope it helps other folks stuck on this problem.
Final note, the video will only render on the device. In the editor you will only see a white texture on the sphere. You have to publish to the device in order to see your awesome 360-video.

How to create VR Video player using Google Cardboard SDK for Unity

I just downloaded Google Cardboard SDK for unity. I am fine and able to create VR project. Setup is fine and everything is working fine.
I am noob at VR Apps. Just stepped in VR Apps.
I am planing to create my own VR Enabled Video Player for android, Just like the default Google Cardboard Youtube player.
Can any one suggest me a link or can guide me in developing this app.
Scott Driscoll's answer totally works. I had some initial problems getting the Easy Movie Texture Unity plug-in to work for me, but finally figured it out, and it works flawlessly. I now have 360-video running as a texture on the inside of a sphere on my iPhone 6. And I have to say, I didn't think it would happen.
For working on a Mac, here's what I did:
Download the Easy Movie Texture plug-in from the Unity Asset Store
Open the Demo Sphere demo scene from Assets/EasyMovieTexture/Scene
Create a new (empty) Prefab to your project, and drag the Sphere GameObject from the Demo Sphere scene onto the Prefab.
Reopen your Cardboard scene and drag the new videosphere prefab into your hierarchy.
Open your source 360-video in Quicktime
File -> Export -> 720p
Change file extension from '.mov' to '.mp4'
Drag your new mp4 file into your projects Assets/Streaming Assets directory. Note: don't import through the menu system, as this will force Unity to convert to OGG.
On the "Media Player Ctrl" script component of your videosphere GameObject, locate the "Str_File_Name" field and provide the FULL filename. Make sure to include the extension as part of the string, "mymovie.mp4".
Pretty sure that's everything. Hope it helps other folks stuck on this problem. Thanks Scott Driscoll!
One last note, you can only view the video on the phone, not in preview in the editor. It would be better if it didn't work this way, but really once the initial issues of resolution and placement are resolved, I don't really need to see the video every time I run the scene in the editor.
Here are the major steps for how we do this:
Add a sphere with an equirectangular UV mapping and inward facing normals around the camera.
Purchase a plugin to play a movie on that sphere’s texture. I recommend Easy Movie Texture.
Use mp4s or ogg vorbis files that are compatible with the platform. This is phone and OS dependent.
Full details: http://immersivetechblog.foundry45.com/2015/07/31/implementing-360-video-in-unity-for-gear-vr-and-cardboard/
I saw the answers above but all of them either required Easy Movie Texture Unity plug-in or coding your way through..
There's another easy solution to this as well which won't require you to buy that asset or code your way through..
Oculus provides an already built free sample framework which you can use without much trouble..
The solution below shows both how to create both a photo viewer as well as video viewer for Unity..
Building your 360 degree PhotoViewer:
Go to Blender and delete all the prexisitng objects (if any) and make an icosphere and increase the subdivisions to a point where it looks more like a sphere like 6 and hit Generate UVs (both these options are found in settings underneath the create tab in add to sphere) and go to edit and choose Flip Normals so that you can see inside out rather than outside inwards and save it.
Bring that icosphere saved file into your assets folder in Unity.
Download GoogleVR SDK and bring GoogleVR plugin into your assets folder as well.. (You can download it here: https://developers.google.com/vr/unity/)
Delete the main camera and directional light present in default.
Bring your icosphere asset into your project.
Bring GVR Main from your assets folder into your project: GoogleVR plugin -> Legacy -> Prefab -> GVR Main
Take any panaroma or 360 photo and bring it in your assets folder.
Take this photo in your asset folder and put it above the icosphere in your scene and hit play. You should be able to see your 360 degree photos.
Building your 360 degree MoviePlayer:
Step 1 same.
Now go to the Oculus developer console and download this file and bring this to your assets folder. https://developer3.oculus.com/downloads/game-engines/1.5.0/Oculus_Sample_Framework_for_Unity_5_Project/
Bring this file you downloaded above to your assets folder.
Find MoviePlayer in your assetsFolder in bring it in your project.
Bring the icosphere you downloaded into your assets folder as well and scale it a little bit so you can see correctly.
Copy the MoviePlayer sample script and Audio Source in the components of the MovieSurface from the project and add it in the components of the sphere in the scene, also get rid of the animator in the components of the sphere.
Bring the Movie Player material found in the Materials under Mesh Renderer in MovieSurface and add it on top of your sphere.
Now this sphere formed is your 360 degree movie player so store it as an asset in the asset folder.
Create a new scene, delete the directional light and bring your saved icosphere asset into this scene and move the main camera at the centre.
Delete the non required assets to clean up some space in your project other than MoviePlayer, Plugins and Streaming Assets.
You'll have to convert the desired mp4 into an ogv file as well for the plugin to play in VR and bring both the mp4 and ogv files into your streaming assets folder and change the MovieName and click Play. You should be able to see your 360 degree video playing.
*To play it in your devices, just go to build settings and choose the desired platform and delete all the scene and just Add Open Scene and click on the Virtual Reality Supported in Other Settings under Player Settings.
To play it in your android phone you need to download the GoogleVR SDK just like above and bring it in your assets folder and find the GVRViewerMain in the assets folder and bring it in the scene and uncheck the Virtual Reality Supported you did above and just build and run the whole thing in your device (You should be able to see the view in you game mode when you hit play in Unity).
You should be able to see the video in your respective gear.
There's also a video tutorial available but I'm only able to share only 2 links with my new StackOverFlow profile.
I can't help you with Unity, but in java, you can create a texture with OpenGL-ES:
private static int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
....
GLES20.glGenTextures(1, textureHandle, 0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandle[0]);
Use it to create a surface texture and a surface:
SurfaceTexture surfaceTexture = new SurfaceTexture(textureHandle[0]);
Surface surface = new Surface(surfaceTexture);
And then pass that surface to android.media.MediaPlayer:
MediaPlayer mediaPlayer = new MediaPlayer(getContext(), uriToMyMediaFile, surface);
Bind that texture to a square in your scene and call this every frame:
surfaceTexture.updateTexImage()
and the video will play when you call mediaPlayer.start();
If Unity allows you to write your own java code to run behind the scenes, this should work if you bind that texture to a surface from Unity.
If you have a video stream that you can't play with mediaPlayer (like a live video chat, etc), you can use the surface with android.media.MediaCodec as well, but there's a lot more setup work involved.
This has become very simple for Unity 5.6 and above.
You just need a sphere with its normals inverted which you can either find online or just go to blender and make an IcoSphere and flip its normals or you can use a shader to do the same on a normal sphere. In either case use an Unlit texture for the shader.
Add a Video Player in the component which comes default with Unity to this sphere.
Add any 360 degree video to this Video Player. You can also add an online link as well. And it plays consistently well throughout the range of platforms from GoogleVR to SteamVR.
The only downside is, it only plays monoscopic images/videos by default and there requires some tweaking to run stereoscopic images/videos.