Commit 2ba50aa5 authored by Jan's avatar Jan
Browse files

External postprocessors

parent 418160a8
......@@ -4,3 +4,21 @@
[submodule "Plugin-PoissonReconstruction"]
path = Plugin-PoissonReconstruction
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-PoissonReconstruction.git
[submodule "PluginCollection-PostProcessors/Plugin-RadialBlur"]
path = PluginCollection-PostProcessors/Plugin-RadialBlur
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-RadialBlur.git
[submodule "PluginCollection-PostProcessors/Plugin-PoissonBlur"]
path = PluginCollection-PostProcessors/Plugin-PoissonBlur
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-PoissonBlur.git
[submodule "PluginCollection-PostProcessors/Plugin-GaussBlur"]
path = PluginCollection-PostProcessors/Plugin-GaussBlur
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-GaussBlur.git
[submodule "PluginCollection-PostProcessors/Plugin-FXAA"]
path = PluginCollection-PostProcessors/Plugin-FXAA
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-FXAA.git
[submodule "PluginCollection-PostProcessors/Plugin-DoF"]
path = PluginCollection-PostProcessors/Plugin-DoF
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-DoF.git
[submodule "PluginCollection-PostProcessors/Plugin-BilateralBlur"]
path = PluginCollection-PostProcessors/Plugin-BilateralBlur
url = https://www.graphics.rwth-aachen.de:9000/OpenFlipper-Free/Plugin-BilateralBlur.git
Subproject commit 9b9ad29582f81e083fa17e8e9a4f9f7cc704fcf0
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 17080 $ *
* $LastChangedBy: moeller $ *
* $Date: 2013-07-19 12:58:31 +0200 (Fri, 19 Jul 2013) $ *
* *
\*===========================================================================*/
#include <ACG/GL/acg_glew.hh>
#include "PostProcessorBilateralBlur.hh"
#include <ACG/GL/ScreenQuad.hh>
#include <ACG/GL/ShaderCache.hh>
#include <ACG/GL/GLFormatInfo.hh>
#include <QDialog>
#include <QColor>
#include <QLabel>
#include <QSlider>
#include <QVBoxLayout>
#include <ACG/QtWidgets/QtColorChooserButton.hh>
PostProcessorBilateralBlur::PostProcessorBilateralBlur()
: blur_(32, 32, 4, 2.0f, 2.0f, GL_RGBA)
{
}
PostProcessorBilateralBlur::~PostProcessorBilateralBlur()
{
}
QString PostProcessorBilateralBlur::checkOpenGL()
{
if (!ACG::openGLVersion(3,0))
return QString("Bilateral blur plugin requires OpenGL 3.0!");
return QString("");
}
void PostProcessorBilateralBlur::postProcess( ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output )
{
glBindFramebuffer(GL_FRAMEBUFFER, _output.fbo_);
glDrawBuffer(_output.drawBuffer_);
glDepthMask(1);
glColorMask(1,1,1,1);
blur_.resizeInput(_input[0]->width, _input[0]->height);
blur_.setParams(_glstate->projection(), _input[0]->depthTex_);
blur_.execute(_input[0]->colorTex_, 0, 0, 0);
}
QAction* PostProcessorBilateralBlur::optionsAction()
{
QAction * action = new QAction("Gaussian Blur Options" , this );
connect(action,SIGNAL(triggered( bool )),this,SLOT(optionDialog( bool )));
return action;
}
void PostProcessorBilateralBlur::optionDialog( bool )
{
//generate widget
QDialog* optionsDlg = new QDialog();
QVBoxLayout* layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
QColor curColor;
curColor.setRgbF(0.3f, 0.2f, 0.7f);
QLabel* label = new QLabel(tr("Radius [1, 32]:"));
layout->addWidget(label);
QSlider* radiusSlider = new QSlider(Qt::Horizontal);
radiusSlider->setRange(1, 32);
radiusSlider->setValue(8);
radiusSlider->setTracking(true);
layout->addWidget(radiusSlider);
label = new QLabel(tr("spatial sigma [0.1, 20.0]:"));
layout->addWidget(label);
QSlider* sigmaSlider = new QSlider(Qt::Horizontal);
sigmaSlider->setRange(1, 200);
sigmaSlider->setValue(10);
sigmaSlider->setTracking(true);
layout->addWidget(sigmaSlider);
label = new QLabel(tr("linear depth sigma [0.1, 20.0]:"));
layout->addWidget(label);
QSlider* sigmaRSlider = new QSlider(Qt::Horizontal);
sigmaRSlider->setRange(1, 200);
sigmaRSlider->setValue(10);
sigmaRSlider->setTracking(true);
layout->addWidget(sigmaRSlider);
optionsDlg->setLayout(layout);
connect(radiusSlider, SIGNAL(sliderMoved(int)), this, SLOT(radiusChanged(int)));
connect(sigmaSlider, SIGNAL(sliderMoved(int)), this, SLOT(sigmaSChanged(int)));
connect(sigmaRSlider, SIGNAL(sliderMoved(int)), this, SLOT(sigmaRChanged(int)));
optionsDlg->show();
}
void PostProcessorBilateralBlur::radiusChanged( int _radius )
{
ACG::Vec2f sigma = blur_.sigma();
blur_.setKernel(_radius, sigma[0], sigma[1]);
}
void PostProcessorBilateralBlur::sigmaSChanged( int _val )
{
ACG::Vec2f sigma = blur_.sigma();
sigma[0] = float(_val) * 0.1f;
blur_.setKernel(blur_.radius(), sigma[0], sigma[1]);
}
void PostProcessorBilateralBlur::sigmaRChanged( int _val )
{
ACG::Vec2f sigma = blur_.sigma();
sigma[1] = float(_val) * 0.1f;
blur_.setKernel(blur_.radius(), sigma[0], sigma[1]);
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( postprocessorbilateralblurplugin , PostProcessorBilateralBlur );
#endif
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
* www.openflipper.org *
* *
*--------------------------------------------------------------------------- *
* This file is part of OpenFlipper. *
* *
* OpenFlipper is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 3 of *
* the License, or (at your option) any later version with the *
* following exceptions: *
* *
* If other files instantiate templates or use macros *
* or inline functions from this file, or you compile this file and *
* link it with other files to produce an executable, this file does *
* not by itself cause the resulting executable to be covered by the *
* GNU Lesser General Public License. This exception does not however *
* invalidate any other reasons why the executable file might be *
* covered by the GNU Lesser General Public License. *
* *
* OpenFlipper is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU LesserGeneral Public *
* License along with OpenFlipper. If not, *
* see <http://www.gnu.org/licenses/>. *
* *
\*===========================================================================*/
/*===========================================================================*\
* *
* $Revision: 17080 $ *
* $LastChangedBy: moeller $ *
* $Date: 2013-07-19 12:58:31 +0200 (Fri, 19 Jul 2013) $ *
* *
\*===========================================================================*/
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/PostProcessorInterface.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/FBO.hh>
#include <vector>
#include <ACG/GL/FilterKernels.hh>
class PostProcessorBilateralBlur : public QObject, BaseInterface, PostProcessorInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(PostProcessorInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PostProcessorBilateralBlur")
#endif
public:
PostProcessorBilateralBlur();
~PostProcessorBilateralBlur();
public :
QString name() { return (QString("Bilateral Blur Postprocessor Plugin")); };
QString description( ) { return (QString(tr("Separable bilateral blur"))); };
public slots:
QString version() { return QString("1.0"); };
QAction* optionsAction();
private slots:
void postProcess(ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output);
QString postProcessorName() {return QString("Bilateral Blur");}
QString checkOpenGL();
void optionDialog(bool);
void radiusChanged(int);
void sigmaSChanged(int);
void sigmaRChanged(int);
private:
ACG::BilateralBlurFilter blur_;
};
Subproject commit 0d16054d33fda4d3072367e77ef4613b724e09d8
include (plugin)
openflipper_plugin ( INSTALLDATA Shaders GLEWDEFINITIONS GL_BUFFER_UPDATE_BARRIER_BIT GL_SHADER_IMAGE_ACCESS_BARRIER_BIT GL_ATOMIC_COUNTER_BARRIER_BIT )
#version 430
in vec2 vTexCoord;
out vec4 outColor;
layout(binding = 0) uniform sampler2D g_Input;
layout(binding = 0, rgba32f) uniform image2D g_Output;
void main()
{
ivec2 pos = ivec2(gl_FragCoord.xy);
vec4 v = texture(g_Input, vTexCoord);
imageStore(g_Output, pos, v);
discard;
outColor = v;
}
#version 430
/*
ref: http://http.developer.nvidia.com/GPUGems/gpugems_ch23.html
*/
#include "../Common/depthbuffer.glsl"
in vec2 vTexCoord;
out vec4 outColor;
layout(binding = 0) uniform sampler2D g_SAT;
layout(binding = 1) uniform sampler2D g_DepthTex;
layout(binding = 2) uniform sampler2D g_SceneTex;
uniform mat4 g_P;
uniform vec2 g_ClipPlanes;
vec4 textureBoxFilter(in sampler2D tex, in vec2 pos, in vec2 size)
{
ivec2 iDim = ivec2(textureSize(tex, 0));
ivec2 iPos = ivec2(iDim * pos);
ivec2 iSize = ivec2(size);
iSize = max(iSize, ivec2(1,1));
ivec2 iPosMax = iPos + iSize;
ivec2 iPosMin = iPos - iSize;
// fix filtering at border
ivec2 borderShift = max(iPosMax - iDim + ivec2(1,1), ivec2(0,0));
iPosMax -= borderShift;
iPosMin -= borderShift;
// SAT lookup
vec4 v = texelFetch(tex, iPosMax, 0);
v -= texelFetch(tex, ivec2(iPosMin.x, iPosMax.y), 0);
v -= texelFetch(tex, ivec2(iPosMax.x, iPosMin.y), 0);
v += texelFetch(tex, iPosMin, 0);
// div by area
v /= float(iSize.x * iSize.y * 4); // fast enough, but could be in float alu
return v;
}
// input: depth in view space (positive depth, so -posVS.z)
float ComputeCOC(float depthVS)
{
// "Improved Depth-of-Field Rendering" Scheuermann and Tatarchuk (ShaderX 3)
float f;
float focusZ = mix(g_ClipPlanes.x, g_ClipPlanes.y, 0.4);
if (depthVS < focusZ)
{
f = (depthVS - focusZ) / (focusZ - g_ClipPlanes.x);
}
else
{
f = (depthVS - focusZ) / (g_ClipPlanes.y - focusZ);
f = clamp(f, 0, 1);
}
// return f * 0.5 + 0.5;
// not based on a real model, but does not require param tweaking
return pow(abs(depthVS - focusZ), 1.2) * 0.21;
}
void main()
{
vec2 texSize = vec2(textureSize(g_SAT, 0));
float depth = texture(g_DepthTex, vTexCoord).x;
float zVS = ProjectedToViewspaceDepth(depth, g_P[2][2], g_P[3][2]);
float coc = ComputeCOC(-zVS);
vec4 col = vec4(0,0,0,0);
if (coc <= 1.0)
col = texture(g_SceneTex, vTexCoord);
else
col = textureBoxFilter(g_SAT, vTexCoord, vec2(coc, coc));
outColor = col;
// outColor = textureLod(g_SceneTex, vTexCoord, 0);
// outColor = vec4(1,1,1,1) * fract(zVS);
// outColor = vec4(1,1,1,1) * (-zVS);
}
#ifndef SAT_BLOCKSIZE
#define SAT_BLOCKSIZE 64
#endif
/*
supported data types
*/
#define SAT_FLOAT1 1
#define SAT_FLOAT2 2
//#define SAT_FLOAT3 3 rgb32f not supported by opengl
#define SAT_FLOAT4 4
#define SAT_INT1 5
#define SAT_INT2 6
//#define SAT_INT3 7
#define SAT_INT4 8
#define SAT_UINT1 9
#define SAT_UINT2 10
//#define SAT_UINT3 11
#define SAT_UINT4 12
#ifndef SAT_DATATYPE
#define SAT_DATATYPE SAT_FLOAT4
#endif
// find internalfmt of rw-buffers
#if SAT_DATATYPE == SAT_FLOAT1
#define SAT_INTERNALFMT r32f
#define SAT_DATAVEC float
#define SAT_DATANULL 0.0f
#define SAT_ELEMDIM 1
#elif SAT_DATATYPE == SAT_FLOAT2
#define SAT_INTERNALFMT rg32f
#define SAT_DATAVEC vec2
#define SAT_DATANULL vec2(0,0)
#define SAT_ELEMDIM 2
#elif SAT_DATATYPE == SAT_FLOAT4
#define SAT_INTERNALFMT rgba32f
#define SAT_DATAVEC vec4
#define SAT_DATANULL vec4(0,0,0,0)
#define SAT_ELEMDIM 4
#elif SAT_DATATYPE == SAT_INT1
#define SAT_INTERNALFMT r32i
#define SAT_DATAVEC int
#define SAT_DATANULL 0
#define SAT_ELEMDIM 1
#elif SAT_DATATYPE == SAT_INT2
#define SAT_INTERNALFMT rg32i
#define SAT_DATAVEC ivec2
#define SAT_DATANULL ivec2(0,0)
#define SAT_ELEMDIM 2
#elif SAT_DATATYPE == SAT_INT4
#define SAT_INTERNALFMT rgba32i
#define SAT_DATAVEC ivec4
#define SAT_DATANULL ivec4(0,0,0,0)
#define SAT_ELEMDIM 4
#elif SAT_DATATYPE == SAT_UINT1
#define SAT_INTERNALFMT r32ui
#define SAT_DATAVEC uint
#define SAT_DATANULL 0
#define SAT_ELEMDIM 1
#elif SAT_DATATYPE == SAT_UINT2
#define SAT_INTERNALFMT rg32ui
#define SAT_DATAVEC uvec2
#define SAT_DATANULL uvec2(0,0)
#define SAT_ELEMDIM 2
#elif SAT_DATATYPE == SAT_UINT4
#define SAT_INTERNALFMT rgba32ui
#define SAT_DATAVEC uvec4
#define SAT_DATANULL uvec4(0,0,0,0)
#define SAT_ELEMDIM 4
#endif
// find prefix for gvec type of input
#if SAT_DATATYPE <= SAT_FLOAT4
#define SAT_TYPEPREFIX
#define SAT_DATASCALAR float
#elif SAT_DATATYPE <= SAT_INT4
#define SAT_TYPEPREFIX i
#define SAT_DATASCALAR int
#elif SAT_DATATYPE <= SAT_UINT4
#define SAT_TYPEPREFIX u
#define SAT_DATASCALAR uint
#endif
// macro magic, direct concatenation does not work
#define SAT_PASTER_1(x,y) x ## y
#define SAT_PASTER(x,y) SAT_PASTER_1(x,y)
// wrap imageLoad/imageStore to work with values of type SAT_DATAVEC instead of gvec4
#if SAT_ELEMDIM == 1
#define SAT_imageLoad(a,b) imageLoad(a,b).x
#define SAT_imageStore(a,b,c) imageStore(a,b,SAT_PASTER(SAT_TYPEPREFIX,vec4(c,0,0,0)))
#elif SAT_ELEMDIM == 2
#define SAT_imageLoad(a,b) imageLoad(a,b).xy
#define SAT_imageStore(a,b,c) imageStore(a,b,SAT_PASTER(SAT_TYPEPREFIX,vec4(c,0,0)))
#elif SAT_ELEMDIM == 3
#define SAT_imageLoad(a,b) imageLoad(a,b).xyz
#define SAT_imageStore(a,b,c) imageStore(a,b,SAT_PASTER(SAT_TYPEPREFIX,vec4(c,0)))
//#define SAT_imageStore(a,b,c) imageStore(a,b, SAT_TYPEPREFIX ## vec4(c,0,0))
#elif SAT_ELEMDIM == 4
#define SAT_imageLoad(a,b) imageLoad(a,b)
#define SAT_imageStore(a,b,c) imageStore(a,b,c)
#endif
// find image type
#ifdef SAT_2D
#define SAT_IMAGETYPE SAT_PASTER(SAT_TYPEPREFIX,image2D)
#else
#define SAT_IMAGETYPE SAT_PASTER(SAT_TYPEPREFIX,imageBuffer)
#endif
#version 440
#ifndef SAT_BLOCKSIZE
#define SAT_BLOCKSIZE 32
#endif
#include "macros.glsl"
// IMPORTANT: has to be adjusted for prefixsum of blocksums pass,
// local_size_x = inputsize / 64
layout (local_size_x = SAT_BLOCKSIZE, local_size_y = SAT_BLOCKSIZE) in;
layout(binding = 0, SAT_INTERNALFMT) uniform SAT_IMAGETYPE g_InputTex;
layout(binding = 1, SAT_INTERNALFMT) uniform SAT_IMAGETYPE g_OutputTex;
//#define SAT_OOBCHECK
void main()