private void UpdateProfile() { GetProfile(profileData); CardboardProfile.Device device = new CardboardProfile.Device(); CardboardProfile.Screen screen = new CardboardProfile.Screen(); device.maxFOV.outer = profileData[0]; device.maxFOV.upper = profileData[1]; device.maxFOV.inner = profileData[2]; device.maxFOV.lower = profileData[3]; screen.width = profileData[4]; screen.height = profileData[5]; screen.border = profileData[6]; device.lenses.separation = profileData[7]; device.lenses.offset = profileData[8]; device.lenses.screenDistance = profileData[9]; device.lenses.alignment = (int)profileData[10]; device.distortion.Coef = new [] { profileData[11], profileData[12] }; Profile.screen = screen; Profile.device = device; float[] rect = new float[4]; Profile.GetLeftEyeNoLensTanAngles(rect); float maxRadius = CardboardProfile.GetMaxRadius(rect); Profile.device.inverse = CardboardProfile.ApproximateInverse( Profile.device.distortion, maxRadius); }
private void SetShaderGlobals() { // For any shaders that want to use these numbers for distortion correction. But only // if distortion correction is needed, yet not already being handled by another method. if (Cardboard.SDK.VRModeEnabled && Cardboard.SDK.DistortionCorrection == Cardboard.DistortionCorrectionMethod.None) { CardboardProfile p = Cardboard.SDK.Profile; // Distortion vertex shader currently setup for only 6 coefficients. if (p.device.inverse.Coef.Length > 6) { Debug.LogWarning("Inverse distortion correction has more than 6 coefficents. " + "Shader only supports 6."); } Matrix4x4 mat = new Matrix4x4() { }; for (int i = 0; i < p.device.inverse.Coef.Length; i++) { mat[i] = p.device.inverse.Coef[i]; } Shader.SetGlobalMatrix("_Undistortion", mat); float[] rect = new float[4]; p.GetLeftEyeVisibleTanAngles(rect); float r = CardboardProfile.GetMaxRadius(rect); Shader.SetGlobalFloat("_MaxRadSq", r * r); } }
private void SetShaderGlobals() { // For any shaders that want to use these numbers for distortion correction. CardboardProfile p = Cardboard.SDK.Profile; Shader.SetGlobalVector("_Undistortion", new Vector4(p.device.inverse.k1, p.device.inverse.k2)); Shader.SetGlobalVector("_Distortion", new Vector4(p.device.distortion.k1, p.device.distortion.k2)); float[] rect = new float[4]; p.GetLeftEyeVisibleTanAngles(rect); float r = CardboardProfile.GetMaxRadius(rect); Shader.SetGlobalFloat("_MaxRadSq", r * r); }