Allow override of near/far clip planes in Oculus and OpenVR plugins

This commit is contained in:
Anthony J. Thibault 2017-09-06 11:02:44 -07:00
parent a5553d5e1c
commit 2f850826f2
6 changed files with 35 additions and 2 deletions

View file

@ -2596,7 +2596,7 @@ void Application::paintGL() {
mat4 eyeOffsets[2];
mat4 eyeProjections[2];
// adjust near clip plane by heightRatio
// adjust near clip plane by sensorToWorldScale
auto baseProjection = glm::perspective(renderArgs.getViewFrustum().getFieldOfView(),
renderArgs.getViewFrustum().getAspectRatio(),
renderArgs.getViewFrustum().getNearClip() * sensorToWorldScale,

View file

@ -27,7 +27,7 @@ public:
bool isHmd() const override final { return true; }
float getIPD() const override final { return _ipd; }
glm::mat4 getEyeToHeadTransform(Eye eye) const override final { return _eyeOffsets[eye]; }
glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const override final { return _eyeProjections[eye]; }
glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const override { return _eyeProjections[eye]; }
glm::mat4 getCullingProjection(const glm::mat4& baseProjection) const override final { return _cullingProjection; }
glm::uvec2 getRecommendedUiSize() const override final;
glm::uvec2 getRecommendedRenderSize() const override final { return _renderTargetSize; }

View file

@ -60,6 +60,22 @@ bool OculusBaseDisplayPlugin::isSupported() const {
return oculusAvailable();
}
glm::mat4 OculusBaseDisplayPlugin::getEyeProjection(Eye eye, const glm::mat4& baseProjection) const {
if (_session) {
ViewFrustum baseFrustum;
baseFrustum.setProjection(baseProjection);
float baseNearClip = baseFrustum.getNearClip();
float baseFarClip = baseFrustum.getFarClip();
ovrEyeType ovrEye = (eye == Left) ? ovrEye_Left : ovrEye_Right;
ovrFovPort fovPort = _hmdDesc.DefaultEyeFov[eye];
ovrEyeRenderDesc& erd = ovr_GetRenderDesc(_session, ovrEye, fovPort);
ovrMatrix4f ovrPerspectiveProjection = ovrMatrix4f_Projection(erd.Fov, baseNearClip, baseFarClip, ovrProjection_ClipRangeOpenGL);
return toGlm(ovrPerspectiveProjection);
} else {
return baseProjection;
}
}
// DLL based display plugins MUST initialize GLEW inside the DLL code.
void OculusBaseDisplayPlugin::customizeContext() {
glewExperimental = true;

View file

@ -19,6 +19,8 @@ public:
~OculusBaseDisplayPlugin();
bool isSupported() const override;
glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const override;
bool hasAsyncReprojection() const override { return true; }

View file

@ -357,6 +357,19 @@ bool OpenVrDisplayPlugin::isSupported() const {
return openVrSupported();
}
glm::mat4 OpenVrDisplayPlugin::getEyeProjection(Eye eye, const glm::mat4& baseProjection) const {
if (_system) {
ViewFrustum baseFrustum;
baseFrustum.setProjection(baseProjection);
float baseNearClip = baseFrustum.getNearClip();
float baseFarClip = baseFrustum.getFarClip();
vr::EVREye openVrEye = (eye == Left) ? vr::Eye_Left : vr::Eye_Right;
return toGlm(_system->GetProjectionMatrix(openVrEye, baseNearClip, baseFarClip));
} else {
return baseProjection;
}
}
float OpenVrDisplayPlugin::getTargetFrameRate() const {
if (forceInterleavedReprojection && !_asyncReprojectionActive) {
return TARGET_RATE_OpenVr / 2.0f;

View file

@ -38,6 +38,8 @@ public:
bool isSupported() const override;
const QString getName() const override { return NAME; }
glm::mat4 getEyeProjection(Eye eye, const glm::mat4& baseProjection) const override;
void init() override;
float getTargetFrameRate() const override;