public override void Render(double time, Framebuffer fbuf, VREye eye) { var sorted = parent.Draws.OrderBy(a => (a.Item2 - Engine.CurrentPlayer.Position).LengthSquared); foreach (var(mesh_idx, _) in sorted) { parent.queue.RecordDraw(new DrawData() { State = parent.state, Meshes = new MeshData[] { new MeshData() { BaseInstance = 0, InstanceCount = 1, Mesh = parent.ChunkCache[mesh_idx].Item1 } } }); } parent.cullShader.Set("eyeIdx", (int)eye); parent.voxelShader.Set("eyeIdx", (int)eye); parent.queue.Build(Engine.Frustums[(int)eye], Engine.CurrentPlayer.Position); parent.cmdBuffer.Submit(); }
public Matrix4x4 CreateView(VREye eye, Vector3 positionOffset, Vector3 forward, Vector3 up) { Vector3 eyePos = GetEyePosition(eye) + positionOffset; Quaternion eyeQuat = GetEyeRotation(eye); Vector3 forwardTransformed = Vector3.Transform(forward, eyeQuat); Vector3 upTransformed = Vector3.Transform(up, eyeQuat); return(Matrix4x4.CreateLookAt(eyePos, eyePos + forwardTransformed, upTransformed)); }
public Matrix CreateView(VREye eye, Vector3 positionOffset, Vector3 forward, Vector3 up, out Vector3 eyePos, out Vector3 target) { eyePos = GetEyePosition(eye) + positionOffset; Quaternion eyeQuat = GetEyeRotation(eye); Vector3 forwardTransformed = Vector3.Transform(forward, eyeQuat); Vector3 upTransformed = Vector3.Transform(up, eyeQuat); target = eyePos + forwardTransformed; return(Matrix.LookAt(eyePos, target, upTransformed)); }
private void GetDeviceDescription() { var displayJson = context.getStringParameter("/display"); deviceDescriptor = DeviceDescriptor.Parse(displayJson); if (deviceDescriptor != null) { //// temporary overrides to simulate OSVR HDK //// without actually reading in the json value //deviceDescriptor.DisplayMode = "horz_side_by_side"; //deviceDescriptor.MonocularHorizontal = 90f; //deviceDescriptor.MonocularVertical = 101.25f; //deviceDescriptor.OverlapPercent = 100f; //deviceDescriptor.PitchTilt = 0f; //deviceDescriptor.K1Red = 0f; //deviceDescriptor.K1Green = 0f; //deviceDescriptor.K1Blue = 0f; //deviceDescriptor.RightRoll = 0f; //deviceDescriptor.LeftRoll = 0f; //deviceDescriptor.CenterProjX = 0.5f; //deviceDescriptor.CenterProjY = 0.5f; LeftEye = new VREye(pose, Eye.Left, deviceDescriptor); RightEye = new VREye(pose, Eye.Right, deviceDescriptor); switch (deviceDescriptor.DisplayMode) { case "full_screen": ViewMode = MonoGame.ViewMode.Mono; break; case "horz_side_by_side": case "vert_side_by_side": default: ViewMode = MonoGame.ViewMode.Stereo; break; } //SetResolution(deviceDescriptor.Width, deviceDescriptor.Height); // set resolution before FOV VerticalFieldOfView = MathHelper.Clamp(deviceDescriptor.MonocularVertical, 0, 180); // TODO: should we provide HorizontalFieldOfView? //SetDistortion(deviceDescriptor.K1Red, deviceDescriptor.K1Green, deviceDescriptor.K1Blue, // deviceDescriptor.CenterProjX, deviceDescriptor.CenterProjY); //set distortion shader // if the view needs to be rotated 180 degrees, create a parent game object that is flipped // 180 degrees on the z axis if (deviceDescriptor.Rotate180 > 0) { LeftEye.RotatePi = true; RightEye.RotatePi = true; } SetEyeRotation(deviceDescriptor.OverlapPercent, deviceDescriptor.MonocularHorizontal); SetEyeRoll(deviceDescriptor.LeftRoll, deviceDescriptor.RightRoll); } }
public Quaternion GetEyeRotation(VREye eye) { switch (eye) { case VREye.Left: return(LeftEyeRotation); case VREye.Right: return(RightEyeRotation); default: throw new VeldridException($"Invalid {nameof(VREye)}: {eye}."); } }
public Vector3 GetEyePosition(VREye eye) { switch (eye) { case VREye.Left: return(LeftEyePosition); case VREye.Right: return(RightEyePosition); default: throw new VeldridException($"Invalid {nameof(VREye)}: {eye}."); } }
//Update the pose of each eye, then update and render each eye's surfaces public void UpdateEyes() { for (uint eyeIndex = 0; eyeIndex < EyeCount; eyeIndex++) { //update the client DisplayController.UpdateClient(); //update the eye pose VREye eye = Eyes[eyeIndex]; eye.UpdateEyePose(_displayController.DisplayConfig.GetViewerEyePose(ViewerIndex, (byte)eyeIndex)); //update the eye's surfaces, includes a call to Render the surface eye.UpdateSurfaces(); } }
private void DrawSceneForEye(VREye eye, GameTime gameTime, RenderTarget2D renderTarget, IStereoSceneDrawer sceneDrawer) { graphicsDeviceManager.GraphicsDevice.SetRenderTarget(renderTarget); graphicsDeviceManager.GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true }; graphicsDeviceManager.GraphicsDevice.Clear(Color.Navy); sceneDrawer.DrawScene( gameTime: gameTime, viewport: graphicsDeviceManager.GraphicsDevice.Viewport, // Note: The transform is in view space, but VREye.Translation is in world // space, so we need to negate it here. stereoTransform: Matrix.CreateTranslation(Vector3.Negate(eye.Translation)), view: eye.Transform, projection: eye.Projection); }
public SceneState(VREye eyeSide, Matrix4D perspectiveMatrix, Matrix4D viewMatrix) { DiffuseIntensity = 0.65f; SpecularIntensity = 0.25f; AmbientIntensity = 0.10f; Shininess = 12; Camera = new Camera(); SunPosition = new Vector3D(200000, 0, 0); ModelMatrix = Matrix4D.Identity; HighResolutionSnapScale = 1; _isVRMode = false; _vrEye = eyeSide; _perspectiveMatrix = perspectiveMatrix; _viewMatrix = viewMatrix; HmdPoseMatrix = Matrix4D.Identity; }
//Creates the Eyes of this Viewer public void CreateEyes(uint eyeCount) { _eyeCount = eyeCount; //cache the number of eyes this viewer controls _eyes = new VREye[_eyeCount]; for (uint eyeIndex = 0; eyeIndex < _eyeCount; eyeIndex++) { GameObject eyeGameObject = new GameObject("Eye" + eyeIndex); //add an eye gameobject to the scene VREye eye = eyeGameObject.AddComponent <VREye>(); //add the VReye component eye.Viewer = this; //ASSUME THERE IS ONLY ONE VIEWER eye.EyeIndex = eyeIndex; //set the eye's index eyeGameObject.transform.parent = _displayController.transform; //child of DisplayController eyeGameObject.transform.localPosition = Vector3.zero; _eyes[eyeIndex] = eye; uint eyeSurfaceCount = DisplayController.DisplayConfig.GetNumSurfacesForViewerEye(ViewerIndex, (byte)eyeIndex); eye.CreateSurfaces(eyeSurfaceCount); } }
//this function finds and initializes each eye void CatalogEyes() { foreach (VREye currentEye in GetComponentsInChildren <VREye>()) { //catalog: switch (currentEye.eye) { case Eye.left: _leftEye = currentEye; break; case Eye.right: _rightEye = currentEye; break; } } }
//Update the pose of each eye, then update and render each eye's surfaces public void UpdateEyes() { if (DisplayController.UseRenderManager) { //Update RenderInfo #if UNITY_5_2 || UNITY_5_3 GL.IssuePluginEvent(DisplayController.RenderManager.GetRenderEventFunction(), OsvrRenderManager.UPDATE_RENDERINFO_EVENT); #else Debug.LogError("GL.IssuePluginEvent failed. This version of Unity cannot support RenderManager."); DisplayController.UseRenderManager = false; #endif } else { DisplayController.UpdateClient(); } for (uint eyeIndex = 0; eyeIndex < EyeCount; eyeIndex++) { //update the eye pose VREye eye = Eyes[eyeIndex]; //get eye pose from DisplayConfig //@todo fix bug with poses coming from RenderManager eye.UpdateEyePose(_displayController.DisplayConfig.GetViewerEyePose(ViewerIndex, (byte)eyeIndex)); /*if (DisplayController.UseRenderManager) * { * //get eye pose from RenderManager * eye.UpdateEyePose(DisplayController.RenderManager.GetRenderManagerEyePose((byte)eyeIndex)); * } * else * { * //get eye pose from DisplayConfig * eye.UpdateEyePose(_displayController.DisplayConfig.GetViewerEyePose(ViewerIndex, (byte)eyeIndex)); * }*/ // update the eye's surfaces, includes call to Render eye.UpdateSurfaces(); } }
private void UpdateCamera(Camera camera, int eyeIndex) { VREye eye = VRSystem.Instance.EyesProperties[eyeIndex]; VRPose pose = eye.Pose; // HACK... TODO: better method? camera.FieldOfView = VRSystem.Instance.FieldOfView; if (eyeIndex == 0) { VRSystem.Instance.Left.Camera = camera; } else if (eyeIndex == 1) { VRSystem.Instance.Right.Camera = camera; } var transform = camera.LocalTransform; transform.Translation = Monoscopic ? CenterEyeAnchor.LocalTransform.Translation : pose.Position; transform.Orientation = Monoscopic ? CenterEyeAnchor.LocalTransform.Orientation : pose.Orientation; camera.LocalTransform = transform; }
//Update the pose of each eye, then update and render each eye's surfaces public void UpdateEyes() { if (DisplayController.UseRenderManager) { // Update RenderInfo // RenderManager supported on unity 5.2+ #if !(UNITY_5_1 || UNIT_5_0 || UNITY_4_7 || UNITY_4_6) GL.IssuePluginEvent(DisplayController.RenderManager.GetRenderEventFunction(), OsvrRenderManager.UPDATE_RENDERINFO_EVENT); #else Debug.LogError("[OSVR-Unity] GL.IssuePluginEvent failed. This version of Unity cannot support RenderManager."); DisplayController.UseRenderManager = false; #endif } else { DisplayController.UpdateClient(); } for (uint eyeIndex = 0; eyeIndex < EyeCount; eyeIndex++) { //update the eye pose VREye eye = Eyes[eyeIndex]; if (DisplayController.UseRenderManager) { //get eye pose from RenderManager eye.UpdateEyePose(DisplayController.RenderManager.GetRenderManagerEyePose((byte)eyeIndex)); } else { //get eye pose from DisplayConfig eye.UpdateEyePose(_displayController.DisplayConfig.GetViewerEyePose(ViewerIndex, (byte)eyeIndex)); } // update the eye's surfaces, includes call to Render eye.UpdateSurfaces(); } }
protected override void Initialize() { base.Initialize(); this.ovrApplication = Game.Current.Application as OpenVRApplication; if (this.ovrApplication.HmdDetected) { var eyeTextures = this.ovrApplication.EyeTextures; this.EyesProperties = new VREye[3]; for (int i = 0; i < this.EyesProperties.Length; i++) { var vrEye = new VREye(); if (i < eyeTextures.Length) { vrEye.Texture = eyeTextures[i]; } this.EyesProperties[i] = vrEye; } } }
void Awake() { if (mirrorCamera == null) { VREye eye = FindObjectOfType <VREye>(); if (eye != null) { mirrorCamera = eye.GetComponent <Camera>(); } else { //if there are no eyes, try to find a camera on the current object mirrorCamera = GetComponent <Camera>(); } } if (fillTexture == null) { fillTexture = new Texture2D(1, 1); fillTexture.SetPixel(1, 1, Color.black); fillTexture.wrapMode = TextureWrapMode.Repeat; fillTexture.Apply(); } }
public nsISupports GetEyeParameters(VREye whichEye) { return(this.CallMethod <nsISupports>("getEyeParameters", whichEye)); }
//Creates the Eyes of this Viewer public void CreateEyes(uint eyeCount) { _eyeCount = eyeCount; //cache the number of eyes this viewer controls _eyes = new VREye[_eyeCount]; uint eyeIndex = 0; uint foundEyes = 0; //Check if there are already VREyes in the scene. //If so, use them instead of creating a new VREye[] eyesInScene = FindObjectsOfType <VREye>(); foundEyes = (uint)eyesInScene.Length; if (eyesInScene != null && foundEyes > 0) { for (eyeIndex = 0; eyeIndex < eyesInScene.Length; eyeIndex++) { VREye eye = eyesInScene[eyeIndex]; // get the VREye gameobject GameObject eyeGameObject = eye.gameObject; eyeGameObject.name = "VREye" + eyeIndex; eye.Viewer = this; eye.EyeIndex = eyeIndex; //set the eye's index eyeGameObject.transform.parent = DisplayController.transform; //child of DisplayController eyeGameObject.transform.localPosition = Vector3.zero; eyeGameObject.transform.rotation = this.transform.rotation; _eyes[eyeIndex] = eye; uint eyeSurfaceCount = DisplayController.DisplayConfig.GetNumSurfacesForViewerEye(ViewerIndex, (byte)eyeIndex); eye.CreateSurfaces(eyeSurfaceCount); } } for (; eyeIndex < _eyeCount; eyeIndex++) { if (foundEyes == 0) { GameObject eyeGameObject = new GameObject("Eye" + eyeIndex); //add an eye gameobject to the scene VREye eye = eyeGameObject.AddComponent <VREye>(); //add the VReye component eye.Viewer = this; //ASSUME THERE IS ONLY ONE VIEWER eye.EyeIndex = eyeIndex; //set the eye's index eyeGameObject.transform.parent = DisplayController.transform; //child of DisplayController eyeGameObject.transform.localPosition = Vector3.zero; eyeGameObject.transform.rotation = this.transform.rotation; _eyes[eyeIndex] = eye; //create the eye's rendering surface uint eyeSurfaceCount = DisplayController.DisplayConfig.GetNumSurfacesForViewerEye(ViewerIndex, (byte)eyeIndex); eye.CreateSurfaces(eyeSurfaceCount); } else { //if we need to create a new VREye, and there is already one in the scene (eyeIndex > 0), //duplicate the last eye found instead of creating new gameobjects GameObject eyeGameObject = (GameObject)Instantiate(_eyes[eyeIndex - 1].gameObject); VREye eye = eyeGameObject.GetComponent <VREye>(); //add the VReye component eye.Viewer = this; //ASSUME THERE IS ONLY ONE VIEWER eye.EyeIndex = eyeIndex; //set the eye's index eyeGameObject.name = "VREye" + eyeIndex; eyeGameObject.transform.parent = DisplayController.transform; //child of DisplayController eyeGameObject.transform.localPosition = Vector3.zero; eyeGameObject.transform.rotation = this.transform.rotation; _eyes[eyeIndex] = eye; uint eyeSurfaceCount = DisplayController.DisplayConfig.GetNumSurfacesForViewerEye(ViewerIndex, (byte)eyeIndex); eye.CreateSurfaces(eyeSurfaceCount); } } }
public abstract void Render(double time, Framebuffer fbuf, VREye eye);
//this function finds and initializes each eye void CatalogEyes() { foreach (VREye currentEye in GetComponentsInChildren<VREye>()) { //catalog: switch (currentEye.eye) { case Eye.left: _leftEye = currentEye; break; case Eye.right: _rightEye = currentEye; break; } } }
public void SetEyeParameter(VREye eye, double offsetX, double offsetY, double offsetZ, double upDegree, double rightDegree, double downDegree, double leftDegree) { this.CallVoidMethod("setEyeParameter", eye, offsetX, offsetY, offsetZ, upDegree, rightDegree, downDegree, leftDegree); }