Example #1
0
            //Create this Eye's VRSurfaces.
            //Each VRSurface has a camera component which controls rendering for the VREye
            public void CreateSurfaces(uint surfaceCount)
            {
                _surfaceCount = surfaceCount;
                _surfaces     = new VRSurface[_surfaceCount];
                if (surfaceCount != NUM_SURFACES)
                {
                    Debug.LogError("Eye" + _eyeIndex + " has " + surfaceCount + " surfaces, but " +
                                   "this implementation requires exactly one surface per eye.");
                    return;
                }
                //loop through surfaces because at some point we could support eyes with multiple surfaces
                //but this implementation currently supports exactly one
                for (uint surfaceIndex = 0; surfaceIndex < surfaceCount; surfaceIndex++)
                {
                    GameObject surfaceGameObject = new GameObject("Surface");
                    VRSurface  surface           = surfaceGameObject.AddComponent <VRSurface>();
                    surface.Eye    = this;
                    surface.Camera = surfaceGameObject.GetComponent <Camera>(); //VRSurface has camera component by default
                    CopyCamera(Viewer.Camera, surface.Camera);                  //copy camera properties from the "dummy" camera to surface camera
                    surface.Camera.enabled                    = false;          //disabled so we can control rendering manually
                    surfaceGameObject.transform.parent        = this.transform; //surface is child of Eye
                    surfaceGameObject.transform.localPosition = Vector3.zero;
                    Surfaces[surfaceIndex]                    = surface;

                    //distortion
                    bool useDistortion = Viewer.DisplayController.DisplayConfig.DoesViewerEyeSurfaceWantDistortion(Viewer.ViewerIndex, (byte)_eyeIndex, surfaceIndex);
                    if (useDistortion)
                    {
                        //@todo figure out which type of distortion to use
                        //right now, there is only one option, SurfaceRadialDistortion
                        //get distortion parameters
                        OSVR.ClientKit.RadialDistortionParameters distortionParameters =
                            Viewer.DisplayController.DisplayConfig.GetViewerEyeSurfaceRadialDistortion(
                                Viewer.ViewerIndex, (byte)_eyeIndex, surfaceIndex);

                        surface.SetDistortion(distortionParameters);
                    }

                    //render manager
                    if (Viewer.DisplayController.UseRenderManager)
                    {
                        if (surface.GetRenderTexture() == null)
                        {
                            //Set the surfaces viewport from RenderManager
                            surface.SetViewport(Viewer.DisplayController.RenderManager.GetEyeViewport((int)EyeIndex));

                            //create a RenderTexture for this eye's camera to render into
                            RenderTexture renderTexture = new RenderTexture(surface.Viewport.Width, surface.Viewport.Height, 24, RenderTextureFormat.Default);
                            surface.SetRenderTexture(renderTexture);
                        }
                    }
                }
            }