From 66d35118cb09b9531400c979b0763a92da9fac5a Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 28 Aug 2017 18:14:46 -0700 Subject: [PATCH] Refining the debugging to better understand the issues --- .../render-utils/src/AntialiasingEffect.cpp | 35 ++++++++++++++++ .../render-utils/src/AntialiasingEffect.h | 20 +++++++++ libraries/render-utils/src/taa.slf | 6 ++- libraries/render-utils/src/taa.slh | 16 +++++--- libraries/render-utils/src/taa_blend.slf | 19 +++++---- .../lib/styles-uit/HifiConstants.qmlc | Bin 51304 -> 51304 bytes .../utilities/render/antialiasing.qml | 38 ++++++++++++++---- 7 files changed, 111 insertions(+), 23 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index af896024d6..b41aec4030 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -287,6 +287,7 @@ void Antialiasing::configure(const Config& config) { _params.edit().velocityScale = config.velocityScale; _params.edit().setUnjitter(config.unjitter); + _params.edit().setConstrainColor(config.constrainColor); _params.edit().debugShowVelocityThreshold = config.debugShowVelocityThreshold; @@ -380,6 +381,34 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const }); } + +void JitterSampleConfig::setIndex(int current) { + _index = (current) % JitterSample::SampleSequence::SEQUENCE_LENGTH; + emit dirty(); +} + +int JitterSampleConfig::pause() { + freeze = true; + emit dirty(); + return _index; +} + +int JitterSampleConfig::prev() { + setIndex(_index - 1); + return _index; +} + +int JitterSampleConfig::next() { + setIndex(_index + 1); + return _index; +} + +int JitterSampleConfig::play() { + freeze = false; + emit dirty(); + return _index; +} + JitterSample::SampleSequence::SampleSequence(){ // Halton sequence (2,3) offsets[0] = { 1.0f / 2.0f, 1.0f / 3.0f }; @@ -398,6 +427,12 @@ JitterSample::SampleSequence::SampleSequence(){ void JitterSample::configure(const Config& config) { _freeze = config.freeze; + if (_freeze) { + auto pausedIndex = config.getIndex(); + if (_jitterBuffer->currentIndex != pausedIndex) { + _jitterBuffer.edit().currentIndex = pausedIndex; + } + } _scale = config.scale; } void JitterSample::run(const render::RenderContextPointer& renderContext, JitterBuffer& jitterBuffer) { diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 0fa0a5739e..b63a42b8ac 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -23,13 +23,29 @@ class JitterSampleConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float scale MEMBER scale NOTIFY dirty) Q_PROPERTY(bool freeze MEMBER freeze NOTIFY dirty) + Q_PROPERTY(int index READ getIndex NOTIFY dirty) public: JitterSampleConfig() : render::Job::Config(true) {} float scale{ 0.5f }; bool freeze{ false }; + + void setIndex(int current); + +public slots: + int pause(); + int prev(); + int next(); + int play(); + + int getIndex() const { return _index; } + signals: void dirty(); + +private: + int _index{ 0 }; + }; @@ -68,6 +84,7 @@ class AntialiasingConfig : public render::Job::Config { Q_PROPERTY(float velocityScale MEMBER velocityScale NOTIFY dirty) Q_PROPERTY(bool unjitter MEMBER unjitter NOTIFY dirty) + Q_PROPERTY(bool constrainColor MEMBER constrainColor NOTIFY dirty) Q_PROPERTY(bool debug MEMBER debug NOTIFY dirty) Q_PROPERTY(float debugX MEMBER debugX NOTIFY dirty) @@ -91,6 +108,7 @@ public: float debugOrbZoom{ 2.0f }; bool unjitter{ true }; + bool constrainColor{ true }; bool debug { false }; bool showCursorPixel { false }; @@ -116,6 +134,8 @@ struct TAAParams { void setUnjitter(bool enabled) { SET_BIT(debug.y, 0, enabled); } bool isUnjitter() const { return (bool)GET_BIT(debug.y, 0); } + void setConstrainColor(bool enabled) { SET_BIT(debug.y, 1, enabled); } + bool isConstrainColor() const { return (bool)GET_BIT(debug.y, 1); } void setDebug(bool enabled) { SET_BIT(debug.x, 0, enabled); } bool isDebug() const { return (bool) GET_BIT(debug.x, 0); } diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 8f591035f3..c387e165da 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -20,12 +20,14 @@ layout(location = 0) out vec4 outFragColor; void main() { vec2 texelSize = getInvWidthHeight(); - vec2 fragUV = varTexCoord0 - float(taa_unjitter()) * taa_getJitterSample(sequence.currentIndex) * texelSize; + vec2 fragUV = varTexCoord0; + if (taa_unjitter()) { + fragUV -= taa_getJitterSample(sequence.currentIndex) * texelSize; + } vec3 nearFragUV = taa_findClosestFragment3x3(fragUV); vec2 fragVel = taa_fetchVelocityMap(nearFragUV.xy); - /*vec3 sourceColor; vec3 historyColor; vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV, fragVel, sourceColor, historyColor); diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index ae9f62d471..cfe3170e24 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -67,7 +67,9 @@ bool taa_showClosestFragment() { bool taa_unjitter() { return GET_BIT(params.debug.y, 0); } - +bool taa_constrainColor() { + return GET_BIT(params.debug.y, 1); +} vec2 taa_getDebugCursorTexcoord() { return params.pixelInfo_orbZoom.xy; @@ -191,7 +193,10 @@ vec3 taa_temporalReprojection(vec2 fragUV, vec2 fragVelocity, float fragZe) vec2 imageSize = getWidthHeight(0); vec2 texelSize = getInvWidthHeight(); - fragUV += float(taa_unjitter()) * taa_getJitterSample(sequence.currentIndex) * texelSize; + + if (taa_unjitter()) { + fragUV += taa_getJitterSample(sequence.currentIndex) * texelSize; + } const float _SubpixelThreshold = 0.5; const float _GatherBase = 0.5; @@ -249,10 +254,11 @@ vec3 taa_temporalReprojection(vec2 fragUV, vec2 fragVelocity, float fragZe) float k_feedback = mix(_FeedbackMin, _FeedbackMax, unbiased_weight_sqr); // output - vec3 nextColor = mix(texel1, texel0, k_feedback).xyz; + vec3 nextColor = mix(texel1, texel0, k_feedback).xyz; - - // vec3 nextColor = mix(texel0, texel1, params.blend); + if (!taa_constrainColor()) { + nextColor = mix(historyColor, sourceColor, params.blend); + } return taa_resolveColor(nextColor); } diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index 44a54b44de..6cecaab7ea 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -73,17 +73,19 @@ void main(void) { vec2 prevOrbPosToPix = pixPos - prevOrbPos; float prevOrbPosToPixLength = length(prevOrbPosToPix); + float orbPixThreshold = 2.0 / taa_getDebugOrbZoom(); + if ((prevOrbPosToPixLength < tenPercentHeight) && (cursorVelocityLength > 0.5)) { vec2 prevOrbPosToPix_uv = cursorPrevUV + prevOrbPosToPix * texelSize / taa_getDebugOrbZoom(); vec3 preOrbColor = vec3(0.0); if (!(any(lessThan(prevOrbPosToPix_uv, vec2(0.0))) || any(greaterThan(prevOrbPosToPix_uv, vec2(1.0))))) { preOrbColor = texture(historyMap, prevOrbPosToPix_uv).xyz; } - if (prevOrbPosToPixLength < 2.0) { + if (prevOrbPosToPixLength < orbPixThreshold) { preOrbColor = vec3(1.0, 0.0, 1.0); } float distanceToNext = length(imageSize * (cursorUV - prevOrbPosToPix_uv)); - if (distanceToNext < 2.0) { + if (distanceToNext < orbPixThreshold) { preOrbColor = vec3(1.0, 0.5, 0.0); } outFragColor = vec4(preOrbColor, 1.0); @@ -96,10 +98,10 @@ void main(void) { nextOrbColor = texture(nextMap, nextOrbPosToPix_uv).xyz; } float distanceToPrev = length(imageSize * (cursorPrevUV - nextOrbPosToPix_uv)); - if (distanceToPrev < 2.0) { + if (distanceToPrev < orbPixThreshold) { nextOrbColor = vec3(1.0, 0.0, 1.0); } - if (nextOrbPosToPixLength < 2.0) { + if (nextOrbPosToPixLength < orbPixThreshold) { nextOrbColor = vec3(1.0, 0.5, 0.0); } @@ -114,13 +116,14 @@ void main(void) { vec2 jitterRegionPos = (pixPos - vec2(tenPercentHeight, imageSize.y - tenPercentHeight)); if ((all(lessThan(jitterRegionPos, jitterRegionSize)) && all(greaterThan(jitterRegionPos, vec2(0.0))))) { - float niceDotR2 = 4; + float niceDotR2 = 4.0; for (int s = 0; s < SEQUENCE_LENGTH; s++) { vec2 pixToSampleVec = jitterRegionPos - (vec2(0.5) + taa_getJitterSample(s)) * jitterRegionSize; - float radius2 = (s == sequence.currentIndex ? 2.0 * niceDotR2 : niceDotR2); - if (dot(pixToSampleVec, pixToSampleVec) < radius2) { - outFragColor = vec4(colorRamp(float(s) / float(SEQUENCE_LENGTH)), 1.0); + float radius2 = (s == sequence.currentIndex ? 4.0 * niceDotR2 : niceDotR2); + float distToSample2 = dot(pixToSampleVec, pixToSampleVec); + if (distToSample2 < radius2) { + outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(SEQUENCE_LENGTH)), 1.0 - distToSample2 / radius2), 1.0); return; } } diff --git a/scripts/developer/utilities/lib/styles-uit/HifiConstants.qmlc b/scripts/developer/utilities/lib/styles-uit/HifiConstants.qmlc index 369d4444878f60a092189d56d24fd586c7a0c747..a11d8cf029dcb2a16ad80b66aa3ac76475f0233e 100644 GIT binary patch delta 104 zcmaDcf%(M*W}U(^ljM}dl0-oU1_nk>R))Potmk4G85nG;85nAuW^T0qCvEb_ZFTsZ z_rd2k>inow4Q60qNMp!k$YDrjuwu{$!(=eaogtHR)%vaax!s@3=B5a3=DU@Bo!xd$^}mDUF9x# zN&L=6ogbB&p$rTRX$+YRISi=`Rt)-Jm<(olFl2&df*4X63K;Sydsek?zEU;C7XT#3 B9RmOW diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml index e3001e96cc..8f9c02b8be 100644 --- a/scripts/developer/utilities/render/antialiasing.qml +++ b/scripts/developer/utilities/render/antialiasing.qml @@ -30,6 +30,8 @@ Rectangle { spacing: 20 Column{ + spacing: 10 + ConfigSlider { label: qsTr("Source blend") integral: false @@ -47,11 +49,36 @@ Rectangle { min: 0.0 } Row { + spacing: 10 CheckBox { text: "Unjitter" checked: Render.getConfig("RenderMainView.Antialiasing")["unjitter"] onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["unjitter"] = checked } } + CheckBox { + text: "Freeze " + checked: Render.getConfig("RenderMainView.JitterCam")["freeze"] + onCheckedChanged: { Render.getConfig("RenderMainView.JitterCam")["freeze"] = checked } + } + Text { + text: Render.getConfig("RenderMainView.JitterCam").index + } + Button { + text: "<" + onClicked: { Render.getConfig("RenderMainView.JitterCam").prev(); } + } + Button { + text: ">" + onClicked: { Render.getConfig("RenderMainView.JitterCam").next(); } + } + } + Row { + spacing: 10 + CheckBox { + text: "Constrain color" + checked: Render.getConfig("RenderMainView.Antialiasing")["constrainColor"] + onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["constrainColor"] = checked } + } } Row { CheckBox { @@ -59,11 +86,6 @@ Rectangle { checked: Render.getConfig("RenderMainView.Antialiasing")["debug"] onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["debug"] = checked } } - CheckBox { - text: "Freeze " - checked: Render.getConfig("RenderMainView.JitterCam")["freeze"] - onCheckedChanged: { Render.getConfig("RenderMainView.JitterCam")["freeze"] = checked } - } CheckBox { text: "Show Debug Cursor" checked: Render.getConfig("RenderMainView.Antialiasing")["showCursorPixel"] @@ -85,7 +107,7 @@ Rectangle { onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["showJitterSequence"] = checked } } CheckBox { - text: "CLosest Fragment" + text: "Closest Fragment" checked: Render.getConfig("RenderMainView.Antialiasing")["showClosestFragment"] onCheckedChanged: { Render.getConfig("RenderMainView.Antialiasing")["showClosestFragment"] = checked } } @@ -103,8 +125,8 @@ Rectangle { integral: false config: Render.getConfig("RenderMainView.Antialiasing") property: "debugOrbZoom" - max: 8.0 - min: 0.0 + max: 32.0 + min: 1.0 } } }