From 4edfe6c9ab230917c7b37df088bd0023a919070f Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Tue, 20 Feb 2018 14:48:21 +0100 Subject: [PATCH] Trying to keep track of a better previous correction --- interface/src/Application.cpp | 3 ++- interface/src/Application.h | 1 + interface/src/Application_render.cpp | 4 +++- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 2 +- .../src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp | 2 +- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 10 ++++++---- .../src/display-plugins/hmd/HmdDisplayPlugin.h | 1 + libraries/gpu-gl/src/gpu/gl/GLBackend.cpp | 7 ++++--- libraries/gpu-gl/src/gpu/gl/GLBackend.h | 2 +- libraries/gpu/src/gpu/Context.cpp | 3 ++- libraries/gpu/src/gpu/Context.h | 2 +- libraries/gpu/src/gpu/Frame.h | 2 ++ 12 files changed, 25 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 07ca337878..a993b4c830 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5275,7 +5275,8 @@ void Application::update(float deltaTime) { editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) { PerformanceTimer perfTimer("editRenderArgs"); - appRenderArgs._headPose= getHMDSensorPose(); + appRenderArgs._prevHeadPose = appRenderArgs._headPose; + appRenderArgs._headPose = getHMDSensorPose(); auto myAvatar = getMyAvatar(); diff --git a/interface/src/Application.h b/interface/src/Application.h index d4041aa3be..75aed1e434 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -620,6 +620,7 @@ private: glm::mat4 _eyeOffsets[2]; glm::mat4 _eyeProjections[2]; glm::mat4 _headPose; + glm::mat4 _prevHeadPose; glm::mat4 _sensorToWorld; float _sensorToWorldScale { 1.0f }; bool _isStereo{ false }; diff --git a/interface/src/Application_render.cpp b/interface/src/Application_render.cpp index 868299537c..7532928491 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -62,6 +62,7 @@ void Application::paintGL() { RenderArgs renderArgs; glm::mat4 HMDSensorPose; + glm::mat4 HMDSensorPrevPose; glm::mat4 eyeToWorld; glm::mat4 sensorToWorld; @@ -79,6 +80,7 @@ void Application::paintGL() { } HMDSensorPose = _appRenderArgs._headPose; + HMDSensorPrevPose = _appRenderArgs._prevHeadPose; eyeToWorld = _appRenderArgs._eyeToWorld; sensorToWorld = _appRenderArgs._sensorToWorld; isStereo = _appRenderArgs._isStereo; @@ -90,7 +92,7 @@ void Application::paintGL() { { PROFILE_RANGE(render, "/gpuContextReset"); - _gpuContext->beginFrame(HMDSensorPose); + _gpuContext->beginFrame(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/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index fbae89fb70..31ed9572e9 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -361,7 +361,7 @@ void OpenGLDisplayPlugin::customizeContext() { auto presentThread = DependencyManager::get(); Q_ASSERT(thread() == presentThread->thread()); - getGLBackend()->setCameraCorrection(mat4(), true); + getGLBackend()->setCameraCorrection(mat4(), mat4(), true); for (auto& cursorValue : _cursorsData) { auto& cursorData = cursorValue.second; diff --git a/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp index 4c89cf8821..40063652c8 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp @@ -85,6 +85,6 @@ void DebugHmdDisplayPlugin::updatePresentPose() { // Simulates head pose latency correction _currentPresentFrameInfo.presentPose = glm::mat4_cast(glm::angleAxis(yaw, Vectors::UP)) * - glm::mat4_cast(glm::angleAxis(pitch, Vectors::RIGHT)); + glm::mat4_cast(glm::angleAxis(pitch, Vectors::RIGHT)) ; } } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 292e829771..22dd7823f6 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -330,6 +330,7 @@ void HmdDisplayPlugin::updateFrameData() { } } if (newFrameIndex != INVALID_FRAME) { + _previousPresentFrameInfo = _currentPresentFrameInfo; _currentPresentFrameInfo = _frameInfos[newFrameIndex]; } }); @@ -338,10 +339,11 @@ void HmdDisplayPlugin::updateFrameData() { updatePresentPose(); if (_currentFrame) { - auto batchPose = _currentFrame->pose; - auto currentPose = _currentPresentFrameInfo.presentPose; - auto correction = glm::inverse(batchPose) * currentPose; - getGLBackend()->setCameraCorrection(correction); + auto invBatchPose = glm::inverse(_currentFrame->pose); + auto invPrevBatchPose = glm::inverse(_currentFrame->prevPose); + auto correction = invBatchPose * _currentPresentFrameInfo.presentPose; + auto prevCorrection = invPrevBatchPose * _previousPresentFrameInfo.presentPose; + getGLBackend()->setCameraCorrection(correction, prevCorrection); } } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index 78d5904c7d..cbb5312871 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -78,6 +78,7 @@ protected: QMap _frameInfos; FrameInfo _currentPresentFrameInfo; + FrameInfo _previousPresentFrameInfo; FrameInfo _currentRenderFrameInfo; RateCounter<> _stutterRate; diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index de1e8f9359..1d2bafc5db 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -760,10 +760,11 @@ void GLBackend::recycle() const { Texture::KtxStorage::releaseOpenKtxFiles(); } -void GLBackend::setCameraCorrection(const Mat4& correction, bool reset) { +void GLBackend::setCameraCorrection(const Mat4& correction, const Mat4& prevCorrection, bool reset) { auto invCorrection = glm::inverse(correction); - _transform._correction.prevCorrection = (reset ? correction : _transform._correction.correction); - _transform._correction.prevCorrectionInverse = (reset ? invCorrection : _transform._correction.correctionInverse); + auto invPrevCorrection = glm::inverse(prevCorrection); + _transform._correction.prevCorrection = (reset ? correction : prevCorrection); + _transform._correction.prevCorrectionInverse = (reset ? invCorrection : invPrevCorrection); _transform._correction.correction = correction; _transform._correction.correctionInverse = invCorrection; _pipeline._cameraCorrectionBuffer._buffer->setSubData(0, _transform._correction); diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.h b/libraries/gpu-gl/src/gpu/gl/GLBackend.h index 505c26eb68..f8e084008b 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.h @@ -68,7 +68,7 @@ public: virtual ~GLBackend(); - void setCameraCorrection(const Mat4& correction, bool reset = false); + void setCameraCorrection(const Mat4& correction, const Mat4& prevCorrection, bool reset = false); void render(const Batch& batch) final override; // This call synchronize the Full Backend cache with the current GLState diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index b5b067dcac..e6fa983310 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -53,11 +53,12 @@ const std::string& Context::getBackendVersion() const { return _backend->getVersion(); } -void Context::beginFrame(const glm::mat4& renderPose) { +void Context::beginFrame(const glm::mat4& renderPose, const glm::mat4& prevRenderPose) { assert(!_frameActive); _frameActive = true; _currentFrame = std::make_shared(); _currentFrame->pose = renderPose; + _currentFrame->prevPose = prevRenderPose; 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 2082c175ad..2daf9da4ef 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -161,7 +161,7 @@ public: const std::string& getBackendVersion() const; - void beginFrame(const glm::mat4& renderPose = glm::mat4()); + void beginFrame(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 1ed77a26b7..e5365541b4 100644 --- a/libraries/gpu/src/gpu/Frame.h +++ b/libraries/gpu/src/gpu/Frame.h @@ -30,6 +30,8 @@ namespace gpu { uint32_t frameIndex{ 0 }; /// 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 + Mat4 prevPose; /// The collection of batches which make up the frame Batches batches; /// The main thread updates to buffers that are applicable for this frame.