Commit 45ceb95e authored by Jan Möbius's avatar Jan Möbius

Moved Grayscale PostProcessor to Free branch

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free-Staging@17534 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 77a86a38
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 "PostProcessorGrayPlugin.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>
PostProcessorGrayscalePlugin::PostProcessorGrayscalePlugin() :
shader_(0)
{
}
PostProcessorGrayscalePlugin::~PostProcessorGrayscalePlugin()
{
delete shader_;
}
QString PostProcessorGrayscalePlugin::postProcessorName() {
return QString("Grayscale");
}
void PostProcessorGrayscalePlugin::postProcess(ACG::GLState* _glstate, const PostProcessorInput& _input, GLuint _targetFBO) {
// ======================================================================================================
// Load shader if needed
// ======================================================================================================
if (!shader_)
shader_ = GLSL::loadProgram("Grayscale/screenquad.glsl", "Grayscale/gray.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( postprocessorgrayscaleplugin , PostProcessorGrayscalePlugin );
#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 PostProcessorGrayscalePlugin : public QObject, BaseInterface, PostProcessorInterface
{
Q_OBJECT
Q_INTERFACES(BaseInterface)
Q_INTERFACES(PostProcessorInterface)
#if QT_VERSION >= 0x050000
Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-PostProcessorGrayscale")
#endif
public:
PostProcessorGrayscalePlugin();
~PostProcessorGrayscalePlugin();
public :
QString name() { return (QString("Grayscale Postprocessor Plugin")); };
QString description( ) { return (QString(tr("Converts an RGB image to grayscale"))); };
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
uniform sampler2D textureSampler;
in vec2 vTexCoord;
out vec4 oColor;
void main()
{
vec4 col = texture2D(textureSampler, vTexCoord);
vec3 conv = vec3(0.299, 0.587, 0.114);
float lum = dot(col.rgb, conv);
oColor = vec4(lum, lum, lum, 1.0);
// oColor.xyz = rgbM;
}
#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
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