From 6ec6ccfec15410eddb79a6ebbaf68f6c6e215d31 Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 17 Aug 2017 18:26:59 -0700 Subject: [PATCH] Just making debugging easier --- .../render-utils/src/AntialiasingEffect.cpp | 25 ++++++-- libraries/render-utils/src/taa.slf | 17 ++---- libraries/render-utils/src/taa_blend.slf | 61 +++++++++++++++++++ 3 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 libraries/render-utils/src/taa_blend.slf diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 8e532b2e82..5508891568 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -172,7 +172,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const */ #include "taa_frag.h" -#include "fxaa_blend_frag.h" +#include "taa_blend_frag.h" @@ -180,6 +180,8 @@ const int AntialiasingPass_FrameTransformSlot = 0; const int AntialiasingPass_HistoryMapSlot = 0; const int AntialiasingPass_SourceMapSlot = 1; const int AntialiasingPass_VelocityMapSlot = 2; +const int AntialiasingPass_CurrentMapSlot = 3; + Antialiasing::Antialiasing() { } @@ -220,16 +222,20 @@ const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() { const gpu::PipelinePointer& Antialiasing::getBlendPipeline() { if (!_blendPipeline) { auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); - auto ps = gpu::Shader::createPixel(std::string(fxaa_blend_frag)); + auto ps = gpu::Shader::createPixel(std::string(taa_blend_frag)); gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps); gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding(std::string("colorTexture"), 0)); - + slotBindings.insert(gpu::Shader::Binding(std::string("currentMap"), AntialiasingPass_CurrentMapSlot)); + slotBindings.insert(gpu::Shader::Binding(std::string("historyMap"), AntialiasingPass_HistoryMapSlot)); + slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), AntialiasingPass_SourceMapSlot)); + slotBindings.insert(gpu::Shader::Binding(std::string("velocityMap"), AntialiasingPass_VelocityMapSlot)); + + gpu::Shader::makeProgram(*program, slotBindings); gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - // PrepareStencil::testMask(*state); + PrepareStencil::testMask(*state); // Good to go add the brand new pipeline @@ -297,10 +303,17 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const batch.draw(gpu::TRIANGLE_STRIP, 4); // Blend step - batch.setResourceTexture(0, _antialiasingTexture[currentFrame]); + batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, _antialiasingTexture[currentFrame]); + batch.setFramebuffer(sourceBuffer); batch.setPipeline(getBlendPipeline()); batch.draw(gpu::TRIANGLE_STRIP, 4); + + batch.setResourceTexture(AntialiasingPass_HistoryMapSlot, nullptr); + batch.setResourceTexture(AntialiasingPass_SourceMapSlot, nullptr); + batch.setResourceTexture(AntialiasingPass_VelocityMapSlot, nullptr); + batch.setResourceTexture(AntialiasingPass_CurrentMapSlot, nullptr); + }); } diff --git a/libraries/render-utils/src/taa.slf b/libraries/render-utils/src/taa.slf index 9e1aaf6d43..ce9a347065 100644 --- a/libraries/render-utils/src/taa.slf +++ b/libraries/render-utils/src/taa.slf @@ -44,21 +44,14 @@ void main() { vec2 velocity = rawVelocity; vec2 prevTexCoord = varTexCoord0 - params.motionScale * velocity; + + vec3 prevColor = currentColor; - prevTexCoord = clamp(prevTexCoord, vec2(0.1), vec2(0.9)); - vec3 prevColor = texture(historyMap, prevTexCoord).xyz; + if (any(lessThan(prevTexCoord, vec2(0.0)) || any(greaterThan(prevTexCoord, vec2(1.0))) { + prevColor = texture(historyMap, prevTexCoord).xyz; + } vec3 newColor = mix(prevColor, currentColor, params.blend); outFragColor = vec4(newColor, 1.0); - - if (abs(varTexCoord0.x - params.debugX) < (1.0 / 2048.0)) { - outFragColor.rgb = vec3(1.0, 1.0, 0.0); - } - if (varTexCoord0.x < params.debugX) { - outFragColor = vec4(currentColor, 1.0); - if (dot(velocity, velocity) > 0.0001) { - outFragColor = vec4(0.0, 1.0, 1.0, 1.0); - } - } } diff --git a/libraries/render-utils/src/taa_blend.slf b/libraries/render-utils/src/taa_blend.slf new file mode 100644 index 0000000000..2b54baaf9d --- /dev/null +++ b/libraries/render-utils/src/taa_blend.slf @@ -0,0 +1,61 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// taa_blend.frag +// fragment shader +// +// Created by Sam Gateau on 8/17/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +<@include DeferredBufferWrite.slh@> + +uniform sampler2D currentMap; +uniform sampler2D colorMap; +uniform sampler2D historyMap; +uniform sampler2D velocityMap; + +in vec2 varTexCoord0; +layout(location = 0) out vec4 outFragColor; + +struct TAAParams +{ + float debugX; + float blend; + float motionScale; + float spareB; +}; + +layout(std140) uniform taaParamsBuffer { + TAAParams params; +}; + +void main(void) { + outFragColor = texture(currentMap, varTexCoord0); + + if (varTexCoord0.x > params.debugX) { + return; + } + + vec3 sourceColor = texture(colorMap, varTexCoord0).xyz; + + vec2 velocity = texture(velocityMap, varTexCoord0).xy; + vec2 prevTexCoord = varTexCoord0 - params.motionScale * velocity; + + outFragColor = vec4(sourceColor, 1.0); + + if (abs(varTexCoord0.x - params.debugX) < (1.0 / 2048.0)) { + outFragColor.rgb = vec3(1.0, 1.0, 0.0); + return; + } + + if (dot(velocity, velocity) > 0.0001) { + outFragColor = vec4(0.0, 1.0, 1.0, 1.0); + } + + +}