diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 62deddacb0..b9efe2f3f6 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5342,7 +5342,6 @@ void Application::update(float deltaTime) { editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) { PerformanceTimer perfTimer("editRenderArgs"); - appRenderArgs._prevHeadPose = appRenderArgs._headPose; appRenderArgs._headPose = getHMDSensorPose(); auto myAvatar = getMyAvatar(); @@ -5447,7 +5446,6 @@ 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 77a0080db8..8eaab9f842 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -618,11 +618,9 @@ private: render::Args _renderArgs; glm::mat4 _eyeToWorld; glm::mat4 _view; - glm::mat4 _prevView; 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 0a26ddb9c0..d17c5dbef7 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -81,7 +81,6 @@ void Application::paintGL() { } HMDSensorPose = _appRenderArgs._headPose; - HMDSensorPrevPose = _appRenderArgs._prevHeadPose; eyeToWorld = _appRenderArgs._eyeToWorld; sensorToWorld = _appRenderArgs._sensorToWorld; isStereo = _appRenderArgs._isStereo; @@ -93,8 +92,7 @@ void Application::paintGL() { { PROFILE_RANGE(render, "/gpuContextReset"); - _gpuContext->beginFrame(_appRenderArgs._view, _appRenderArgs._prevView, - HMDSensorPose, HMDSensorPrevPose); + _gpuContext->beginFrame(_appRenderArgs._view, HMDSensorPose); // 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 172a153f65..4e67ee3db8 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -338,18 +338,10 @@ void HmdDisplayPlugin::updateFrameData() { updatePresentPose(); if (_currentFrame) { - auto invBatchPose = glm::inverse(_currentFrame->pose); - auto invPrevBatchPose = glm::inverse(_currentFrame->prevPose); - auto correction = invBatchPose * _currentPresentFrameInfo.presentPose; - // _currentFrame->prevView * glm::inverse(_prevRenderView) : this is to get the - // view matrix of the last rendered frame in the present thread - auto prevCorrection = _currentFrame->prevView * glm::inverse(_prevRenderView); - prevCorrection = prevCorrection * invPrevBatchPose * _previousPresentFrameInfo.presentPose; - - getGLBackend()->setCameraCorrection(correction, prevCorrection); - - _previousPresentFrameInfo = _currentPresentFrameInfo; - _prevRenderView = _currentFrame->view; + auto batchPose = _currentFrame->pose; + auto correction = glm::inverse(_currentPresentFrameInfo.presentPose) * batchPose ; + getGLBackend()->setCameraCorrection(correction, _prevRenderView); + _prevRenderView = correction * _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 7c63536c7b..098005aa0d 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -78,7 +78,6 @@ protected: QMap _frameInfos; FrameInfo _currentPresentFrameInfo; - FrameInfo _previousPresentFrameInfo; FrameInfo _currentRenderFrameInfo; mat4 _prevRenderView; RateCounter<> _stutterRate; diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp index 103a104aa8..b4e4656dc7 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackend.cpp @@ -760,11 +760,11 @@ void GLBackend::recycle() const { Texture::KtxStorage::releaseOpenKtxFiles(); } -void GLBackend::setCameraCorrection(const Mat4& correction, const Mat4& prevCorrection, bool reset) { +void GLBackend::setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset) { auto invCorrection = glm::inverse(correction); - auto invPrevCorrection = glm::inverse(prevCorrection); - _transform._correction.prevCorrection = (reset ? correction : prevCorrection); - _transform._correction.prevCorrectionInverse = (reset ? invCorrection : invPrevCorrection); + auto invPrevView = glm::inverse(prevRenderView); + _transform._correction.prevView = (reset ? Mat4() : prevRenderView); + _transform._correction.prevViewInverse = (reset ? Mat4() : invPrevView); _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 20259e7d4d..14a3d202f2 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, const Mat4& prevCorrection, bool reset = false); + void setCameraCorrection(const Mat4& correction, const Mat4& prevRenderView, bool reset = false); void render(const Batch& batch) final override; // This call synchronize the Full Backend cache with the current GLState @@ -313,8 +313,8 @@ protected: struct CameraCorrection { mat4 correction; mat4 correctionInverse; - mat4 prevCorrection; - mat4 prevCorrectionInverse; + mat4 prevView; + mat4 prevViewInverse; }; struct TransformStageState { diff --git a/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp index f286a5cca9..72aaa5aa66 100644 --- a/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl/src/gpu/gl/GLBackendTransform.cpp @@ -105,7 +105,7 @@ void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const Stereo if (_viewIsCamera && (_viewCorrectionEnabled && _correction.correction != glm::mat4())) { // FIXME should I switch to using the camera correction buffer in Transform.slf and leave this out? Transform result; - _view.mult(result, _view, _correction.correction); + _view.mult(result, _view, _correction.correctionInverse); if (_skybox) { result.setTranslation(vec3()); } diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index e4d8a88499..e1b68c88ca 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -53,15 +53,12 @@ const std::string& Context::getBackendVersion() const { return _backend->getVersion(); } -void Context::beginFrame(const glm::mat4& renderView, const glm::mat4& prevRenderView, - const glm::mat4& renderPose, const glm::mat4& prevRenderPose) { +void Context::beginFrame(const glm::mat4& renderView, const glm::mat4& renderPose) { 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 3667121c4e..2df7de2331 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -161,8 +161,7 @@ public: const std::string& getBackendVersion() const; - 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 beginFrame(const glm::mat4& renderView = glm::mat4(), const glm::mat4& renderPose = 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 ea8e70c9bc..441e3c5b5d 100644 --- a/libraries/gpu/src/gpu/Frame.h +++ b/libraries/gpu/src/gpu/Frame.h @@ -30,12 +30,8 @@ namespace gpu { 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 - 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. diff --git a/libraries/render-utils/src/DeferredFrameTransform.cpp b/libraries/render-utils/src/DeferredFrameTransform.cpp index 34d3a56d23..d1c51bf46f 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.cpp +++ b/libraries/render-utils/src/DeferredFrameTransform.cpp @@ -31,10 +31,6 @@ void DeferredFrameTransform::update(RenderArgs* args) { //_parametersBuffer.edit()._ditheringInfo.y += 0.25f; - // Move the current view transform to prev - frameTransformBuffer.prevInvView = frameTransformBuffer.invView; - frameTransformBuffer.prevView = frameTransformBuffer.view; - Transform cameraTransform; args->getViewFrustum().evalViewTransform(cameraTransform); cameraTransform.getMatrix(frameTransformBuffer.invView); diff --git a/libraries/render-utils/src/DeferredFrameTransform.h b/libraries/render-utils/src/DeferredFrameTransform.h index 0b5cb6a989..8c2f0a7321 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.h +++ b/libraries/render-utils/src/DeferredFrameTransform.h @@ -54,11 +54,6 @@ protected: // View matrix from world space to eye space (mono) glm::mat4 view; - // Previous Frame Inv View matrix from eye space (mono) to world space - glm::mat4 prevInvView; - // Previous Frame View matrix from world space to eye space (mono) - glm::mat4 prevView; - FrameTransform() {} }; UniformBufferView _frameTransformBuffer; diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index 3332eeb662..5fccbd6a99 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -17,8 +17,8 @@ struct CameraCorrection { mat4 _correction; mat4 _correctionInverse; - mat4 _prevCorrection; - mat4 _prevCorrectionInverse; + mat4 _prevView; + mat4 _prevViewInverse; }; uniform cameraCorrectionBuffer { @@ -35,8 +35,6 @@ struct DeferredFrameTransform { mat4 _projectionMono; mat4 _viewInverse; mat4 _view; - mat4 _prevViewInverse; - mat4 _prevView; }; uniform deferredFrameTransformBuffer { @@ -78,19 +76,19 @@ float getPosLinearDepthFar() { } mat4 getViewInverse() { - return frameTransform._viewInverse * cameraCorrection._correction; + return frameTransform._viewInverse * cameraCorrection._correctionInverse; } mat4 getView() { - return cameraCorrection._correctionInverse * frameTransform._view; + return cameraCorrection._correction * frameTransform._view; } mat4 getPreviousView() { - return cameraCorrection._prevCorrectionInverse * frameTransform._prevView; + return cameraCorrection._prevView; } mat4 getPreviousViewInverse() { - return frameTransform._prevViewInverse * cameraCorrection._prevCorrection; + return cameraCorrection._prevViewInverse; } DeferredFrameTransform getDeferredFrameTransform() {