Simplified camera view history and TAA is now working in all circumstances.

This commit is contained in:
Olivier Prat 2018-02-23 10:19:05 +01:00
parent 7432c8361e
commit 4636f43728
14 changed files with 21 additions and 55 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -31,10 +31,6 @@ void DeferredFrameTransform::update(RenderArgs* args) {
//_parametersBuffer.edit<Parameters>()._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);

View file

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

View file

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