ShaderLookupDistort() : lookupTextureSize(512, 512), chroma(true) { OVR::Util::Render::StereoConfig stereoConfig; stereoConfig.SetHMDInfo(ovrHmdInfo); const OVR::Util::Render::DistortionConfig & distortion = stereoConfig.GetDistortionConfig(); // The Rift examples use a post-distortion scale to resize the // image upward after distorting it because their K values have // been chosen such that they always result in a scale > 1.0, and // thus shrink the image. However, we can correct for that by // finding the distortion scale the same way the OVR examples do, // and then pre-multiplying the constants by it. double postDistortionScale = 1.0 / stereoConfig.GetDistortionScale(); for (int i = 0; i < 4; ++i) { K[i] = (float)(distortion.K[i] * postDistortionScale); } // red channel correction chromaK[0] = glm::vec2( ovrHmdInfo.ChromaAbCorrection[0], ovrHmdInfo.ChromaAbCorrection[1]); // blue channel correction chromaK[1] = glm::vec2( ovrHmdInfo.ChromaAbCorrection[2], ovrHmdInfo.ChromaAbCorrection[3]); for (int i = 0; i < 2; ++i) { chromaK[i][0] = ((1.0 - chromaK[i][0]) * postDistortionScale) + 1.0; chromaK[i][1] *= postDistortionScale; } lensOffset = 1.0f - (2.0f * ovrHmdInfo.LensSeparationDistance / ovrHmdInfo.HScreenSize); }
DistortionHelper(const OVR::HMDInfo & ovrHmdInfo) { OVR::Util::Render::StereoConfig stereoConfig; stereoConfig.SetHMDInfo(ovrHmdInfo); const OVR::Util::Render::DistortionConfig & distortion = stereoConfig.GetDistortionConfig(); double postDistortionScale = 1.0 / stereoConfig.GetDistortionScale(); for (int i = 0; i < 4; ++i) { K[i] = distortion.K[i] * postDistortionScale; } lensOffset = distortion.XCenterOffset; eyeAspect = ovrHmdInfo.HScreenSize / 2.0f / ovrHmdInfo.VScreenSize; }