From bf982c3a85e91c4434155e78b830d8ffc8dfdcf5 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 25 Aug 2017 00:25:13 -0700 Subject: [PATCH] using the linear depth buffer and voila --- libraries/render-utils/src/AntialiasingEffect.cpp | 8 +++++--- libraries/render-utils/src/AntialiasingEffect.h | 2 +- libraries/render-utils/src/RenderDeferredTask.cpp | 2 +- libraries/render-utils/src/taa.slf | 8 +++++++- libraries/render-utils/src/taa.slh | 6 +++--- libraries/render-utils/src/taa_blend.slf | 5 +++++ 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index b07eff949e..cd90c1b08c 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -182,9 +182,10 @@ const int AntialiasingPass_FrameTransformSlot = 1; const int AntialiasingPass_HistoryMapSlot = 0; const int AntialiasingPass_SourceMapSlot = 1; const int AntialiasingPass_VelocityMapSlot = 2; -const int AntialiasingPass_NextMapSlot = 3; const int AntialiasingPass_DepthMapSlot = 3; +const int AntialiasingPass_NextMapSlot = 4; + Antialiasing::Antialiasing() { } @@ -298,7 +299,8 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const auto& deferredFrameTransform = inputs.get0(); auto& sourceBuffer = inputs.get1(); - auto& velocityBuffer = inputs.get2(); + auto& linearDepthBuffer = inputs.get2(); + auto& velocityBuffer = inputs.get3(); int width = sourceBuffer->getWidth(); int height = sourceBuffer->getHeight(); @@ -334,7 +336,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const batch.setResourceTexture(AntialiasingPass_HistoryMapSlot, _antialiasingTexture[prevFrame]); batch.setResourceTexture(AntialiasingPass_SourceMapSlot, sourceBuffer->getRenderBuffer(0)); batch.setResourceTexture(AntialiasingPass_VelocityMapSlot, velocityBuffer->getVelocityTexture()); - batch.setResourceTexture(AntialiasingPass_DepthMapSlot, sourceBuffer->getDepthStencilBuffer()); + batch.setResourceTexture(AntialiasingPass_DepthMapSlot, linearDepthBuffer->getLinearDepthTexture()); batch.setUniformBuffer(AntialiasingPass_ParamsSlot, _params._buffer); batch.setUniformBuffer(AntialiasingPass_FrameTransformSlot, deferredFrameTransform->getFrameTransformBuffer()); diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index f4b0b93915..91c92697b6 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -71,7 +71,7 @@ using TAAParamsBuffer = gpu::StructBuffer; class Antialiasing { public: - using Inputs = render::VaryingSet3; + using Inputs = render::VaryingSet4 < DeferredFrameTransformPointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, VelocityFramebufferPointer > ; using Config = AntialiasingConfig; using JobModel = render::Job::ModelI; diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index 8028b158f6..d5b8ac7fe0 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -221,7 +221,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren } // AA job to be revisited - const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, primaryFramebuffer, velocityBuffer).asVarying(); + const auto antialiasingInputs = Antialiasing::Inputs(deferredFrameTransform, primaryFramebuffer, linearDepthTarget, velocityBuffer).asVarying(); task.addJob("Antialiasing", antialiasingInputs); diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index aa88cc61e2..4b02757702 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -21,12 +21,18 @@ layout(location = 0) out vec4 outFragColor; void main() { vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0); + // vec3 fragUV = vec3(varTexCoord0, taa_fetchDepth(varTexCoord0)); vec2 fragVel = taa_fetchVelocityMap(fragUV.xy); - vec3 sourceColor; vec3 historyColor; //vec3 nextColor = taa_temporalReprojection(fragUV.xy, fragVel, fragUV.z); vec2 prevFragUV = taa_fetchSourceAndHistory(fragUV.xy, fragVel, sourceColor, historyColor); + /* vec3 sourceColor = taa_fetchSourceMap(fragUV.xy).xyz; + vec2 prevFragUV = fragUV.xy - fragVel; + vec3 historyColor = sourceColor; + if (!(any(lessThan(prevFragUV, vec2(0.0))) || any(greaterThan(prevFragUV, vec2(1.0))))) { + historyColor = taa_fetchHistoryMap(prevFragUV).xyz; + }*/ vec3 nextColor = mix(historyColor, sourceColor, params.blend); diff --git a/libraries/render-utils/src/taa.slh b/libraries/render-utils/src/taa.slh index ad27ae4939..1b2e0e3300 100644 --- a/libraries/render-utils/src/taa.slh +++ b/libraries/render-utils/src/taa.slh @@ -88,15 +88,15 @@ vec4 taa_fetchNextMap(vec2 uv) { } vec2 taa_fetchVelocityMap(vec2 uv) { - return params.motionScale * texture(velocityMap, uv).xy; + return texture(velocityMap, uv).xy; } float taa_fetchDepth(vec2 uv) { - return texture(depthMap, vec2(uv), 0).x; + return -texture(depthMap, vec2(uv), 0).x; } -#define ZCMP_GT(a, b) (a < b) +#define ZCMP_GT(a, b) (a > b) vec3 taa_findClosestFragment3x3(vec2 uv) { diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf index c66957a0ab..9bddee0a3d 100644 --- a/libraries/render-utils/src/taa_blend.slf +++ b/libraries/render-utils/src/taa_blend.slf @@ -21,6 +21,7 @@ void main(void) { vec3 nextColor = texture(nextMap, varTexCoord0).xyz; outFragColor = vec4(nextColor, 1.0); + // Pixel being shaded vec3 sourceColor = texture(sourceMap, varTexCoord0).xyz; @@ -115,6 +116,10 @@ void main(void) { return; } + vec3 fragUV = taa_findClosestFragment3x3(varTexCoord0); + outFragColor = vec4((fragUV.xy - varTexCoord0) * imageSize * 0.5 + vec2(0.5), 0.0, 1.0); + + return; outFragColor = vec4(nextColor, 1.0); vec3 prevColor = nextColor;