From c6d598cc8838f79b10600a31d1a15cb12e559bc2 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 20 Apr 2018 10:52:50 +0200 Subject: [PATCH] Jitter is now set through a batch command --- .../gpu-gl-common/src/gpu/gl/GLBackend.cpp | 26 +++++++++--- .../gpu-gl-common/src/gpu/gl/GLBackend.h | 4 +- .../src/gpu/gl/GLBackendTransform.cpp | 13 ++++-- libraries/gpu/src/gpu/Batch.cpp | 6 +++ libraries/gpu/src/gpu/Batch.h | 6 ++- libraries/gpu/src/gpu/Context.cpp | 18 +++++--- libraries/gpu/src/gpu/Context.h | 9 ++-- .../gpu/src/gpu/TransformCamera_shared.slh | 26 ++++++------ .../render-utils/src/AntialiasingEffect.cpp | 37 +---------------- .../render-utils/src/AntialiasingEffect.h | 5 ++- .../src/DeferredFrameTransform.cpp | 41 +++++++++++-------- .../render-utils/src/DeferredFrameTransform.h | 9 ++-- .../render-utils/src/RenderCommonTask.cpp | 4 +- libraries/render-utils/src/RenderCommonTask.h | 2 +- .../render-utils/src/RenderDeferredTask.cpp | 17 ++++---- .../render-utils/src/RenderDeferredTask.h | 2 +- tests/gpu-test/src/TestWindow.cpp | 2 +- 17 files changed, 124 insertions(+), 103 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp index 9bb02d678d..501e59f38e 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp @@ -44,8 +44,9 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::gl::GLBackend::do_setModelTransform), (&::gpu::gl::GLBackend::do_setViewTransform), - (&::gpu::gl::GLBackend::do_setProjectionTransform), - (&::gpu::gl::GLBackend::do_setViewportTransform), + (&::gpu::gl::GLBackend::do_setProjectionTransform), + (&::gpu::gl::GLBackend::do_setProjectionJitter), + (&::gpu::gl::GLBackend::do_setViewportTransform), (&::gpu::gl::GLBackend::do_setDepthRangeTransform), (&::gpu::gl::GLBackend::do_setPipeline), @@ -166,7 +167,18 @@ void GLBackend::renderPassTransfer(const Batch& batch) { case Batch::COMMAND_drawIndexedInstanced: case Batch::COMMAND_multiDrawIndirect: case Batch::COMMAND_multiDrawIndexedIndirect: - _transform.preUpdate(_commandIndex, _stereo); + { + Vec2u outputSize{ 1,1 }; + + if (_output._framebuffer) { + outputSize.x = _output._framebuffer->getWidth(); + outputSize.y = _output._framebuffer->getHeight(); + } else if (glm::dot(_transform._projectionJitter, _transform._projectionJitter)>0.0f) { + qCWarning(gpugllogging) << "Jittering needs to have a frame buffer to be set"; + } + + _transform.preUpdate(_commandIndex, _stereo, outputSize); + } break; case Batch::COMMAND_disableContextStereo: @@ -179,8 +191,10 @@ void GLBackend::renderPassTransfer(const Batch& batch) { case Batch::COMMAND_setViewportTransform: case Batch::COMMAND_setViewTransform: - case Batch::COMMAND_setProjectionTransform: { - CommandCall call = _commandCalls[(*command)]; + case Batch::COMMAND_setProjectionTransform: + case Batch::COMMAND_setProjectionJitter: + { + CommandCall call = _commandCalls[(*command)]; (this->*(call))(batch, *offset); break; } @@ -254,6 +268,8 @@ void GLBackend::render(const Batch& batch) { if (!batch.isStereoEnabled()) { _stereo._enable = false; } + // Reset jitter + _transform._projectionJitter = Vec2(0.0f, 0.0f); { PROFILE_RANGE(render_gpu_gl_detail, "Transfer"); diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 6355137a19..8f815cf4b3 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -126,6 +126,7 @@ public: virtual void do_setModelTransform(const Batch& batch, size_t paramOffset) final; virtual void do_setViewTransform(const Batch& batch, size_t paramOffset) final; virtual void do_setProjectionTransform(const Batch& batch, size_t paramOffset) final; + virtual void do_setProjectionJitter(const Batch& batch, size_t paramOffset) final; virtual void do_setViewportTransform(const Batch& batch, size_t paramOffset) final; virtual void do_setDepthRangeTransform(const Batch& batch, size_t paramOffset) final; @@ -367,6 +368,7 @@ protected: Mat4 _projection; Vec4i _viewport { 0, 0, 1, 1 }; Vec2 _depthRange { 0.0f, 1.0f }; + Vec2 _projectionJitter{ 0.0f, 0.0f }; bool _invalidView { false }; bool _invalidProj { false }; bool _invalidViewport { false }; @@ -379,7 +381,7 @@ protected: mutable List::const_iterator _camerasItr; mutable size_t _currentCameraOffset{ INVALID_OFFSET }; - void preUpdate(size_t commandIndex, const StereoState& stereo); + void preUpdate(size_t commandIndex, const StereoState& stereo, Vec2u framebufferSize); void update(size_t commandIndex, const StereoState& stereo) const; void bindCurrentCamera(int stereoSide) const; } _transform; diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp index 72aaa5aa66..63ae483b44 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp @@ -28,6 +28,12 @@ void GLBackend::do_setProjectionTransform(const Batch& batch, size_t paramOffset _transform._invalidProj = true; } +void GLBackend::do_setProjectionJitter(const Batch& batch, size_t paramOffset) { + _transform._projectionJitter.x = batch._params[paramOffset]._float; + _transform._projectionJitter.y = batch._params[paramOffset+1]._float; + _transform._invalidProj = true; +} + void GLBackend::do_setViewportTransform(const Batch& batch, size_t paramOffset) { memcpy(&_transform._viewport, batch.readData(batch._params[paramOffset]._uint), sizeof(Vec4i)); @@ -90,7 +96,7 @@ void GLBackend::syncTransformStateCache() { _transform._enabledDrawcallInfoBuffer = false; } -void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const StereoState& stereo) { +void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const StereoState& stereo, Vec2u framebufferSize) { // Check all the dirty flags and update the state accordingly if (_invalidViewport) { _camera._viewport = glm::vec4(_viewport); @@ -117,18 +123,19 @@ void GLBackend::TransformStageState::preUpdate(size_t commandIndex, const Stereo if (_invalidView || _invalidProj || _invalidViewport) { size_t offset = _cameraUboSize * _cameras.size(); + Vec2 finalJitter = _projectionJitter / Vec2(framebufferSize); _cameraOffsets.push_back(TransformStageState::Pair(commandIndex, offset)); if (stereo.isStereo()) { #ifdef GPU_STEREO_CAMERA_BUFFER - _cameras.push_back(CameraBufferElement(_camera.getEyeCamera(0, stereo, _view), _camera.getEyeCamera(1, stereo, _view))); + _cameras.push_back(CameraBufferElement(_camera.getEyeCamera(0, stereo, _view, finalJitter), _camera.getEyeCamera(1, stereo, _view, finalJitter))); #else _cameras.push_back((_camera.getEyeCamera(0, stereo, _view))); _cameras.push_back((_camera.getEyeCamera(1, stereo, _view))); #endif } else { #ifdef GPU_STEREO_CAMERA_BUFFER - _cameras.push_back(CameraBufferElement(_camera.recomputeDerived(_view))); + _cameras.push_back(CameraBufferElement(_camera.getMonoCamera(_view, finalJitter))); #else _cameras.push_back((_camera.recomputeDerived(_view))); #endif diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index db4941c163..2b60070cb7 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -265,6 +265,12 @@ void Batch::setProjectionTransform(const Mat4& proj) { _params.emplace_back(cacheData(sizeof(Mat4), &proj)); } +void Batch::setProjectionJitter(float jx, float jy) { + ADD_COMMAND(setProjectionJitter); + _params.emplace_back(jx); + _params.emplace_back(jy); +} + void Batch::setViewportTransform(const Vec4i& viewport) { ADD_COMMAND(setViewportTransform); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 96b234295d..c08158b982 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -167,6 +167,7 @@ public: void resetViewTransform() { setViewTransform(Transform(), false); } void setViewTransform(const Transform& view, bool camera = true); void setProjectionTransform(const Mat4& proj); + void setProjectionJitter(float jx = 0.0f, float jy = 0.0f); // Viewport is xy = low left corner in framebuffer, zw = width height of the viewport, expressed in pixels void setViewportTransform(const Vec4i& viewport); void setDepthRangeTransform(float nearDepth, float farDepth); @@ -292,8 +293,9 @@ public: COMMAND_setModelTransform, COMMAND_setViewTransform, - COMMAND_setProjectionTransform, - COMMAND_setViewportTransform, + COMMAND_setProjectionTransform, + COMMAND_setProjectionJitter, + COMMAND_setViewportTransform, COMMAND_setDepthRangeTransform, COMMAND_setPipeline, diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp index 20ce113ce2..75c80a0164 100644 --- a/libraries/gpu/src/gpu/Context.cpp +++ b/libraries/gpu/src/gpu/Context.cpp @@ -174,11 +174,6 @@ void Context::getStereoViews(mat4* eyeViews) const { } } -void Context::setProjectionJitter(float jx, float jy) { - _projectionJitter.x = jx; - _projectionJitter.y = jy; -} - void Context::downloadFramebuffer(const FramebufferPointer& srcFramebuffer, const Vec4i& region, QImage& destImage) { _backend->downloadFramebuffer(srcFramebuffer, region, destImage); } @@ -227,7 +222,7 @@ const Backend::TransformCamera& Backend::TransformCamera::recomputeDerived(const return *this; } -Backend::TransformCamera Backend::TransformCamera::getEyeCamera(int eye, const StereoState& _stereo, const Transform& xformView) const { +Backend::TransformCamera Backend::TransformCamera::getEyeCamera(int eye, const StereoState& _stereo, const Transform& xformView, Vec2 normalizedJitter) const { TransformCamera result = *this; Transform offsetTransform = xformView; if (!_stereo._skybox) { @@ -236,6 +231,9 @@ Backend::TransformCamera Backend::TransformCamera::getEyeCamera(int eye, const S // FIXME: If "skybox" the ipd is set to 0 for now, let s try to propose a better solution for this in the future } result._projection = _stereo._eyeProjections[eye]; + normalizedJitter.x *= 2.0f; + result._projection[2][0] += normalizedJitter.x; + result._projection[2][1] += normalizedJitter.y; result.recomputeDerived(offsetTransform); result._stereoInfo = Vec4(1.0f, (float)eye, 0.0f, 0.0f); @@ -243,6 +241,14 @@ Backend::TransformCamera Backend::TransformCamera::getEyeCamera(int eye, const S return result; } +Backend::TransformCamera Backend::TransformCamera::getMonoCamera(const Transform& xformView, Vec2 normalizedJitter) const { + TransformCamera result = *this; + result._projection[2][0] += normalizedJitter.x; + result._projection[2][1] += normalizedJitter.y; + result.recomputeDerived(xformView); + return result; +} + // Counters for Buffer and Texture usage in GPU/Context ContextMetricSize Backend::freeGPUMemSize; diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h index 394ac463ee..eda8fee596 100644 --- a/libraries/gpu/src/gpu/Context.h +++ b/libraries/gpu/src/gpu/Context.h @@ -70,7 +70,10 @@ public: class TransformCamera : public _TransformCamera { public: const Backend::TransformCamera& recomputeDerived(const Transform& xformView) const; - TransformCamera getEyeCamera(int eye, const StereoState& stereo, const Transform& xformView) const; + // Jitter should be divided by framebuffer size + TransformCamera getMonoCamera(const Transform& xformView, Vec2 normalizedJitter) const; + // Jitter should be divided by framebuffer size + TransformCamera getEyeCamera(int eye, const StereoState& stereo, const Transform& xformView, Vec2 normalizedJitter) const; }; @@ -130,7 +133,6 @@ protected: friend class Context; mutable ContextStats _stats; StereoState _stereo; - }; class Context { @@ -202,8 +204,6 @@ public: void setStereoViews(const mat4 eyeViews[2]); void getStereoProjections(mat4* eyeProjections) const; void getStereoViews(mat4* eyeViews) const; - void setProjectionJitter(float jx, float jy); - gpu::Vec2 getProjectionJitter() const { return _projectionJitter; } // Downloading the Framebuffer is a synchronous action that is not efficient. // It s here for convenience to easily capture a snapshot @@ -250,7 +250,6 @@ protected: FramePointer _currentFrame; RangeTimerPointer _frameRangeTimer; StereoState _stereo; - gpu::Vec2 _projectionJitter{ 0.0f, 0.0f }; // Sampled at the end of every frame, the stats of all the counters mutable ContextStats _frameStats; diff --git a/libraries/gpu/src/gpu/TransformCamera_shared.slh b/libraries/gpu/src/gpu/TransformCamera_shared.slh index 6de17f1134..37521d8201 100644 --- a/libraries/gpu/src/gpu/TransformCamera_shared.slh +++ b/libraries/gpu/src/gpu/TransformCamera_shared.slh @@ -1,22 +1,22 @@ // glsl / C++ compatible source as interface for FadeEffect #ifdef __cplusplus -# define MAT4 Mat4 -# define VEC4 Vec4 -# define MUTABLE mutable +# define _MAT4 Mat4 +# define _VEC4 Vec4 +# define _MUTABLE mutable #else -# define MAT4 mat4 -# define VEC4 vec4 -# define MUTABLE +# define _MAT4 mat4 +# define _VEC4 vec4 +# define _MUTABLE #endif struct _TransformCamera { - MUTABLE MAT4 _view; - MUTABLE MAT4 _viewInverse; - MUTABLE MAT4 _projectionViewUntranslated; - MAT4 _projection; - MUTABLE MAT4 _projectionInverse; - VEC4 _viewport; // Public value is int but float in the shader to stay in floats for all the transform computations. - MUTABLE VEC4 _stereoInfo; + _MUTABLE _MAT4 _view; + _MUTABLE _MAT4 _viewInverse; + _MUTABLE _MAT4 _projectionViewUntranslated; + _MAT4 _projection; + _MUTABLE _MAT4 _projectionInverse; + _VEC4 _viewport; // Public value is int but float in the shader to stay in floats for all the transform computations. + _MUTABLE _VEC4 _stereoInfo; }; // <@if 1@> diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 18f236124c..78b33c39f7 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -499,7 +499,7 @@ void JitterSample::configure(const Config& config) { _scale = config.scale; } -void JitterSample::run(const render::RenderContextPointer& renderContext) { +void JitterSample::run(const render::RenderContextPointer& renderContext, Output& jitter) { auto& current = _sampleSequence.currentIndex; if (!_freeze) { if (current >= 0) { @@ -508,40 +508,7 @@ void JitterSample::run(const render::RenderContextPointer& renderContext) { current = -1; } } - auto args = renderContext->args; - auto viewFrustum = args->getViewFrustum(); - - auto jit = _sampleSequence.offsets[(current < 0 ? SEQUENCE_LENGTH : current)]; - auto width = (float)args->_viewport.z; - auto height = (float)args->_viewport.w; - - auto jx = jit.x / width; - auto jy = jit.y / height; - - if (!args->isStereo()) { - auto projMat = viewFrustum.getProjection(); - - projMat[2][0] += jx; - projMat[2][1] += jy; - - viewFrustum.setProjection(projMat); - viewFrustum.calculate(); - args->pushViewFrustum(viewFrustum); - } else { - mat4 projMats[2]; - args->_context->getStereoProjections(projMats); - - jx *= 2.0f; - - for (int i = 0; i < 2; i++) { - auto& projMat = projMats[i]; - projMat[2][0] += jx; - projMat[2][1] += jy; - } - - args->_context->setStereoProjections(projMats); - } - args->_context->setProjectionJitter(jx, jy); + jitter = _sampleSequence.offsets[(current < 0 ? SEQUENCE_LENGTH : current)]; } diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 0cdf870257..7d6f05da4e 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -62,10 +62,11 @@ public: }; using Config = JitterSampleConfig; - using JobModel = render::Job::Model; + using Output = glm::vec2; + using JobModel = render::Job::ModelO; void configure(const Config& config); - void run(const render::RenderContextPointer& renderContext); + void run(const render::RenderContextPointer& renderContext, Output& jitter); private: diff --git a/libraries/render-utils/src/DeferredFrameTransform.cpp b/libraries/render-utils/src/DeferredFrameTransform.cpp index 34d644e725..21d5b120d6 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.cpp +++ b/libraries/render-utils/src/DeferredFrameTransform.cpp @@ -18,7 +18,7 @@ DeferredFrameTransform::DeferredFrameTransform() { _frameTransformBuffer = gpu::BufferView(std::make_shared(sizeof(FrameTransform), (const gpu::Byte*) &frameTransform)); } -void DeferredFrameTransform::update(RenderArgs* args) { +void DeferredFrameTransform::update(RenderArgs* args, glm::vec2 jitter) { // Update the depth info with near and far (same for stereo) auto nearZ = args->getViewFrustum().getNearClip(); @@ -38,46 +38,53 @@ void DeferredFrameTransform::update(RenderArgs* args) { args->getViewFrustum().evalProjectionMatrix(frameTransformBuffer.projectionMono); + // There may be some sort of mismatch here if the viewport size isn't the same as the frame buffer size as + // jitter is normalized by frame buffer size in TransformCamera. But we should be safe. + jitter.x /= args->_viewport.z; + jitter.y /= args->_viewport.w; + // Running in stereo ? bool isStereo = args->isStereo(); if (!isStereo) { - frameTransformBuffer.projection[0] = frameTransformBuffer.projectionMono; + frameTransformBuffer.projectionUnjittered[0] = frameTransformBuffer.projectionMono; + frameTransformBuffer.invProjectionUnjittered[0] = glm::inverse(frameTransformBuffer.projectionUnjittered[0]); + frameTransformBuffer.stereoInfo = glm::vec4(0.0f, (float)args->_viewport.z, 0.0f, 0.0f); frameTransformBuffer.invpixelInfo = glm::vec4(1.0f / args->_viewport.z, 1.0f / args->_viewport.w, 0.0f, 0.0f); - frameTransformBuffer.invProjection[0] = glm::inverse(frameTransformBuffer.projection[0]); - frameTransformBuffer.projectionUnjittered[0] = frameTransformBuffer.projection[0]; - frameTransformBuffer.projectionUnjittered[0][2][0] -= args->_context->getProjectionJitter().x; - frameTransformBuffer.projectionUnjittered[0][2][1] -= args->_context->getProjectionJitter().y; - frameTransformBuffer.invProjectionUnjittered[0] = glm::inverse(frameTransformBuffer.projectionUnjittered[0]); - } else { + frameTransformBuffer.projection[0] = frameTransformBuffer.projectionUnjittered[0]; + frameTransformBuffer.projection[0][2][0] += jitter.x; + frameTransformBuffer.projection[0][2][1] += jitter.y; + frameTransformBuffer.invProjection[0] = glm::inverse(frameTransformBuffer.projection[0]); + } else { mat4 projMats[2]; mat4 eyeViews[2]; args->_context->getStereoProjections(projMats); args->_context->getStereoViews(eyeViews); + jitter.x *= 2.0f; + for (int i = 0; i < 2; i++) { // Compose the mono Eye space to Stereo clip space Projection Matrix auto sideViewMat = projMats[i] * eyeViews[i]; - frameTransformBuffer.projection[i] = sideViewMat; - frameTransformBuffer.invProjection[i] = glm::inverse(sideViewMat); + frameTransformBuffer.projectionUnjittered[i] = sideViewMat; + frameTransformBuffer.invProjectionUnjittered[i] = glm::inverse(sideViewMat); - frameTransformBuffer.projectionUnjittered[i] = frameTransformBuffer.projection[i]; - frameTransformBuffer.projectionUnjittered[i][2][0] -= args->_context->getProjectionJitter().x; - frameTransformBuffer.projectionUnjittered[i][2][1] -= args->_context->getProjectionJitter().y; - frameTransformBuffer.invProjectionUnjittered[i] = glm::inverse(frameTransformBuffer.projectionUnjittered[i]); + frameTransformBuffer.projection[i] = frameTransformBuffer.projectionUnjittered[i]; + frameTransformBuffer.projection[i][2][0] += jitter.x; + frameTransformBuffer.projection[i][2][1] += jitter.y; + frameTransformBuffer.invProjection[i] = glm::inverse(frameTransformBuffer.projection[i]); } frameTransformBuffer.stereoInfo = glm::vec4(1.0f, (float)(args->_viewport.z >> 1), 0.0f, 1.0f); frameTransformBuffer.invpixelInfo = glm::vec4(1.0f / (float)(args->_viewport.z >> 1), 1.0f / args->_viewport.w, 0.0f, 0.0f); - } } -void GenerateDeferredFrameTransform::run(const render::RenderContextPointer& renderContext, DeferredFrameTransformPointer& frameTransform) { +void GenerateDeferredFrameTransform::run(const render::RenderContextPointer& renderContext, const Input& jitter, Output& frameTransform) { if (!frameTransform) { frameTransform = std::make_shared(); } - frameTransform->update(renderContext->args); + frameTransform->update(renderContext->args, jitter); } diff --git a/libraries/render-utils/src/DeferredFrameTransform.h b/libraries/render-utils/src/DeferredFrameTransform.h index 64237cb763..f8181b6b8a 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.h +++ b/libraries/render-utils/src/DeferredFrameTransform.h @@ -25,7 +25,7 @@ public: DeferredFrameTransform(); - void update(RenderArgs* args); + void update(RenderArgs* args, glm::vec2 jitter); UniformBufferView getFrameTransformBuffer() const { return _frameTransformBuffer; } @@ -72,11 +72,14 @@ using DeferredFrameTransformPointer = std::shared_ptr; class GenerateDeferredFrameTransform { public: - using JobModel = render::Job::ModelO; + + using Input = glm::vec2; + using Output = DeferredFrameTransformPointer; + using JobModel = render::Job::ModelIO; GenerateDeferredFrameTransform() {} - void run(const render::RenderContextPointer& renderContext, DeferredFrameTransformPointer& frameTransform); + void run(const render::RenderContextPointer& renderContext, const Input& jitter, Output& frameTransform); private: }; diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index d54cefa5c7..293393550b 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -46,6 +46,7 @@ void DrawOverlay3D::run(const RenderContextPointer& renderContext, const Inputs& const auto& inItems = inputs.get0(); const auto& lightingModel = inputs.get1(); + const auto jitter = inputs.get2(); config->setNumDrawn((int)inItems.size()); emit config->numDrawnChanged(); @@ -75,7 +76,8 @@ void DrawOverlay3D::run(const RenderContextPointer& renderContext, const Inputs& args->getViewFrustum().evalViewTransform(viewMat); batch.setProjectionTransform(projMat); - batch.setViewTransform(viewMat); + batch.setProjectionJitter(jitter.x, jitter.y); + batch.setViewTransform(viewMat); // Setup lighting model for all items; batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); diff --git a/libraries/render-utils/src/RenderCommonTask.h b/libraries/render-utils/src/RenderCommonTask.h index 767b6893cd..79599d3ab7 100644 --- a/libraries/render-utils/src/RenderCommonTask.h +++ b/libraries/render-utils/src/RenderCommonTask.h @@ -60,7 +60,7 @@ protected: class DrawOverlay3D { public: - using Inputs = render::VaryingSet2 ; + using Inputs = render::VaryingSet3; using Config = DrawOverlay3DConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index e2089cc038..bea298122e 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -95,10 +95,10 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren fadeEffect->build(task, opaques); - task.addJob("JitterCam"); + const auto jitter = task.addJob("JitterCam"); // Prepare deferred, generate the shared Deferred Frame Transform - const auto deferredFrameTransform = task.addJob("DeferredFrameTransform"); + const auto deferredFrameTransform = task.addJob("DeferredFrameTransform", jitter); const auto lightingModel = task.addJob("LightingModel"); @@ -116,7 +116,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren task.addJob("PrepareStencil", primaryFramebuffer); // Render opaque objects in DeferredBuffer - const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel).asVarying(); + const auto opaqueInputs = DrawStateSortDeferred::Inputs(opaques, lightingModel, jitter).asVarying(); task.addJob("DrawOpaqueDeferred", opaqueInputs, shapePlumber); task.addJob("OpaqueRangeTimer", opaqueRangeTimer); @@ -205,8 +205,8 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto overlaysInFrontOpaque = filteredOverlaysOpaque.getN(0); const auto overlaysInFrontTransparent = filteredOverlaysTransparent.getN(0); - const auto overlayInFrontOpaquesInputs = DrawOverlay3D::Inputs(overlaysInFrontOpaque, lightingModel).asVarying(); - const auto overlayInFrontTransparentsInputs = DrawOverlay3D::Inputs(overlaysInFrontTransparent, lightingModel).asVarying(); + const auto overlayInFrontOpaquesInputs = DrawOverlay3D::Inputs(overlaysInFrontOpaque, lightingModel, jitter).asVarying(); + const auto overlayInFrontTransparentsInputs = DrawOverlay3D::Inputs(overlaysInFrontTransparent, lightingModel, jitter).asVarying(); task.addJob("DrawOverlayInFrontOpaque", overlayInFrontOpaquesInputs, true); task.addJob("DrawOverlayInFrontTransparent", overlayInFrontTransparentsInputs, false); @@ -288,9 +288,10 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren const auto overlaysHUDOpaque = filteredOverlaysOpaque.getN(1); const auto overlaysHUDTransparent = filteredOverlaysTransparent.getN(1); + const auto nullJitter = Varying(glm::vec2(0.0f, 0.0f)); - const auto overlayHUDOpaquesInputs = DrawOverlay3D::Inputs(overlaysHUDOpaque, lightingModel).asVarying(); - const auto overlayHUDTransparentsInputs = DrawOverlay3D::Inputs(overlaysHUDTransparent, lightingModel).asVarying(); + const auto overlayHUDOpaquesInputs = DrawOverlay3D::Inputs(overlaysHUDOpaque, lightingModel, nullJitter).asVarying(); + const auto overlayHUDTransparentsInputs = DrawOverlay3D::Inputs(overlaysHUDTransparent, lightingModel, nullJitter).asVarying(); task.addJob("DrawOverlayHUDOpaque", overlayHUDOpaquesInputs, true); task.addJob("DrawOverlayHUDTransparent", overlayHUDTransparentsInputs, false); @@ -382,6 +383,7 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const const auto& inItems = inputs.get0(); const auto& lightingModel = inputs.get1(); + const auto jitter = inputs.get2(); RenderArgs* args = renderContext->args; @@ -398,6 +400,7 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const args->getViewFrustum().evalViewTransform(viewMat); batch.setProjectionTransform(projMat); + batch.setProjectionJitter(jitter.x, jitter.y); batch.setViewTransform(viewMat); // Setup lighting model for all items; diff --git a/libraries/render-utils/src/RenderDeferredTask.h b/libraries/render-utils/src/RenderDeferredTask.h index 1b57c88768..b923ec0878 100644 --- a/libraries/render-utils/src/RenderDeferredTask.h +++ b/libraries/render-utils/src/RenderDeferredTask.h @@ -81,7 +81,7 @@ protected: class DrawStateSortDeferred { public: - using Inputs = render::VaryingSet2; + using Inputs = render::VaryingSet3; using Config = DrawStateSortConfig; using JobModel = render::Job::ModelI; diff --git a/tests/gpu-test/src/TestWindow.cpp b/tests/gpu-test/src/TestWindow.cpp index 1fa4862e53..f667f20f2b 100644 --- a/tests/gpu-test/src/TestWindow.cpp +++ b/tests/gpu-test/src/TestWindow.cpp @@ -98,7 +98,7 @@ void TestWindow::beginFrame() { _preparePrimaryFramebuffer.run(_renderContext, primaryFramebuffer); DeferredFrameTransformPointer frameTransform; - _generateDeferredFrameTransform.run(_renderContext, frameTransform); + _generateDeferredFrameTransform.run(_renderContext, glm::vec2(0.0f, 0.0f), frameTransform); LightingModelPointer lightingModel; _generateLightingModel.run(_renderContext, lightingModel);