From 1c3b4b0c9b791bbd153cb49126a73aff0fd75602 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 7 Dec 2017 17:54:58 -0800 Subject: [PATCH 1/5] Merging and adding Olivier's fixes to taa --- libraries/render-utils/src/taa.slh | 2 +- scripts/developer/utilities/render/antialiasing.js | 2 +- .../developer/utilities/render/antialiasing.qml | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 4e5f0e76ba..83f4d8a893 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -317,7 +317,7 @@ mat3 taa_evalNeighbourColorVariance(vec3 sourceColor, vec2 fragUV, vec2 fragVelo vec3 mu = sumSamples / vec3(9.0); - vec3 sigma = sqrt(sumSamples2 / vec3(9.0) - mu * mu); + vec3 sigma = sqrt(max(sumSamples2 / vec3(9.0) - mu * mu, vec3(0.0))); float gamma = params.covarianceGamma; vec3 cmin = mu - gamma * sigma; diff --git a/scripts/developer/utilities/render/antialiasing.js b/scripts/developer/utilities/render/antialiasing.js index b6c146caac..e915d75e93 100644 --- a/scripts/developer/utilities/render/antialiasing.js +++ b/scripts/developer/utilities/render/antialiasing.js @@ -13,7 +13,7 @@ (function() { var TABLET_BUTTON_NAME = "TAA"; - var QMLAPP_URL = Script.resolvePath("./Antialiasing.qml"); + var QMLAPP_URL = Script.resolvePath("./antialiasing.qml"); var onLuciScreen = false; diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml index 1c58cf8437..e88be0f9bf 100644 --- a/scripts/developer/utilities/render/antialiasing.qml +++ b/scripts/developer/utilities/render/antialiasing.qml @@ -12,8 +12,8 @@ import QtQuick 2.7 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.3 -import "../lib/styles-uit" -import "../lib/controls-uit" as HifiControls +import "qrc:///qml/styles-uit" +import "qrc:///qml/controls-uit" as HifiControls import "configSlider" @@ -129,7 +129,7 @@ Rectangle { } } } - HifiControls.ConfigSlider { + ConfigSlider { label: qsTr("Covariance gamma") integral: false config: Render.getConfig("RenderMainView.Antialiasing") @@ -145,7 +145,7 @@ Rectangle { onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["feedbackColor"] = checked } } - HifiControls.ConfigSlider { + ConfigSlider { label: qsTr("Source blend") integral: false config: Render.getConfig("RenderMainView.Antialiasing") @@ -172,7 +172,7 @@ Rectangle { onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["showCursorPixel"] = checked } } } - HifiControls.ConfigSlider { + ConfigSlider { label: qsTr("Debug Region <") integral: false config: Render.getConfig("RenderMainView.Antialiasing") @@ -186,7 +186,7 @@ Rectangle { checked: Render.getConfig("RenderMainView.Antialiasing")["showClosestFragment"] onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["showClosestFragment"] = checked } } - HifiControls.ConfigSlider { + ConfigSlider { label: qsTr("Debug Velocity Threshold [pix]") integral: false config: Render.getConfig("RenderMainView.Antialiasing") @@ -194,7 +194,7 @@ Rectangle { max: 50 min: 0.0 } - HifiControls.ConfigSlider { + ConfigSlider { label: qsTr("Debug Orb Zoom") integral: false config: Render.getConfig("RenderMainView.Antialiasing") From f4f0bb9c1c52382c6a8fd04d28030ca36bf1dd0a Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Mon, 18 Dec 2017 16:26:05 +0100 Subject: [PATCH 2/5] Fixed assert in Buffer update when switching to HMD simulator --- libraries/gpu/src/gpu/Buffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/gpu/src/gpu/Buffer.cpp b/libraries/gpu/src/gpu/Buffer.cpp index 7ed2411c71..02e6c552cf 100644 --- a/libraries/gpu/src/gpu/Buffer.cpp +++ b/libraries/gpu/src/gpu/Buffer.cpp @@ -98,8 +98,8 @@ Buffer::Update::Update(const Buffer& parent) : buffer(parent) { void Buffer::Update::apply() const { // Make sure we're loaded in order - ++buffer._applyUpdateCount; - assert(buffer._applyUpdateCount.load() == updateNumber); + auto applyUpdateCount = ++buffer._applyUpdateCount; + assert(applyUpdateCount == updateNumber); const auto pageSize = buffer._pages._pageSize; buffer._renderSysmem.resize(size); buffer._renderPages.accommodate(size); From 9bc02ec564666ba55ef2a79866fa969e6c58283d Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 10 Jan 2018 21:01:26 -0800 Subject: [PATCH 3/5] simple changes to try debugging the stereo rendering --- interface/src/Application_render.cpp | 2 +- .../src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/Application_render.cpp b/interface/src/Application_render.cpp index 1231e5834b..49748b7d0a 100644 --- a/interface/src/Application_render.cpp +++ b/interface/src/Application_render.cpp @@ -216,7 +216,7 @@ void Application::runRenderFrame(RenderArgs* renderArgs) { // Make sure the WorldBox is in the scene // For the record, this one RenderItem is the first one we created and added to the scene. - // We could meoee that code elsewhere but you know... + // We could move that code elsewhere but you know... if (!render::Item::isValidID(WorldBoxRenderData::_item)) { auto worldBoxRenderData = std::make_shared(); auto worldBoxRenderPayload = std::make_shared(worldBoxRenderData); diff --git a/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp index 6e397efbe5..9d73c21288 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/DebugHmdDisplayPlugin.cpp @@ -52,8 +52,8 @@ bool DebugHmdDisplayPlugin::internalActivate() { _eyeProjections[1][3] = vec4{ 0.000000000, 0.000000000, -0.0800003856, 0.000000000 }; _eyeInverseProjections[0] = glm::inverse(_eyeProjections[0]); _eyeInverseProjections[1] = glm::inverse(_eyeProjections[1]); - _eyeOffsets[0][3] = vec4{ -0.0327499993, 0.0, 0.0149999997, 1.0 }; - _eyeOffsets[1][3] = vec4{ 0.0327499993, 0.0, 0.0149999997, 1.0 }; + _eyeOffsets[0][3] = vec4{ -0.0327499993, 0.0, -0.0149999997, 1.0 }; + _eyeOffsets[1][3] = vec4{ 0.0327499993, 0.0, -0.0149999997, 1.0 }; _renderTargetSize = { 3024, 1680 }; _cullingProjection = _eyeProjections[0]; // This must come after the initialization, so that the values calculated @@ -63,10 +63,13 @@ bool DebugHmdDisplayPlugin::internalActivate() { } void DebugHmdDisplayPlugin::updatePresentPose() { + Parent::updatePresentPose(); +/* float yaw = sinf(secTimestampNow()) * 0.25f; float pitch = cosf(secTimestampNow()) * 0.25f; // Simulates head pose latency correction _currentPresentFrameInfo.presentPose = glm::mat4_cast(glm::angleAxis(yaw, Vectors::UP)) * glm::mat4_cast(glm::angleAxis(pitch, Vectors::RIGHT)); +*/ } From b7b478f640a04bcd6cc7bc4b862356946a6b829e Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Thu, 25 Jan 2018 17:33:18 +0100 Subject: [PATCH 4/5] Using proper inverse projection matrix in velocity buffer computation to reproject to world pos --- .../src/display-plugins/stereo/StereoDisplayPlugin.cpp | 1 + .../src/display-plugins/stereo/StereoDisplayPlugin.h | 2 +- libraries/plugins/src/plugins/DisplayPlugin.cpp | 7 ++++++- libraries/plugins/src/plugins/DisplayPlugin.h | 4 +--- libraries/render-utils/src/AntialiasingEffect.h | 6 +++--- libraries/render-utils/src/DeferredFrameTransform.cpp | 2 ++ libraries/render-utils/src/DeferredFrameTransform.h | 2 ++ libraries/render-utils/src/DeferredTransform.slh | 10 ++++++++++ .../render-utils/src/velocityBuffer_cameraMotion.slf | 6 +++--- 9 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp index ae8f9ec039..cfdfb1fc21 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.cpp @@ -101,3 +101,4 @@ void StereoDisplayPlugin::internalDeactivate() { float StereoDisplayPlugin::getRecommendedAspectRatio() const { return aspect(Parent::getRecommendedRenderSize()); } + diff --git a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h index 3b481dce97..c4205ea1db 100644 --- a/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/stereo/StereoDisplayPlugin.h @@ -26,7 +26,7 @@ public: // the IPD at the Application level, the way we now allow with HMDs. // If that becomes an issue then we'll need to break up the functionality similar // to the HMD plugins. - // virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override; + //virtual glm::mat4 getEyeToHeadTransform(Eye eye) const override; protected: virtual bool internalActivate() override; diff --git a/libraries/plugins/src/plugins/DisplayPlugin.cpp b/libraries/plugins/src/plugins/DisplayPlugin.cpp index 2a8a72f594..47503e8f85 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.cpp +++ b/libraries/plugins/src/plugins/DisplayPlugin.cpp @@ -42,4 +42,9 @@ std::function Displa hudOperator = _hudOperator; } return hudOperator; -} \ No newline at end of file +} + +glm::mat4 HmdDisplay::getEyeToHeadTransform(Eye eye) const { + static const glm::mat4 xform; + return xform; +} diff --git a/libraries/plugins/src/plugins/DisplayPlugin.h b/libraries/plugins/src/plugins/DisplayPlugin.h index 2c717f629c..e95084df52 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.h +++ b/libraries/plugins/src/plugins/DisplayPlugin.h @@ -93,9 +93,7 @@ class HmdDisplay : public StereoDisplay { public: // HMD specific methods // TODO move these into another class? - virtual glm::mat4 getEyeToHeadTransform(Eye eye) const { - static const glm::mat4 transform; return transform; - } + virtual glm::mat4 getEyeToHeadTransform(Eye eye) const; // returns a copy of the most recent head pose, computed via updateHeadPose virtual glm::mat4 getHeadPose() const { diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 1362a7c7b3..d201be3f73 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -58,7 +58,7 @@ class JitterSample { public: enum { - SEQUENCE_LENGTH = 16 + SEQUENCE_LENGTH = 128 }; using Config = JitterSampleConfig; @@ -106,12 +106,12 @@ class AntialiasingConfig : public render::Job::Config { public: AntialiasingConfig() : render::Job::Config(true) {} - float blend{ 0.1f }; + float blend{ 0.075f }; bool constrainColor{ true }; bool covarianceClipColor{ true }; - float covarianceGamma{ 1.0f }; + float covarianceGamma{ 0.9f }; bool clipExactColor{ false }; bool feedbackColor{ false }; diff --git a/libraries/render-utils/src/DeferredFrameTransform.cpp b/libraries/render-utils/src/DeferredFrameTransform.cpp index d6dc9e1372..34d3a56d23 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.cpp +++ b/libraries/render-utils/src/DeferredFrameTransform.cpp @@ -48,6 +48,7 @@ void DeferredFrameTransform::update(RenderArgs* args) { frameTransformBuffer.projection[0] = frameTransformBuffer.projectionMono; 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]); } else { mat4 projMats[2]; @@ -59,6 +60,7 @@ void DeferredFrameTransform::update(RenderArgs* args) { // 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.stereoInfo = glm::vec4(1.0f, (float)(args->_viewport.z >> 1), 0.0f, 1.0f); diff --git a/libraries/render-utils/src/DeferredFrameTransform.h b/libraries/render-utils/src/DeferredFrameTransform.h index a90effe053..0b5cb6a989 100644 --- a/libraries/render-utils/src/DeferredFrameTransform.h +++ b/libraries/render-utils/src/DeferredFrameTransform.h @@ -45,6 +45,8 @@ protected: glm::vec4 stereoInfo{ 0.0 }; // Mono proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space glm::mat4 projection[2]; + // Inverse proj matrix or Left and Right proj matrix going from Mono Eye space to side clip space + glm::mat4 invProjection[2]; // THe mono projection for sure glm::mat4 projectionMono; // Inv View matrix from eye space (mono) to world space diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index 25d352387f..eef32917d8 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -31,6 +31,7 @@ struct DeferredFrameTransform { vec4 _depthInfo; vec4 _stereoInfo; mat4 _projection[2]; + mat4 _invProjection[2]; mat4 _projectionMono; mat4 _viewInverse; mat4 _view; @@ -128,6 +129,15 @@ vec3 evalEyePositionFromZeye(int side, float Zeye, vec2 texcoord) { return vec3(Xe, Ye, Zeye); } +vec3 evalEyePositionFromZdb(int side, float Zdb, vec2 texcoord) { + // compute the view space position using the depth + vec3 clipPos; + clipPos.xy = texcoord.xy * 2.0 - 1.0; + clipPos.z = Zdb * 2.0 - 1.0; + vec4 eyePos = frameTransform._invProjection[side] * vec4(clipPos.xyz, 1.0); + return eyePos.xyz / eyePos.w; +} + ivec2 getPixelPosTexcoordPosAndSide(in vec2 glFragCoord, out ivec2 pixelPos, out vec2 texcoordPos, out ivec4 stereoSide) { ivec2 fragPos = ivec2(glFragCoord.xy); diff --git a/libraries/render-utils/src/velocityBuffer_cameraMotion.slf b/libraries/render-utils/src/velocityBuffer_cameraMotion.slf index 7488f42535..d908ea24da 100644 --- a/libraries/render-utils/src/velocityBuffer_cameraMotion.slf +++ b/libraries/render-utils/src/velocityBuffer_cameraMotion.slf @@ -26,14 +26,14 @@ void main(void) { ivec2 framePixelPos = getPixelPosTexcoordPosAndSide(gl_FragCoord.xy, pixelPos, texcoordPos, stereoSide); float Zdb = texelFetch(depthMap, ivec2(gl_FragCoord.xy), 0).x; - float Zeye = evalZeyeFromZdb(Zdb); -/* if (Zeye <= -getPosLinearDepthFar()) { +/* float Zeye = evalZeyeFromZdb(Zdb); + if (Zeye <= -getPosLinearDepthFar()) { outFragColor = vec4(0.5, 0.5, 0.0, 0.0); return; }*/ // The position of the pixel fragment in Eye space then in world space - vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos); + vec3 eyePos = evalEyePositionFromZdb(stereoSide.x, Zdb, texcoordPos); vec3 worldPos = (frameTransform._viewInverse * cameraCorrection._correction * vec4(eyePos, 1.0)).xyz; vec3 prevEyePos = (cameraCorrection._prevCorrectionInverse * frameTransform._prevView * vec4(worldPos, 1.0)).xyz; From 9cb5c95fe3058bb03c6b85220ab809c801ab78f1 Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 26 Jan 2018 15:05:46 +0100 Subject: [PATCH 5/5] Added velocity buffer to deferredLighting.qml --- libraries/render-utils/src/DeferredTransform.slh | 3 +-- scripts/developer/utilities/render/deferredLighting.qml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/DeferredTransform.slh b/libraries/render-utils/src/DeferredTransform.slh index eef32917d8..f1765978eb 100644 --- a/libraries/render-utils/src/DeferredTransform.slh +++ b/libraries/render-utils/src/DeferredTransform.slh @@ -132,8 +132,7 @@ vec3 evalEyePositionFromZeye(int side, float Zeye, vec2 texcoord) { vec3 evalEyePositionFromZdb(int side, float Zdb, vec2 texcoord) { // compute the view space position using the depth vec3 clipPos; - clipPos.xy = texcoord.xy * 2.0 - 1.0; - clipPos.z = Zdb * 2.0 - 1.0; + clipPos.xyz = vec3(texcoord.xy, Zdb) * 2.0 - 1.0; vec4 eyePos = frameTransform._invProjection[side] * vec4(clipPos.xyz, 1.0); return eyePos.xyz / eyePos.w; } diff --git a/scripts/developer/utilities/render/deferredLighting.qml b/scripts/developer/utilities/render/deferredLighting.qml index 1da7871172..189d23c44f 100644 --- a/scripts/developer/utilities/render/deferredLighting.qml +++ b/scripts/developer/utilities/render/deferredLighting.qml @@ -200,6 +200,7 @@ Rectangle { ListElement { text: "Debug Scattering"; color: "White" } ListElement { text: "Ambient Occlusion"; color: "White" } ListElement { text: "Ambient Occlusion Blurred"; color: "White" } + ListElement { text: "Velocity"; color: "White" } ListElement { text: "Custom"; color: "White" } } width: 200