Commit d2c16b73 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

add options dialog for toon renderer

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@18367 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 9fc2ae2e
......@@ -4,6 +4,7 @@ uniform sampler2D samplerScene;
uniform sampler2D samplerDepth;
uniform vec2 clipPlanes;
uniform vec3 outlineColor;
in vec2 vTexCoord;
out vec4 oColor;
......@@ -44,7 +45,7 @@ void main()
vec4 color_scene = texture2D(samplerScene, vTexCoord);
oColor = vec4(color_scene.xyz * edge_factor, color_scene.w);
oColor = vec4(mix(outlineColor.xyz, color_scene.xyz, edge_factor), color_scene.w);
// oColor = vec4(edge_factor, edge_factor, edge_factor, 1.0);
......
......@@ -47,6 +47,7 @@
#include <ACG/GL/ShaderCache.hh>
#include <ACG/GL/ScreenQuad.hh>
#include <ACG/GL/GLError.hh>
#include <ACG/QtWidgets/QtColorChooserButton.hh>
#undef QT_NO_OPENGL
#include <QGLFormat>
......@@ -129,7 +130,7 @@ CelShadingModifier CelShadingModifier::instance;
// =================================================
ToonRenderer::ToonRenderer()
: progOutline_(0)
: progOutline_(0), paletteSize_(2.0f), outlineCol_(0.0f, 0.0f, 0.0f)
{
ACG::ShaderProgGenerator::registerModifier(&CelShadingModifier::instance);
}
......@@ -157,9 +158,6 @@ void ToonRenderer::render(ACG::GLState* _glState, Viewer::ViewerProperties& _pro
// - in shader: l dot n is quantized based on the number of allowed shading tones.
// currently a constant sized step function is used to quantize the intensity
// add this constant to render menu when available
const float numShades = 2.0f;
// collect renderobjects + prepare OpenGL state
prepareRenderingPipeline(_glState, _properties.drawMode(), PluginFunctions::getSceneGraphRootNode());
......@@ -214,7 +212,7 @@ void ToonRenderer::render(ACG::GLState* _glState, Viewer::ViewerProperties& _pro
prog->link();
prog->use();
prog->setUniform("g_celPaletteSize", numShades);
prog->setUniform("g_celPaletteSize", paletteSize_);
renderObject(sortedObjects_[i], prog);
}
......@@ -249,6 +247,7 @@ void ToonRenderer::render(ACG::GLState* _glState, Viewer::ViewerProperties& _pro
progOutline_->setUniform("samplerDepth", 1);
progOutline_->setUniform("texcoordOffset", ACG::Vec2f(1.0f / float(viewRes->scene_->width()), 1.0f / float(viewRes->scene_->height()) ));
progOutline_->setUniform("clipPlanes", ACG::Vec2f(_glState->near_plane(), _glState->far_plane()));
progOutline_->setUniform("outlineColor", outlineCol_);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, viewRes->scene_->getAttachment(GL_COLOR_ATTACHMENT1));
......@@ -294,11 +293,55 @@ QString ToonRenderer::checkOpenGL() {
QAction* ToonRenderer::optionsAction()
{
// QDialog* optionDlg = new QDialog(0, 0);
//
// optionDlg->show();
QAction * action = new QAction("Toon Renderer Options" , this );
connect(action,SIGNAL(triggered( bool )),this,SLOT(actionDialog( bool )));
return action;
}
void ToonRenderer::actionDialog( bool )
{
//generate widget
QDialog* optionsDlg = new QDialog();
QVBoxLayout* layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
QColor curColor;
curColor.setRgbF(outlineCol_[0],outlineCol_[1],outlineCol_[2]);
QLabel* label = new QLabel(tr("Palette Size [0, 10]:"));
layout->addWidget(label);
QSlider* paletteSizeSlider = new QSlider(Qt::Horizontal);
paletteSizeSlider->setRange(0, 1000);
paletteSizeSlider->setValue(int(paletteSize_ * 100.0));
paletteSizeSlider->setTracking(true);
layout->addWidget(paletteSizeSlider);
QtColorChooserButton* outlineColorBtn = new QtColorChooserButton("Outline Color");
layout->addWidget(outlineColorBtn);
outlineColorBtn->setColor( curColor );
optionsDlg->setLayout(layout);
connect(paletteSizeSlider, SIGNAL(sliderMoved(int)), this, SLOT(paletteSizeChanged(int)));
connect(outlineColorBtn, SIGNAL(colorChanged(QColor)), this, SLOT(outlineColorChanged(QColor)));
optionsDlg->show();
}
void ToonRenderer::paletteSizeChanged( int _val ) {
paletteSize_ = float(_val) / 100.0f;
}
return 0;
void ToonRenderer::outlineColorChanged( QColor _col ) {
outlineCol_[0] = _col.redF();
outlineCol_[1] = _col.greenF();
outlineCol_[2] = _col.blueF();
}
void ToonRenderer::ViewerResources::resize( int _newWidth, int _newHeight ) {
......
......@@ -87,6 +87,10 @@ private slots:
QString checkOpenGL();
void actionDialog( bool );
void paletteSizeChanged( int );
void outlineColorChanged( QColor );
private:
void loadShader();
......@@ -94,6 +98,12 @@ private:
/// outline shader: multiply scene color with edge factor derived from edges in depth buffer
GLSL::Program* progOutline_;
/// size of cel shading palette
float paletteSize_;
/// outline color
ACG::Vec3f outlineCol_;
/// Collection of fbos for each viewport
struct ViewerResources
{
......
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