Commit 4a4650e0 authored by Jan Möbius's avatar Jan Möbius

Added Sobel Post Processor


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free-Staging@17536 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8342d972
include (plugin)
openflipper_plugin ( INSTALLDATA Shaders )
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2013 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$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#else
#include <QtGui>
#endif
#include "PostProcessorSobelPlugin.hh"
#include <iostream>
#include <ACG/GL/GLState.hh>
#include <ACG/GL/gl.hh>
#include <ACG/GL/ScreenQuad.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
PostProcessorSobelPlugin::PostProcessorSobelPlugin() :
shader_(0)
{
}
PostProcessorSobelPlugin::~PostProcessorSobelPlugin()
{
delete shader_;
}
QString PostProcessorSobelPlugin::postProcessorName() {
return QString("Sobel");
}
void PostProcessorSobelPlugin::postProcess(ACG::GLState* _glstate, const PostProcessorInput& _input, GLuint _targetFBO) {
// ======================================================================================================
// Load shader if needed
// ======================================================================================================
if (!shader_)
shader_ = GLSL::loadProgram("Sobel/screenquad.glsl", "Sobel/sobel.glsl");
// ======================================================================================================
// Bind input texture
// ======================================================================================================
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _input.colorTex_);
// ======================================================================================================
// Bind output FBO
// ======================================================================================================
glBindFramebuffer(GL_FRAMEBUFFER, _targetFBO);
// ======================================================================================================
// Clear rendering buffer
// ======================================================================================================
_glstate->clearBuffers();
// ======================================================================================================
// Setup render states
// ======================================================================================================
glDepthMask(1);
glColorMask(1,1,1,1);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
// ======================================================================================================
// Setup shader
// ======================================================================================================
shader_->use();
shader_->setUniform("textureSampler", 0);
ACG::Vec2f texcoordOffset(1.0f / float(_input.width), 1.0f / float(_input.height));
shader_->setUniform("texcoordOffset", texcoordOffset);
// ======================================================================================================
// Execute
// ======================================================================================================
ACG::ScreenQuad::draw(shader_);
shader_->disable();
}
#if QT_VERSION < 0x050000
Q_EXPORT_PLUGIN2( postprocessorsobelplugin , PostProcessorSobelPlugin );
#endif
/*===========================================================================*\
* *
* OpenFlipper *
* Copyright (C) 2001-2013 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$ *
* $LastChangedBy$ *
* $Date$ *
* *
\*===========================================================================*/
#include <QObject>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/PostProcessorInterface.hh>
#include <ACG/GL/globjects.hh>
#include <ACG/ShaderUtils/GLSLShader.hh>
class PostProcessorSobelPlugin : public QObject, BaseInterface, PostProcessorInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(PostProcessorInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PostProcessorSobel")
#endif
public:
PostProcessorSobelPlugin();
~PostProcessorSobelPlugin();
public :
QString name() { return (QString("Sobel Postprocessor Plugin")); };
QString description( ) { return (QString(tr("Runs a sobel filter on the image"))); };
public slots:
QString version() { return QString("1.0"); };
private slots:
void postProcess(ACG::GLState* _glstate, const PostProcessorInput& _input, GLuint _targetFBO);
QString postProcessorName();
private:
/// shader
GLSL::Program* shader_;
};
#version 150
in vec4 inPosition;
out vec2 vTexCoord;
void main()
{
gl_Position = inPosition;
vTexCoord = inPosition.xy * 0.5 + vec2(0.5, 0.5);
}
\ No newline at end of file
#version 150
uniform sampler2D textureSampler;
in vec2 vTexCoord;
out vec4 oColor;
// The inverse of the texture dimensions along X and Y
uniform vec2 texcoordOffset;
void main()
{
vec2 coord_tl = vec2( vTexCoord.x + texcoordOffset.x , vTexCoord.y - texcoordOffset.y );
vec2 coord_t = vec2( vTexCoord.x + texcoordOffset.x , vTexCoord.y );
vec2 coord_tr = vec2( vTexCoord.x + texcoordOffset.x , vTexCoord.y + texcoordOffset.y );
vec2 coord_cl = vec2( vTexCoord.x,vTexCoord.y-texcoordOffset.y );
vec2 coord_cr = vec2( vTexCoord.x,vTexCoord.y+texcoordOffset.y );
vec2 coord_bl = vec2( vTexCoord.x-texcoordOffset.x,vTexCoord.y-texcoordOffset.y );
vec2 coord_b = vec2( vTexCoord.x-texcoordOffset.x,vTexCoord.y );
vec2 coord_br = vec2( vTexCoord.x-texcoordOffset.x,vTexCoord.y+texcoordOffset.y );
vec4 color_horizontal = abs(texture2D(textureSampler, coord_tl) - texture2D(textureSampler, coord_tr));
color_horizontal += abs(2.0 * texture2D(textureSampler, coord_cl) - 2.0 * texture2D(textureSampler, coord_cr));
color_horizontal += abs(texture2D(textureSampler, coord_bl) - texture2D(textureSampler, coord_br));
vec4 color_vertical = abs(texture2D(textureSampler, coord_tl) - texture2D(textureSampler, coord_bl));
color_vertical += abs(2.0 * texture2D(textureSampler, coord_t) - 2.0 * texture2D(textureSampler, coord_b));
color_vertical += abs(texture2D(textureSampler, coord_tr) - texture2D(textureSampler, coord_br));
oColor = color_horizontal + color_vertical;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment