Trying to keep track of a better previous correction

This commit is contained in:
Olivier Prat 2018-02-20 14:48:21 +01:00
parent 247a1f5769
commit 4edfe6c9ab
12 changed files with 25 additions and 14 deletions

View file

@ -5275,7 +5275,8 @@ void Application::update(float deltaTime) {
editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) { editRenderArgs([this, deltaTime](AppRenderArgs& appRenderArgs) {
PerformanceTimer perfTimer("editRenderArgs"); PerformanceTimer perfTimer("editRenderArgs");
appRenderArgs._headPose= getHMDSensorPose(); appRenderArgs._prevHeadPose = appRenderArgs._headPose;
appRenderArgs._headPose = getHMDSensorPose();
auto myAvatar = getMyAvatar(); auto myAvatar = getMyAvatar();

View file

@ -620,6 +620,7 @@ private:
glm::mat4 _eyeOffsets[2]; glm::mat4 _eyeOffsets[2];
glm::mat4 _eyeProjections[2]; glm::mat4 _eyeProjections[2];
glm::mat4 _headPose; glm::mat4 _headPose;
glm::mat4 _prevHeadPose;
glm::mat4 _sensorToWorld; glm::mat4 _sensorToWorld;
float _sensorToWorldScale { 1.0f }; float _sensorToWorldScale { 1.0f };
bool _isStereo{ false }; bool _isStereo{ false };

View file

@ -62,6 +62,7 @@ void Application::paintGL() {
RenderArgs renderArgs; RenderArgs renderArgs;
glm::mat4 HMDSensorPose; glm::mat4 HMDSensorPose;
glm::mat4 HMDSensorPrevPose;
glm::mat4 eyeToWorld; glm::mat4 eyeToWorld;
glm::mat4 sensorToWorld; glm::mat4 sensorToWorld;
@ -79,6 +80,7 @@ void Application::paintGL() {
} }
HMDSensorPose = _appRenderArgs._headPose; HMDSensorPose = _appRenderArgs._headPose;
HMDSensorPrevPose = _appRenderArgs._prevHeadPose;
eyeToWorld = _appRenderArgs._eyeToWorld; eyeToWorld = _appRenderArgs._eyeToWorld;
sensorToWorld = _appRenderArgs._sensorToWorld; sensorToWorld = _appRenderArgs._sensorToWorld;
isStereo = _appRenderArgs._isStereo; isStereo = _appRenderArgs._isStereo;
@ -90,7 +92,7 @@ void Application::paintGL() {
{ {
PROFILE_RANGE(render, "/gpuContextReset"); PROFILE_RANGE(render, "/gpuContextReset");
_gpuContext->beginFrame(HMDSensorPose); _gpuContext->beginFrame(HMDSensorPose, HMDSensorPrevPose);
// Reset the gpu::Context Stages // Reset the gpu::Context Stages
// Back to the default framebuffer; // Back to the default framebuffer;
gpu::doInBatch("Application_render::gpuContextReset", _gpuContext, [&](gpu::Batch& batch) { gpu::doInBatch("Application_render::gpuContextReset", _gpuContext, [&](gpu::Batch& batch) {

View file

@ -361,7 +361,7 @@ void OpenGLDisplayPlugin::customizeContext() {
auto presentThread = DependencyManager::get<PresentThread>(); auto presentThread = DependencyManager::get<PresentThread>();
Q_ASSERT(thread() == presentThread->thread()); Q_ASSERT(thread() == presentThread->thread());
getGLBackend()->setCameraCorrection(mat4(), true); getGLBackend()->setCameraCorrection(mat4(), mat4(), true);
for (auto& cursorValue : _cursorsData) { for (auto& cursorValue : _cursorsData) {
auto& cursorData = cursorValue.second; auto& cursorData = cursorValue.second;

View file

@ -85,6 +85,6 @@ void DebugHmdDisplayPlugin::updatePresentPose() {
// Simulates head pose latency correction // Simulates head pose latency correction
_currentPresentFrameInfo.presentPose = _currentPresentFrameInfo.presentPose =
glm::mat4_cast(glm::angleAxis(yaw, Vectors::UP)) * glm::mat4_cast(glm::angleAxis(yaw, Vectors::UP)) *
glm::mat4_cast(glm::angleAxis(pitch, Vectors::RIGHT)); glm::mat4_cast(glm::angleAxis(pitch, Vectors::RIGHT)) ;
} }
} }

View file

@ -330,6 +330,7 @@ void HmdDisplayPlugin::updateFrameData() {
} }
} }
if (newFrameIndex != INVALID_FRAME) { if (newFrameIndex != INVALID_FRAME) {
_previousPresentFrameInfo = _currentPresentFrameInfo;
_currentPresentFrameInfo = _frameInfos[newFrameIndex]; _currentPresentFrameInfo = _frameInfos[newFrameIndex];
} }
}); });
@ -338,10 +339,11 @@ void HmdDisplayPlugin::updateFrameData() {
updatePresentPose(); updatePresentPose();
if (_currentFrame) { if (_currentFrame) {
auto batchPose = _currentFrame->pose; auto invBatchPose = glm::inverse(_currentFrame->pose);
auto currentPose = _currentPresentFrameInfo.presentPose; auto invPrevBatchPose = glm::inverse(_currentFrame->prevPose);
auto correction = glm::inverse(batchPose) * currentPose; auto correction = invBatchPose * _currentPresentFrameInfo.presentPose;
getGLBackend()->setCameraCorrection(correction); auto prevCorrection = invPrevBatchPose * _previousPresentFrameInfo.presentPose;
getGLBackend()->setCameraCorrection(correction, prevCorrection);
} }
} }

View file

@ -78,6 +78,7 @@ protected:
QMap<uint32_t, FrameInfo> _frameInfos; QMap<uint32_t, FrameInfo> _frameInfos;
FrameInfo _currentPresentFrameInfo; FrameInfo _currentPresentFrameInfo;
FrameInfo _previousPresentFrameInfo;
FrameInfo _currentRenderFrameInfo; FrameInfo _currentRenderFrameInfo;
RateCounter<> _stutterRate; RateCounter<> _stutterRate;

View file

@ -760,10 +760,11 @@ void GLBackend::recycle() const {
Texture::KtxStorage::releaseOpenKtxFiles(); 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); auto invCorrection = glm::inverse(correction);
_transform._correction.prevCorrection = (reset ? correction : _transform._correction.correction); auto invPrevCorrection = glm::inverse(prevCorrection);
_transform._correction.prevCorrectionInverse = (reset ? invCorrection : _transform._correction.correctionInverse); _transform._correction.prevCorrection = (reset ? correction : prevCorrection);
_transform._correction.prevCorrectionInverse = (reset ? invCorrection : invPrevCorrection);
_transform._correction.correction = correction; _transform._correction.correction = correction;
_transform._correction.correctionInverse = invCorrection; _transform._correction.correctionInverse = invCorrection;
_pipeline._cameraCorrectionBuffer._buffer->setSubData(0, _transform._correction); _pipeline._cameraCorrectionBuffer._buffer->setSubData(0, _transform._correction);

View file

@ -68,7 +68,7 @@ public:
virtual ~GLBackend(); 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; void render(const Batch& batch) final override;
// This call synchronize the Full Backend cache with the current GLState // This call synchronize the Full Backend cache with the current GLState

View file

@ -53,11 +53,12 @@ const std::string& Context::getBackendVersion() const {
return _backend->getVersion(); return _backend->getVersion();
} }
void Context::beginFrame(const glm::mat4& renderPose) { void Context::beginFrame(const glm::mat4& renderPose, const glm::mat4& prevRenderPose) {
assert(!_frameActive); assert(!_frameActive);
_frameActive = true; _frameActive = true;
_currentFrame = std::make_shared<Frame>(); _currentFrame = std::make_shared<Frame>();
_currentFrame->pose = renderPose; _currentFrame->pose = renderPose;
_currentFrame->prevPose = prevRenderPose;
if (!_frameRangeTimer) { if (!_frameRangeTimer) {
_frameRangeTimer = std::make_shared<RangeTimer>("gpu::Context::Frame"); _frameRangeTimer = std::make_shared<RangeTimer>("gpu::Context::Frame");

View file

@ -161,7 +161,7 @@ public:
const std::string& getBackendVersion() const; 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); void appendFrameBatch(Batch& batch);
FramePointer endFrame(); FramePointer endFrame();

View file

@ -30,6 +30,8 @@ namespace gpu {
uint32_t frameIndex{ 0 }; uint32_t frameIndex{ 0 };
/// The sensor pose used for rendering the frame, only applicable for HMDs /// The sensor pose used for rendering the frame, only applicable for HMDs
Mat4 pose; 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 /// The collection of batches which make up the frame
Batches batches; Batches batches;
/// The main thread updates to buffers that are applicable for this frame. /// The main thread updates to buffers that are applicable for this frame.