From 3e0c50e077c6c1c87a878cf4d5cb1afd0e3564cc Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Mon, 4 Dec 2023 14:44:28 -0800 Subject: [PATCH] wild guess to handle view correction, hide portalExitID in create when mirrorMode != portal --- libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp | 5 +++++ libraries/gpu-gl-common/src/gpu/gl/GLBackend.h | 2 ++ .../gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp | 6 +++++- libraries/gpu/src/gpu/Batch.cpp | 6 ++++++ libraries/gpu/src/gpu/Batch.h | 2 ++ libraries/gpu/src/gpu/FrameIOKeys.h | 1 + libraries/render-utils/src/RenderCommonTask.cpp | 10 ++++++++++ .../entityProperties/html/js/entityProperties.js | 1 + 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp index af39458f17..421fef4334 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.cpp @@ -81,6 +81,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::gl::GLBackend::do_disableContextViewCorrection), (&::gpu::gl::GLBackend::do_restoreContextViewCorrection), + (&::gpu::gl::GLBackend::do_setContextMirrorViewCorrection), (&::gpu::gl::GLBackend::do_disableContextStereo), (&::gpu::gl::GLBackend::do_restoreContextStereo), @@ -619,6 +620,10 @@ void GLBackend::do_restoreContextViewCorrection(const Batch& batch, size_t param _transform._viewCorrectionEnabled = true; } +void GLBackend::do_setContextMirrorViewCorrection(const Batch& batch, size_t paramOffset) { + _transform._mirrorViewCorrection = batch._params[paramOffset + 1]._uint != 0; +} + void GLBackend::do_disableContextStereo(const Batch& batch, size_t paramOffset) { } diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index 2947649ce7..6e8af35037 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -211,6 +211,7 @@ public: virtual void do_disableContextViewCorrection(const Batch& batch, size_t paramOffset) final; virtual void do_restoreContextViewCorrection(const Batch& batch, size_t paramOffset) final; + virtual void do_setContextMirrorViewCorrection(const Batch& batch, size_t paramOffset) final; virtual void do_disableContextStereo(const Batch& batch, size_t paramOffset) final; virtual void do_restoreContextStereo(const Batch& batch, size_t paramOffset) final; @@ -433,6 +434,7 @@ protected: Transform _view; CameraCorrection _correction; bool _viewCorrectionEnabled{ true }; + bool _mirrorViewCorrection{ false }; Mat4 _projection; Vec4i _viewport{ 0, 0, 1, 1 }; diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp index 67ab502b6b..03c2b17a0e 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendTransform.cpp @@ -111,7 +111,11 @@ 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.correctionInverse); + glm::mat4 correction = _correction.correctionInverse; + if (_mirrorViewCorrection) { + correction = glm::scale(glm::mat4(), glm::vec3(-1.0f, 1.0f, 1.0f)) * correction; + } + _view.mult(result, _view, correction); if (_skybox) { result.setTranslation(vec3()); } diff --git a/libraries/gpu/src/gpu/Batch.cpp b/libraries/gpu/src/gpu/Batch.cpp index e6217cc600..a41f586d74 100644 --- a/libraries/gpu/src/gpu/Batch.cpp +++ b/libraries/gpu/src/gpu/Batch.cpp @@ -464,6 +464,12 @@ void Batch::restoreContextViewCorrection() { ADD_COMMAND(restoreContextViewCorrection); } +void Batch::setContextMirrorViewCorrection(bool shouldMirror) { + ADD_COMMAND(setContextMirrorViewCorrection); + uint mirrorFlag = shouldMirror ? 1 : 0; + _params.emplace_back(mirrorFlag); +} + void Batch::disableContextStereo() { ADD_COMMAND(disableContextStereo); } diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 0a438ea148..f89dd3ea90 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -239,6 +239,7 @@ public: void disableContextViewCorrection(); void restoreContextViewCorrection(); + void setContextMirrorViewCorrection(bool shouldMirror); void disableContextStereo(); void restoreContextStereo(); @@ -340,6 +341,7 @@ public: COMMAND_disableContextViewCorrection, COMMAND_restoreContextViewCorrection, + COMMAND_setContextMirrorViewCorrection, COMMAND_disableContextStereo, COMMAND_restoreContextStereo, diff --git a/libraries/gpu/src/gpu/FrameIOKeys.h b/libraries/gpu/src/gpu/FrameIOKeys.h index 1a98d0decd..2d88158afb 100644 --- a/libraries/gpu/src/gpu/FrameIOKeys.h +++ b/libraries/gpu/src/gpu/FrameIOKeys.h @@ -181,6 +181,7 @@ constexpr const char* COMMAND_NAMES[] = { "disableContextViewCorrection", "restoreContextViewCorrection", + "setContextMirrorViewCorrection", "disableContextStereo", "restoreContextStereo", diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index 7647a1b8d2..263af717f5 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -307,6 +307,11 @@ public: args->_ignoreItem = portalExitID != Item::INVALID_ITEM_ID ? portalExitID : mirror.id; args->_mirrorDepth = _depth; + gpu::doInBatch("SetupMirrorTask::run", args->_context, [&](gpu::Batch& batch) { + bool shouldMirror = _depth % 2 == (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE); + batch.setContextMirrorViewCorrection(shouldMirror); + }); + // Without calculating the bound planes, the mirror will use the same culling frustum as the main camera, // which is not what we want here. srcViewFrustum.calculate(); @@ -360,6 +365,11 @@ public: gpu::doInBatch("DrawMirrorTask::run", args->_context, [&](gpu::Batch& batch) { args->_batch = &batch; + if (cachedArgs) { + bool shouldMirror = cachedArgs->_mirrorDepth % 2 == (args->_renderMode != RenderArgs::MIRROR_RENDER_MODE); + batch.setContextMirrorViewCorrection(shouldMirror); + } + batch.setFramebuffer(framebuffer); batch.setViewportTransform(args->_viewport); batch.setStateScissorRect(args->_viewport); diff --git a/scripts/system/create/entityProperties/html/js/entityProperties.js b/scripts/system/create/entityProperties/html/js/entityProperties.js index ff28925b96..77e43fe829 100644 --- a/scripts/system/create/entityProperties/html/js/entityProperties.js +++ b/scripts/system/create/entityProperties/html/js/entityProperties.js @@ -146,6 +146,7 @@ const GROUPS = [ label: "Portal Exit", type: "string", propertyID: "portalExitID", + showPropertyRule: { "mirrorMode": "portal" }, } ] },