From ae636105829877fba1c5703d803143c327afb466 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 22 Feb 2018 23:03:33 +0100 Subject: [PATCH] Added history of view to try to adjust for GPU slower than game --- interface/src/Application.cpp | 2 ++ interface/src/Application.h | 2 ++ interface/src/Application_render.cpp | 4 +++- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 4 +++- .../src/display-plugins/hmd/HmdDisplayPlugin.h | 1 + libraries/gpu/src/gpu/Context.cpp | 5 ++++- libraries/gpu/src/gpu/Context.h | 3 ++- libraries/gpu/src/gpu/Frame.h | 4 ++++ 8 files changed, 21 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b63cbd2527..62deddacb0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5447,7 +5447,9 @@ void Application::update(float deltaTime) { { QMutexLocker viewLocker(&_viewMutex); + appRenderArgs._prevView = glm::inverse(_displayViewFrustum.getView()); _myCamera.loadViewFrustum(_displayViewFrustum); + appRenderArgs._view = glm::inverse(_displayViewFrustum.getView()); } { diff --git a/interface/src/Application.h b/interface/src/Application.h index 75aed1e434..77a0080db8 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -617,6 +617,8 @@ private: struct AppRenderArgs { render::Args _renderArgs; glm::mat4 _eyeToWorld; + glm::mat4 _view; + glm::mat4 _prevView; glm::mat4 _eyeOffsets[2]; glm::mat4 _eyeProjections[2]; glm::mat4 _headPose; diff --git a/interface/src/Application_render.cpp b/interface/src/Application_render.cpp index 7532928491..0a26ddb9c0 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -64,6 +64,7 @@ void Application::paintGL() { glm::mat4 HMDSensorPose; glm::mat4 HMDSensorPrevPose; glm::mat4 eyeToWorld; + glm::mat4 prevEyeToWorld; glm::mat4 sensorToWorld; bool isStereo; @@ -92,7 +93,8 @@ void Application::paintGL() { { PROFILE_RANGE(render, "/gpuContextReset"); - _gpuContext->beginFrame(HMDSensorPose, HMDSensorPrevPose); + _gpuContext->beginFrame(_appRenderArgs._view, _appRenderArgs._prevView, + HMDSensorPose, HMDSensorPrevPose); // Reset the gpu::Context Stages // Back to the default framebuffer; gpu::doInBatch("Application_render::gpuContextReset", _gpuContext, [&](gpu::Batch& batch) { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 405ee33a86..f93178cf20 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -341,10 +341,12 @@ void HmdDisplayPlugin::updateFrameData() { auto invBatchPose = glm::inverse(_currentFrame->pose); auto invPrevBatchPose = glm::inverse(_currentFrame->prevPose); auto correction = invBatchPose * _currentPresentFrameInfo.presentPose; - auto prevCorrection = invPrevBatchPose * _previousPresentFrameInfo.presentPose; + auto prevCorrection = /*_currentFrame->prevView * glm::inverse(_prevRenderView) */ invPrevBatchPose * _previousPresentFrameInfo.presentPose; + getGLBackend()->setCameraCorrection(correction, prevCorrection); _previousPresentFrameInfo = _currentPresentFrameInfo; + _prevRenderView = _currentFrame->view; } } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index cbb5312871..7c63536c7b 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -80,6 +80,7 @@ protected: FrameInfo _currentPresentFrameInfo; FrameInfo _previousPresentFrameInfo; FrameInfo _currentRenderFrameInfo; + mat4 _prevRenderView; RateCounter<> _stutterRate; bool _disablePreview { true }; diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index e6fa983310..e4d8a88499 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -53,12 +53,15 @@ const std::string& Context::getBackendVersion() const { return _backend->getVersion(); } -void Context::beginFrame(const glm::mat4& renderPose, const glm::mat4& prevRenderPose) { +void Context::beginFrame(const glm::mat4& renderView, const glm::mat4& prevRenderView, + const glm::mat4& renderPose, const glm::mat4& prevRenderPose) { assert(!_frameActive); _frameActive = true; _currentFrame = std::make_shared(); _currentFrame->pose = renderPose; _currentFrame->prevPose = prevRenderPose; + _currentFrame->view = renderView; + _currentFrame->prevView = prevRenderView; if (!_frameRangeTimer) { _frameRangeTimer = std::make_shared("gpu::Context::Frame"); diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 2daf9da4ef..3667121c4e 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -161,7 +161,8 @@ public: const std::string& getBackendVersion() const; - void beginFrame(const glm::mat4& renderPose = glm::mat4(), const glm::mat4& prevRenderPose = glm::mat4()); + void beginFrame(const glm::mat4& renderView = glm::mat4(), const glm::mat4& prevRenderView = glm::mat4(), + const glm::mat4& renderPose = glm::mat4(), const glm::mat4& prevRenderPose = glm::mat4()); void appendFrameBatch(Batch& batch); FramePointer endFrame(); diff --git a/libraries/gpu/src/gpu/Frame.h b/libraries/gpu/src/gpu/Frame.h index e5365541b4..ea8e70c9bc 100644 --- a/libraries/gpu/src/gpu/Frame.h +++ b/libraries/gpu/src/gpu/Frame.h @@ -28,6 +28,10 @@ namespace gpu { StereoState stereoState; uint32_t frameIndex{ 0 }; + /// The view matrix used for rendering the frame, only applicable for HMDs + Mat4 view; + /// The view matrix used for rendering the previous frame, only applicable for HMDs + Mat4 prevView; /// The sensor pose used for rendering the frame, only applicable for HMDs Mat4 pose; /// The sensor pose used for rendering the previous frame, only applicable for HMDs