From 16fbe00ef5cc1063086a22fc2e6e66f200d9b293 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 30 Aug 2017 22:42:55 -0700 Subject: [PATCH] FIxing the jittering projection modification --- .../render-utils/src/AntialiasingEffect.cpp | 24 +++++------------- .../render-utils/src/AntialiasingEffect.h | 2 +- libraries/render-utils/src/taa.slf | 2 +- libraries/render-utils/src/taa.slh | 16 +++++++++--- libraries/render-utils/src/taa_blend.slf | 8 +++--- .../lib/styles-uit/HifiConstants.qmlc | Bin 51304 -> 51304 bytes 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 4e2d6dd489..b18d7f20ce 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -411,12 +411,11 @@ int JitterSampleConfig::play() { template class Halton { public: - float eval(int index) { float f = 1.0f; float r = 0.0f; float invB = 1.0f / (float)B; - index++; + index++; // Indices start at 1, not 0 while (index > 0) { f = f * invB; @@ -431,19 +430,9 @@ public: JitterSample::SampleSequence::SampleSequence(){ // Halton sequence (2,3) - Halton<2> genX; Halton<3> genY; - offsets[0] = { 1.0f / 2.0f, 1.0f / 3.0f }; - offsets[1] = { 1.0f / 4.0f, 2.0f / 3.0f }; - offsets[2] = { 3.0f / 4.0f, 1.0f / 9.0f }; - offsets[3] = { 1.0f / 8.0f, 4.0f / 9.0f }; - offsets[4] = { 5.0f / 8.0f, 7.0f / 9.0f }; - offsets[5] = { 3.0f / 8.0f, 2.0f / 9.0f }; - offsets[6] = { 7.0f / 8.0f, 5.0f / 9.0f }; - offsets[7] = { 1.0f / 16.0f, 8.0f / 9.0f }; - for (int i = 0; i < SEQUENCE_LENGTH; i++) { offsets[i] = glm::vec2(genX.eval(i), genY.eval(i)); } @@ -451,6 +440,7 @@ JitterSample::SampleSequence::SampleSequence(){ for (int i = 0; i < SEQUENCE_LENGTH; i++) { offsets[i] -= vec2(0.5f); } + offsets[SEQUENCE_LENGTH] = glm::vec2(0.0f); } void JitterSample::configure(const Config& config) { @@ -472,17 +462,17 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Jitter auto projMat = viewFrustum.getProjection(); auto theNear = viewFrustum.getNearClip(); - auto jit = _scale * jitterBuffer.get().offsets[current]; + auto jit = jitterBuffer.get().offsets[current]; auto width = (float) renderContext->args->_viewport.z; auto height = (float) renderContext->args->_viewport.w; // auto jx = -4.0 * jit.x / width; // auto jy = -4.0 * jit.y / height; - auto jx = -2.0 * jit.x / width; - auto jy = -2.0 * jit.y / height; + auto jx = 2.0 * jit.x / width; + auto jy = 2.0 * jit.y / height; - projMat[2][0] += jx * projMat[0][0]; - projMat[2][1] += jy * projMat[1][1]; + projMat[2][0] += jx; + projMat[2][1] += jy; viewFrustum.setProjection(projMat); diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 7743906509..ab25642880 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -55,7 +55,7 @@ public: struct SampleSequence { SampleSequence(); static const int SEQUENCE_LENGTH{ 16 }; - glm::vec2 offsets[SEQUENCE_LENGTH]; + glm::vec2 offsets[SEQUENCE_LENGTH + 1]; int sequenceLength{ SEQUENCE_LENGTH }; int currentIndex{ 0 }; diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 9115cdc832..23c6b5e8cc 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -22,7 +22,7 @@ void main() { vec2 fragUV = varTexCoord0; vec2 texelSize = getInvWidthHeight(); - vec2 fragJitterPix = taa_getJitterSample(sequence.currentIndex); + vec2 fragJitterPix = taa_getCurrentJitterSample(); if (taa_unjitter()) { fragUV -= fragJitterPix * texelSize; } diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 6c4f85d70c..fff5ef15c5 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -15,9 +15,7 @@ const int SEQUENCE_LENGTH = 16; struct JitterSequence { - vec4 offsets[SEQUENCE_LENGTH / 2]; - int sequenceLength; - int currentIndex; + vec4 offsets[(SEQUENCE_LENGTH / 2) + 1]; }; layout(std140) uniform taaJitterBuffer { JitterSequence sequence; @@ -27,6 +25,18 @@ vec2 taa_getJitterSample(int index) { return vec2((bool(index & 0x01) ? sequence.offsets[index >> 1].zw : sequence.offsets[index >> 1].xy)); } +int taa_getJitterSequenceLength() { + return int(sequence.offsets[(SEQUENCE_LENGTH / 2)].z); +} + +int taa_getCurrentJitterIndex() { + return int(sequence.offsets[(SEQUENCE_LENGTH / 2)].w); +} + +vec2 taa_getCurrentJitterSample() { + return taa_getJitterSample(taa_getCurrentJitterIndex()); +} + <@include gpu/Color.slh@> uniform sampler2D depthMap; diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index 0daef04144..cd046506d0 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -28,7 +28,7 @@ void main(void) { vec2 imageSize = getWidthHeight(0); vec2 texelSize = getInvWidthHeight(); - vec2 fragJitterPix = taa_getJitterSample(sequence.currentIndex); + vec2 fragJitterPix = taa_getCurrentJitterSample(); @@ -44,7 +44,7 @@ void main(void) { vec2 cursorUVRaw = taa_getDebugCursorTexcoord(); vec2 cursorPosRaw = floor(cursorUVRaw * imageSize) + vec2(0.5); vec3 cursorFrag = taa_findClosestFragment3x3(cursorUVRaw); - vec2 cursorUV = cursorFrag.xy - fragJitterPix * texelSize; + vec2 cursorUV = cursorUVRaw - fragJitterPix * texelSize; vec2 cursorPos = cursorUV * imageSize; vec2 cursorVelocity = texture(velocityMap, cursorUV).xy; vec2 cursorPrevUV = cursorUV - cursorVelocity; @@ -125,10 +125,10 @@ void main(void) { float niceDotR2 = 4.0; - int sequenceLength = sequence.sequenceLength; + int sequenceLength = taa_getJitterSequenceLength(); for (int s = 0; s < sequenceLength; s++) { vec2 pixToSampleVec = jitterRegionPos - (vec2(0.5) + taa_getJitterSample(s)) * jitterRegionSize; - float radius2 = (s == sequence.currentIndex ? 4.0 * niceDotR2 : niceDotR2); + float radius2 = (s == taa_getCurrentJitterIndex() ? 4.0 * niceDotR2 : niceDotR2); float distToSample2 = dot(pixToSampleVec, pixToSampleVec); if (distToSample2 < radius2) { outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(sequenceLength)), 1.0 - distToSample2 / radius2), 1.0); diff --git a/scripts/developer/utilities/lib/styles-uit/HifiConstants.qmlc b/scripts/developer/utilities/lib/styles-uit/HifiConstants.qmlc index a11d8cf029dcb2a16ad80b66aa3ac76475f0233e..369d4444878f60a092189d56d24fd586c7a0c747 100644 GIT binary patch delta 106 zcmaDcf%(M*W}U(^ljM}dl0-oU1_nk>R)%vaax!s@3=B5a3=DU@Bo!xd$^}mDUF9x# zN&L=6ogbB&p$rTRX$+YRISi=`Rt)-Jm<(olFl2&df*4X63K;Sydsek?zEU;C7XT#3 B9RmOW delta 104 zcmaDcf%(M*W}U(^ljM}dl0-oU1_nk>R))Potmk4G85nG;85nAuW^T0qCvEb_ZFTsZ z_rd2k>inow4Q60qNMp!k$YDrjuwu{$!(=eaogtH