public ComputeStereoEyePosition ( Cardboard, eye, float proj11, float zScale ) : Vector3 | ||
eye | Cardboard, | |
proj11 | float | |
zScale | float | |
return | Vector3 |
private void SetupStereo(bool forceUpdate) { if (Svr.SvrSetting.IsVR9Device) { return; } GvrViewer.Instance.UpdateState(); bool updateValues = forceUpdate || // Being called from Start(), most likely. controller.keepStereoUpdated || // Parent camera may be animating. GvrViewer.Instance.ProfileChanged || // New QR code. cam.targetTexture == null && GvrViewer.Instance.StereoScreen != null; // Need to (re)assign targetTexture. if (updateValues) { // Set projection, viewport and targetTexture. UpdateStereoValues(); Svr.SvrLog.Log(eye + ",rect=" + cam.rect.ToString("F3")); Svr.SvrLog.Log(eye + ",projectionMatrix=" + cam.projectionMatrix.ToString("F3")); Svr.SvrLog.Log(eye + ",fov=" + cam.fieldOfView.ToString("F3")); } // Will need to update view transform if there is a COI, or if there is a remnant of // prior stereo-adjustment smoothing to finish off. bool haveCOI = controller.centerOfInterest != null && controller.centerOfInterest.gameObject.activeInHierarchy; if (updateValues || haveCOI || interpPosition < 1) { // Set view transform. float proj11 = cam.projectionMatrix[1, 1]; float zScale = transform.lossyScale.z; Vector3 eyePos = controller.ComputeStereoEyePosition(eye, proj11, zScale); // Apply smoothing only if updating position every frame. interpPosition = controller.keepStereoUpdated || haveCOI ? Time.deltaTime / (controller.stereoAdjustSmoothing + Time.deltaTime) : 1; //transform.localPosition = Vector3.Lerp(transform.localPosition, eyePos, interpPosition); } // Pass necessary information to any shaders doing distortion correction. if (GvrViewer.Instance.DistortionCorrection == GvrViewer.DistortionCorrectionMethod.None) { // Correction matrix for use in surface shaders that do vertex warping for distortion. // Have to compute it every frame because cameraToWorldMatrix is changing constantly. var fixProj = cam.cameraToWorldMatrix * Matrix4x4.Inverse(cam.projectionMatrix) * realProj; Shader.SetGlobalMatrix("_RealProjection", realProj); Shader.SetGlobalMatrix("_FixProjection", fixProj); Shader.EnableKeyword("GVR_DISTORTION"); } Shader.SetGlobalFloat("_NearClip", cam.nearClipPlane); }
private void SetupStereo() { Cardboard.SDK.UpdateState(); // Will need to update view transform if there is a COI, or if there is a remnant of // prior stereo-adjustment smoothing to finish off. bool haveCOI = controller.centerOfInterest != null && controller.centerOfInterest.gameObject.activeInHierarchy; bool updatePosition = haveCOI || interpPosition < 1; if (controller.keepStereoUpdated || Cardboard.SDK.ProfileChanged || cam.targetTexture == null && Cardboard.SDK.StereoScreen != null) { // Set projection and viewport. UpdateStereoValues(); // Also view transform. updatePosition = true; } if (updatePosition) { // Set view transform. float proj11 = cam.projectionMatrix[1, 1]; float zScale = transform.lossyScale.z; Vector3 eyePos = controller.ComputeStereoEyePosition(eye, proj11, zScale); // Apply smoothing only if updating position every frame. interpPosition = controller.keepStereoUpdated || haveCOI ? Time.deltaTime / (controller.stereoAdjustSmoothing + Time.deltaTime) : 1; transform.localPosition = Vector3.Lerp(transform.localPosition, eyePos, interpPosition); } // Pass necessary information to any shaders doing distortion correction. if (Cardboard.SDK.DistortionCorrection == Cardboard.DistortionCorrectionMethod.None) { // Correction matrix for use in surface shaders that do vertex warping for distortion. // Have to compute it every frame because cameraToWorldMatrix is changing constantly. var fixProj = cam.cameraToWorldMatrix * Matrix4x4.Inverse(cam.projectionMatrix) * realProj; Shader.SetGlobalMatrix("_RealProjection", realProj); Shader.SetGlobalMatrix("_FixProjection", fixProj); } else { // Not doing vertex-based distortion. Set up the parameters to make any vertex-warping // shaders in the project leave vertexes alone. Shader.SetGlobalMatrix("_RealProjection", cam.projectionMatrix); Shader.SetGlobalMatrix("_FixProjection", cam.cameraToWorldMatrix); } Shader.SetGlobalFloat("_NearClip", cam.nearClipPlane); }