From ff6b9f59f86bbf7b47519c8ed0dd4c1f29e2348c Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 8 Aug 2017 01:06:47 -0700 Subject: [PATCH] Trying to produce history and current in one pass but it doesn;t work ? --- .../render-utils/src/AntialiasingEffect.cpp | 41 +++++++++++-------- libraries/render-utils/src/fxaa.slf | 18 +++++--- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index ce7c418776..c520e26bb1 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -188,22 +188,7 @@ Antialiasing::~Antialiasing() { } const gpu::PipelinePointer& Antialiasing::getAntialiasingPipeline() { - int width = DependencyManager::get()->getFrameBufferSize().width(); - int height = DependencyManager::get()->getFrameBufferSize().height(); - - if (_antialiasingBuffer && _antialiasingBuffer->getSize() != uvec2(width, height)) { - _antialiasingBuffer.reset(); - } - - if (!_antialiasingBuffer) { - // Link the antialiasing FBO to texture - _antialiasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing")); - auto format = gpu::Element::COLOR_SRGBA_32; // DependencyManager::get()->getLightingTexture()->getTexelFormat(); - auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); - _antialiasingTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler); - _antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture); - } - + if (!_antialiasingPipeline) { auto vs = gpu::StandardShaderLib::getDrawUnitQuadTexcoordVS(); @@ -257,6 +242,25 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const RenderArgs* args = renderContext->args; + int width = sourceBuffer->getWidth(); + int height = sourceBuffer->getHeight(); + + if (_antialiasingBuffer) { + if (_antialiasingBuffer->getSize() != uvec2(width, height) || (sourceBuffer && (_antialiasingBuffer->getRenderBuffer(1) != sourceBuffer->getRenderBuffer(0)))) { + _antialiasingBuffer.reset(); + } + } + + if (!_antialiasingBuffer) { + // Link the antialiasing FBO to texture + _antialiasingBuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("antialiasing")); + auto format = gpu::Element::COLOR_SRGBA_32; // DependencyManager::get()->getLightingTexture()->getTexelFormat(); + auto defaultSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_POINT); + _antialiasingTexture = gpu::Texture::createRenderBuffer(format, width, height, gpu::Texture::SINGLE_MIP, defaultSampler); + _antialiasingBuffer->setRenderBuffer(0, _antialiasingTexture); + _antialiasingBuffer->setRenderBuffer(1, sourceBuffer->getRenderBuffer(0)); + } + gpu::doInBatch(args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); batch.setViewportTransform(args->_viewport); @@ -268,14 +272,15 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const batch.setFramebuffer(_antialiasingBuffer); batch.setPipeline(getAntialiasingPipeline()); batch.draw(gpu::TRIANGLE_STRIP, 4); + batch.setFramebuffer(sourceBuffer); // Blend step // batch.setResourceTexture(0, _antialiasingTexture); - batch.setResourceTexture(1, nullptr); + /* batch.setResourceTexture(1, nullptr); batch.setFramebuffer(sourceBuffer); batch.setPipeline(getBlendPipeline()); batch.draw(gpu::TRIANGLE_STRIP, 4); - + */ }); } diff --git a/libraries/render-utils/src/fxaa.slf b/libraries/render-utils/src/fxaa.slf index 8bbe2887f5..860030181a 100644 --- a/libraries/render-utils/src/fxaa.slf +++ b/libraries/render-utils/src/fxaa.slf @@ -27,17 +27,18 @@ uniform sampler2D historyTexture; uniform vec2 texcoordOffset; in vec2 varTexCoord0; -out vec4 outFragColor; +layout(location = 0) out vec4 outFragColor; +layout(location = 1) out vec4 outFragColor2; void main() { // outFragColor = vec4(texture(colorTexture, varTexCoord0).xyz, 0.3); // v2 - float ModulationFactor = 1.0 / 16.0; + float ModulationFactor = 1.0 / 8.0; vec3 CurrentSubpixel = textureLod(colorTexture, varTexCoord0, 0.0).rgb; vec3 History = textureLod(historyTexture, varTexCoord0, 0.0).rgb; - +/* vec3 NearColor0 = textureLodOffset(colorTexture, varTexCoord0, 0.0, ivec2(1, 0)).xyz; vec3 NearColor1 = textureLodOffset(colorTexture, varTexCoord0, 0.0, ivec2(0, 1)).xyz; vec3 NearColor2 = textureLodOffset(colorTexture, varTexCoord0, 0.0, ivec2(-1, 0)).xyz; @@ -46,11 +47,16 @@ void main() { vec3 BoxMin = min(CurrentSubpixel, min(NearColor0, min(NearColor1, min(NearColor2, NearColor3)))); vec3 BoxMax = max(CurrentSubpixel, max(NearColor0, max(NearColor1, max(NearColor2, NearColor3))));; - History = clamp(History, BoxMin, BoxMax); + if (gl_FragCoord.x > 800) { + History = clamp(History, BoxMin, BoxMax); + }*/ + outFragColor2.xyz = mix(CurrentSubpixel, History, ModulationFactor); + outFragColor2.w = 1.0; - //if (gl_FragCoord.x > 800) { - outFragColor.xyz = History; + outFragColor.xyz = CurrentSubpixel; outFragColor.w = ModulationFactor; + + /* } else { outFragColor.xyz = CurrentSubpixel; outFragColor.w = 1.0;