From c9a6d6bf148bd9c19365143c6199492ccdd51e2d Mon Sep 17 00:00:00 2001 From: Olivier Prat Date: Fri, 23 Feb 2018 11:53:05 +0100 Subject: [PATCH] Added adjustable post sharpen filter --- .../render-utils/src/AntialiasingEffect.cpp | 4 ++++ .../render-utils/src/AntialiasingEffect.h | 9 ++++++--- libraries/render-utils/src/fxaa_blend.slf | 18 +++++++++++++++++- .../utilities/render/antialiasing.qml | 9 +++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/libraries/render-utils/src/AntialiasingEffect.cpp b/libraries/render-utils/src/AntialiasingEffect.cpp index 06cf4f6675..2cabba1243 100644 --- a/libraries/render-utils/src/AntialiasingEffect.cpp +++ b/libraries/render-utils/src/AntialiasingEffect.cpp @@ -246,6 +246,8 @@ const gpu::PipelinePointer& Antialiasing::getBlendPipeline() { // Good to go add the brand new pipeline _blendPipeline = gpu::Pipeline::create(program, state); + _sharpenLoc = program->getUniforms().findLocation("sharpenIntensity"); + } return _blendPipeline; } @@ -280,6 +282,7 @@ const gpu::PipelinePointer& Antialiasing::getDebugBlendPipeline() { } void Antialiasing::configure(const Config& config) { + _sharpen = config.sharpen; _params.edit().blend = config.blend; _params.edit().covarianceGamma = config.covarianceGamma; @@ -363,6 +366,7 @@ void Antialiasing::run(const render::RenderContextPointer& renderContext, const batch.setPipeline(getDebugBlendPipeline()); } else { batch.setPipeline(getBlendPipeline()); + batch._glUniform1f(_sharpenLoc, _sharpen); } batch.setResourceFramebufferSwapChainTexture(AntialiasingPass_NextMapSlot, _antialiasingBuffers, 1); batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/libraries/render-utils/src/AntialiasingEffect.h b/libraries/render-utils/src/AntialiasingEffect.h index 0dc57f97cd..89209e5426 100644 --- a/libraries/render-utils/src/AntialiasingEffect.h +++ b/libraries/render-utils/src/AntialiasingEffect.h @@ -86,6 +86,7 @@ private: class AntialiasingConfig : public render::Job::Config { Q_OBJECT Q_PROPERTY(float blend MEMBER blend NOTIFY dirty) + Q_PROPERTY(float sharpen MEMBER sharpen NOTIFY dirty) Q_PROPERTY(float covarianceGamma MEMBER covarianceGamma NOTIFY dirty) Q_PROPERTY(bool constrainColor MEMBER constrainColor NOTIFY dirty) @@ -106,8 +107,8 @@ class AntialiasingConfig : public render::Job::Config { public: AntialiasingConfig() : render::Job::Config(true) {} - float blend{ 0.075f }; - + float blend{ 0.05f }; + float sharpen{ 0.25f }; bool constrainColor{ true }; bool covarianceClipColor{ true }; @@ -134,7 +135,7 @@ signals: struct TAAParams { float nope{ 0.0f }; - float blend{ 0.1f }; + float blend{ 0.05f }; float covarianceGamma{ 1.0f }; float debugShowVelocityThreshold{ 1.0f }; @@ -199,6 +200,8 @@ private: gpu::PipelinePointer _debugBlendPipeline; TAAParamsBuffer _params; + float _sharpen{ 0.25f }; + int _sharpenLoc{ -1 }; }; diff --git a/libraries/render-utils/src/fxaa_blend.slf b/libraries/render-utils/src/fxaa_blend.slf index c38de8cb4e..7a10cecb94 100644 --- a/libraries/render-utils/src/fxaa_blend.slf +++ b/libraries/render-utils/src/fxaa_blend.slf @@ -18,7 +18,23 @@ in vec2 varTexCoord0; out vec4 outFragColor; uniform sampler2D colorTexture; +uniform float sharpenIntensity; void main(void) { - outFragColor = texture(colorTexture, varTexCoord0); + vec4 pixels[9]; + vec4 sharpenedPixel; + pixels[0] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(-1,-1), 0); + pixels[1] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(0,-1), 0); + pixels[2] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(1,-1), 0); + + pixels[3] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(-1,0), 0); + pixels[4] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy), 0); + pixels[5] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(1,0), 0); + + pixels[6] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(-1,1), 0); + pixels[7] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(0,1), 0); + pixels[8] = texelFetch(colorTexture, ivec2(gl_FragCoord.xy)+ivec2(1,1), 0); + + sharpenedPixel = pixels[4]*7.8 - (pixels[1]+pixels[3]+pixels[5]+pixels[7]) - (pixels[0]+pixels[2]+pixels[6]+pixels[8])*0.7; + outFragColor = mix(pixels[4], sharpenedPixel, sharpenIntensity); } diff --git a/scripts/developer/utilities/render/antialiasing.qml b/scripts/developer/utilities/render/antialiasing.qml index 26b9e09c09..8487c9160a 100644 --- a/scripts/developer/utilities/render/antialiasing.qml +++ b/scripts/developer/utilities/render/antialiasing.qml @@ -137,6 +137,15 @@ Rectangle { max: 1.0 min: 0.0 } + + ConfigSlider { + label: qsTr("Post sharpen") + integral: false + config: Render.getConfig("RenderMainView.Antialiasing") + property: "sharpen" + max: 1.0 + min: 0.0 + } } Separator {}