Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cardboard - setting up culling mask works in editor but not on Android

Discussion in 'AR/VR (XR) Discussion' started by eyalfx, Mar 14, 2017.

  1. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    I'm using a script that in runtime sets up the culling mask on left and right eye, and it works great in editor but not on Android device.
    I tried any of the solutions in this post https://github.com/googlevr/gvr-unity-sdk/issues/263 but none of them work on 5.6.b11
    I also tried searching for cameras FindObjectsOfType() in runtime and can only find 1 camera (main camera) which is strange. I thought that Unity instantiate 2 new cameras (left and right) to render the scene in stereo which I was hoping to find and change the culling mask manually.
    Did anyone figured it out?
    Thanks.
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    We don't create two cameras for left and right eye with the native integration. We just use the same camera and change the matrices as appropriate for the rendering pass. We also set up a shared cull volume that encompasses both eyes to make sure that we clip correctly for each render pass.

    What is it you are trying to accomplish? Have you tried SetStereoViewMatrix?
     
  3. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    I'm trying to add 2 spheres for a stereo 360 texture. I have the rendering layers setup for left and right eye, and I need to setup the left and right cameras culling mask accordingly so they each render the correct sphere.
    Is there any ways to achieve it ? I'm not sure how SetStereoViewMatrix can help.
    Thanks.
     
  4. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    Is there a way to call OnPreRender() before each eye gets render and modify the sphere material to the appropriate left/right texture?
     
  5. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    I'm still not able to do find a solution for that. I'm sure using stereo photos/videos is a feature that many users will want. Can you think of any solution to achieve that?
    Thanks.
     
  6. Rapskalian

    Rapskalian

    Joined:
    Jan 4, 2011
    Posts:
    45
  7. Rapskalian

    Rapskalian

    Joined:
    Jan 4, 2011
    Posts:
    45
    I believe I have solved this issue. I'll copy my answer to the above Github issue here for posterity:

    It is not necessary to use two spheres to accomplish 360 stereo video playback! You can use only one with a bit of shader magic.

    First of all, I'm using Easy Movie Texture in order to render .mp4 files to texture on Android. This package is referenced often and seems to be the most recommended solution for accomplishing this on Android, but this solution should also work for people that have rolled their own.

    From there, drag out a sphere, but do NOT use the Unity standard sphere. The UVs on it are not appropriate for equirectangular videos which causes distortion near the poles. Instead, use the pSphere09 mesh that comes with Easy Movie Texture. Or alternatively, you could model up your own in Blender and use that.

    Now the key ingredient: there is a shader bundled with the GVR Unity SDK called VideoDemoInsideShader. This is what you want to attach to your sphere's material. To make this work you have to make some edits to the shader code itself, because currently this shader is flipping normals and UVs manually. We don't need this. We already flipped and mapped the UVs correctly in Blender (or are using a sphere that has, like pSphere09). What we do need is the special logic this shader contains for splitting the view to each eye. Comment out the following lines in the shader:

    Code (CSharp):
    1. // cull the outside, since we want to draw on the inside of the mesh.
    2. // Cull Front      <--- Comment this out!
    3.  
    4. // ...
    5.  
    6. v2f vert (appdata_base v) {
    7.     v2f o;
    8.     // invert the normal of the vertex
    9.     // v.normal.xyz = v.normal * -1;                        <----- Comment this out!
    10.     o.pos = GvrUnityObjectToClipPos(v.vertex);
    11.     o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
    12.     if (_StereoVideo > 0) {
    13.         o.uv.y *= 0.5f;
    14.         if(unity_StereoEyeIndex == 0) {
    15.             o.uv.y += 0.5f;
    16.         }
    17.     }
    18.     // o.uv.x = 1 - o.uv.x;                   <---- Comment this out!!
    19.     return o;
    20. }
    21. }
    Now when you set up the Media Player Control component to point to the sphere as its target (this is Easy Movie Texture specific again), it should be properly splitting the video to each eye using a shader. No need to use two spheres and culling masks!
     
    Last edited: Mar 23, 2017
  8. eyalfx

    eyalfx

    Joined:
    Oct 8, 2010
    Posts:
    108
    Thank you so much for posting the solution.
    That works!!!
     
  9. ResoundingStudio

    ResoundingStudio

    Joined:
    Jun 6, 2017
    Posts:
    1
    I got this working, but the bottom (right) shows in both cameras. This was the same problem I was having with the two spheres, two cameras, and culling masks solution. I don't know what I'm missing. Any help would be very much appreciated! Thanks!