diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index b41aec4030..4e2d6dd489 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -409,8 +409,32 @@ int JitterSampleConfig::play() { return _index; } +template class Halton { +public: + + float eval(int index) { + float f = 1.0f; + float r = 0.0f; + float invB = 1.0f / (float)B; + index++; + + while (index > 0) { + f = f * invB; + r = r + f * (float) (index % B); + index = index / B; + } + + return r; + } +}; + + 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 }; @@ -421,7 +445,11 @@ JitterSample::SampleSequence::SampleSequence(){ offsets[7] = { 1.0f / 16.0f, 8.0f / 9.0f }; for (int i = 0; i < SEQUENCE_LENGTH; i++) { - offsets[i] = offsets[i] - vec2(0.5f); + offsets[i] = glm::vec2(genX.eval(i), genY.eval(i)); + } + + for (int i = 0; i < SEQUENCE_LENGTH; i++) { + offsets[i] -= vec2(0.5f); } } @@ -448,11 +476,13 @@ void JitterSample::run(const render::RenderContextPointer& renderContext, Jitter 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; - - projMat[2][0] += jx; - projMat[2][1] += jy; + // 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; + + projMat[2][0] += jx * projMat[0][0]; + projMat[2][1] += jy * projMat[1][1]; viewFrustum.setProjection(projMat); diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index b63a42b8ac..7743906509 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -54,7 +54,7 @@ public: struct SampleSequence { SampleSequence(); - static const int SEQUENCE_LENGTH{ 8 }; + static const int SEQUENCE_LENGTH{ 16 }; glm::vec2 offsets[SEQUENCE_LENGTH]; int sequenceLength{ SEQUENCE_LENGTH }; int currentIndex{ 0 }; diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index 85f094401b..6c4f85d70c 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -13,7 +13,7 @@ <@include DeferredTransform.slh@> <$declareDeferredFrameTransform()$> -const int SEQUENCE_LENGTH = 8; +const int SEQUENCE_LENGTH = 16; struct JitterSequence { vec4 offsets[SEQUENCE_LENGTH / 2]; int sequenceLength; diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index df820a5124..0daef04144 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -125,12 +125,13 @@ void main(void) { float niceDotR2 = 4.0; - for (int s = 0; s < SEQUENCE_LENGTH; s++) { + int sequenceLength = sequence.sequenceLength; + 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 distToSample2 = dot(pixToSampleVec, pixToSampleVec); if (distToSample2 < radius2) { - outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(SEQUENCE_LENGTH)), 1.0 - distToSample2 / radius2), 1.0); + outFragColor = vec4(mix( outFragColor.rgb, colorRamp(float(s) / float(sequenceLength)), 1.0 - distToSample2 / radius2), 1.0); return; } }