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) {
PerformanceTimer perfTimer("editRenderArgs");
appRenderArgs._headPose= getHMDSensorPose();
appRenderArgs._prevHeadPose = appRenderArgs._headPose;
appRenderArgs._headPose = getHMDSensorPose();
auto myAvatar = getMyAvatar();

View file

@ -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 };

View file

@ -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) {

View file

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

View file

@ -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)) ;
}
}

View file

@ -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);
}
}

View file

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

View file

@ -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);

View file

@ -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

View file

@ -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<Frame>();
_currentFrame->pose = renderPose;
_currentFrame->prevPose = prevRenderPose;
if (!_frameRangeTimer) {
_frameRangeTimer = std::make_shared<RangeTimer>("gpu::Context::Frame");

View file

@ -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();

View file

@ -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.