Add a toon shading option box to Preferences Widget [skip ci]
parent
63cbfa83a5
commit
62e411d4e5
|
@ -135,6 +135,9 @@ include(thirdparty/qtsingleapplication/src/qtsingleapplication.pri)
|
||||||
|
|
||||||
INCLUDEPATH += src
|
INCLUDEPATH += src
|
||||||
|
|
||||||
|
SOURCES += src/toonline.cpp
|
||||||
|
HEADERS += src/toonline.h
|
||||||
|
|
||||||
SOURCES += src/meshstroketifier.cpp
|
SOURCES += src/meshstroketifier.cpp
|
||||||
HEADERS += src/meshstroketifier.h
|
HEADERS += src/meshstroketifier.h
|
||||||
|
|
||||||
|
|
|
@ -537,11 +537,13 @@ vec4 metalRoughFunction(const in vec4 baseColor,
|
||||||
else
|
else
|
||||||
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1));
|
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1));
|
||||||
|
|
||||||
if (toonEdgeEnabled == 1) {
|
if (toonEdgeEnabled > 0) {
|
||||||
float depthEdge = depthEdgeSobel();
|
float depthEdge = depthEdgeSobel();
|
||||||
float normalEdge = normalEdgeSobel();
|
float normalEdge = normalEdgeSobel();
|
||||||
if (depthEdge >= 0.009 || normalEdge >= 0.6) {
|
if (depthEdge >= 0.009 || normalEdge >= 0.6) {
|
||||||
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.02));
|
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.02));
|
||||||
|
} else if (toonEdgeEnabled == 2) {
|
||||||
|
return vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -425,11 +425,13 @@ vec4 metalRoughFunction(const in vec4 baseColor,
|
||||||
else
|
else
|
||||||
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1));
|
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1));
|
||||||
|
|
||||||
if (toonEdgeEnabled == 1) {
|
if (toonEdgeEnabled > 0) {
|
||||||
float depthEdge = depthEdgeSobel();
|
float depthEdge = depthEdgeSobel();
|
||||||
float normalEdge = normalEdgeSobel();
|
float normalEdge = normalEdgeSobel();
|
||||||
if (depthEdge >= 0.009 || normalEdge >= 0.6) {
|
if (depthEdge >= 0.009 || normalEdge >= 0.6) {
|
||||||
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.02));
|
cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.02));
|
||||||
|
} else if (toonEdgeEnabled == 2) {
|
||||||
|
return vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2135,7 +2135,8 @@ void DocumentWindow::delayedGenerateNormalAndDepthMaps()
|
||||||
{
|
{
|
||||||
if (!Preferences::instance().toonShading())
|
if (!Preferences::instance().toonShading())
|
||||||
return;
|
return;
|
||||||
|
if (ToonLine::WithoutLine == Preferences::instance().toonLine())
|
||||||
|
return;
|
||||||
generateNormalAndDepthMaps();
|
generateNormalAndDepthMaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QSurfaceFormat>
|
#include <QSurfaceFormat>
|
||||||
#include "modelmeshbinder.h"
|
#include "modelmeshbinder.h"
|
||||||
#include "ddsfile.h"
|
#include "ddsfile.h"
|
||||||
|
#include "preferences.h"
|
||||||
|
|
||||||
ModelMeshBinder::ModelMeshBinder(bool toolEnabled) :
|
ModelMeshBinder::ModelMeshBinder(bool toolEnabled) :
|
||||||
m_toolEnabled(toolEnabled)
|
m_toolEnabled(toolEnabled)
|
||||||
|
@ -321,7 +322,7 @@ void ModelMeshBinder::paint(ModelShaderProgram *program)
|
||||||
if (nullptr != m_toonNormalMap && nullptr != m_toonDepthMap) {
|
if (nullptr != m_toonNormalMap && nullptr != m_toonDepthMap) {
|
||||||
m_toonNormalMap->bind(5);
|
m_toonNormalMap->bind(5);
|
||||||
m_toonDepthMap->bind(6);
|
m_toonDepthMap->bind(6);
|
||||||
program->setUniformValue(program->toonEdgeEnabledLoc(), 1);
|
program->setUniformValue(program->toonEdgeEnabledLoc(), (int)Preferences::instance().toonLine());
|
||||||
}
|
}
|
||||||
f->glDrawArrays(GL_TRIANGLES, 0, m_renderTriangleVertexCount);
|
f->glDrawArrays(GL_TRIANGLES, 0, m_renderTriangleVertexCount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,7 +180,9 @@ QImage ModelOffscreenRender::toImage(const QSize &size)
|
||||||
qDebug() << "bindDefault end";
|
qDebug() << "bindDefault end";
|
||||||
delete renderFbo;
|
delete renderFbo;
|
||||||
|
|
||||||
|
qDebug() << "doneCurrent begin...";
|
||||||
m_context->doneCurrent();
|
m_context->doneCurrent();
|
||||||
|
qDebug() << "doneCurrent end";
|
||||||
delete m_context;
|
delete m_context;
|
||||||
m_context = nullptr;
|
m_context = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ ModelWidget::ModelWidget(QWidget *parent) :
|
||||||
zoom(200);
|
zoom(200);
|
||||||
|
|
||||||
connect(&Preferences::instance(), &Preferences::toonShadingChanged, this, &ModelWidget::reRender);
|
connect(&Preferences::instance(), &Preferences::toonShadingChanged, this, &ModelWidget::reRender);
|
||||||
|
connect(&Preferences::instance(), &Preferences::toonLineChanged, this, &ModelWidget::reRender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelWidget::reRender()
|
void ModelWidget::reRender()
|
||||||
|
|
|
@ -47,8 +47,13 @@ NormalAndDepthMapsGenerator::~NormalAndDepthMapsGenerator()
|
||||||
|
|
||||||
void NormalAndDepthMapsGenerator::generate()
|
void NormalAndDepthMapsGenerator::generate()
|
||||||
{
|
{
|
||||||
|
qDebug() << "Normap map generation begin...";
|
||||||
m_normalMap = new QImage(m_normalMapRender->toImage(m_viewPortSize));
|
m_normalMap = new QImage(m_normalMapRender->toImage(m_viewPortSize));
|
||||||
|
qDebug() << "Normap map generation done";
|
||||||
|
|
||||||
|
qDebug() << "Depth map generation begin...";
|
||||||
m_depthMap = new QImage(m_depthMapRender->toImage(m_viewPortSize));
|
m_depthMap = new QImage(m_depthMapRender->toImage(m_viewPortSize));
|
||||||
|
qDebug() << "Depth map generation done";
|
||||||
}
|
}
|
||||||
|
|
||||||
void NormalAndDepthMapsGenerator::process()
|
void NormalAndDepthMapsGenerator::process()
|
||||||
|
|
|
@ -16,6 +16,7 @@ void Preferences::loadDefault()
|
||||||
m_partColor = Qt::white;
|
m_partColor = Qt::white;
|
||||||
m_flatShading = false;
|
m_flatShading = false;
|
||||||
m_toonShading = false;
|
m_toonShading = false;
|
||||||
|
m_toonLine = ToonLine::WithoutLine;
|
||||||
m_textureSize = 1024;
|
m_textureSize = 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +47,11 @@ Preferences::Preferences()
|
||||||
else
|
else
|
||||||
m_toonShading = isTrueValueString(value);
|
m_toonShading = isTrueValueString(value);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
QString value = m_settings.value("toonLine").toString();
|
||||||
|
if (!value.isEmpty())
|
||||||
|
m_toonLine = ToonLineFromString(value.toUtf8().constData());
|
||||||
|
}
|
||||||
{
|
{
|
||||||
QString value = m_settings.value("textureSize").toString();
|
QString value = m_settings.value("textureSize").toString();
|
||||||
if (!value.isEmpty())
|
if (!value.isEmpty())
|
||||||
|
@ -73,6 +79,11 @@ bool Preferences::toonShading() const
|
||||||
return m_toonShading;
|
return m_toonShading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToonLine Preferences::toonLine() const
|
||||||
|
{
|
||||||
|
return m_toonLine;
|
||||||
|
}
|
||||||
|
|
||||||
int Preferences::textureSize() const
|
int Preferences::textureSize() const
|
||||||
{
|
{
|
||||||
return m_textureSize;
|
return m_textureSize;
|
||||||
|
@ -114,6 +125,15 @@ void Preferences::setToonShading(bool toonShading)
|
||||||
emit toonShadingChanged();
|
emit toonShadingChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preferences::setToonLine(ToonLine toonLine)
|
||||||
|
{
|
||||||
|
if (m_toonLine == toonLine)
|
||||||
|
return;
|
||||||
|
m_toonLine = toonLine;
|
||||||
|
m_settings.setValue("toonLine", ToonLineToString(m_toonLine));
|
||||||
|
emit toonLineChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Preferences::setTextureSize(int textureSize)
|
void Preferences::setTextureSize(int textureSize)
|
||||||
{
|
{
|
||||||
if (m_textureSize == textureSize)
|
if (m_textureSize == textureSize)
|
||||||
|
@ -141,5 +161,6 @@ void Preferences::reset()
|
||||||
emit partColorChanged();
|
emit partColorChanged();
|
||||||
emit flatShadingChanged();
|
emit flatShadingChanged();
|
||||||
emit toonShadingChanged();
|
emit toonShadingChanged();
|
||||||
|
emit toonLineChanged();
|
||||||
emit textureSizeChanged();
|
emit textureSizeChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include "combinemode.h"
|
#include "combinemode.h"
|
||||||
|
#include "toonline.h"
|
||||||
|
|
||||||
class Preferences : public QObject
|
class Preferences : public QObject
|
||||||
{
|
{
|
||||||
|
@ -15,6 +16,7 @@ public:
|
||||||
const QColor &partColor() const;
|
const QColor &partColor() const;
|
||||||
bool flatShading() const;
|
bool flatShading() const;
|
||||||
bool toonShading() const;
|
bool toonShading() const;
|
||||||
|
ToonLine toonLine() const;
|
||||||
QSize documentWindowSize() const;
|
QSize documentWindowSize() const;
|
||||||
void setDocumentWindowSize(const QSize&);
|
void setDocumentWindowSize(const QSize&);
|
||||||
int textureSize() const;
|
int textureSize() const;
|
||||||
|
@ -23,12 +25,14 @@ signals:
|
||||||
void partColorChanged();
|
void partColorChanged();
|
||||||
void flatShadingChanged();
|
void flatShadingChanged();
|
||||||
void toonShadingChanged();
|
void toonShadingChanged();
|
||||||
|
void toonLineChanged();
|
||||||
void textureSizeChanged();
|
void textureSizeChanged();
|
||||||
public slots:
|
public slots:
|
||||||
void setComponentCombineMode(CombineMode mode);
|
void setComponentCombineMode(CombineMode mode);
|
||||||
void setPartColor(const QColor &color);
|
void setPartColor(const QColor &color);
|
||||||
void setFlatShading(bool flatShading);
|
void setFlatShading(bool flatShading);
|
||||||
void setToonShading(bool toonShading);
|
void setToonShading(bool toonShading);
|
||||||
|
void setToonLine(ToonLine toonLine);
|
||||||
void setTextureSize(int textureSize);
|
void setTextureSize(int textureSize);
|
||||||
void reset();
|
void reset();
|
||||||
private:
|
private:
|
||||||
|
@ -36,6 +40,7 @@ private:
|
||||||
QColor m_partColor;
|
QColor m_partColor;
|
||||||
bool m_flatShading;
|
bool m_flatShading;
|
||||||
bool m_toonShading;
|
bool m_toonShading;
|
||||||
|
ToonLine m_toonLine;
|
||||||
QSettings m_settings;
|
QSettings m_settings;
|
||||||
int m_textureSize;
|
int m_textureSize;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -71,6 +71,20 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
|
||||||
Preferences::instance().setToonShading(toonShadingBox->isChecked());
|
Preferences::instance().setToonShading(toonShadingBox->isChecked());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QComboBox *toonLineSelectBox = new QComboBox;
|
||||||
|
for (size_t i = 0; i < (size_t)ToonLine::Count; ++i) {
|
||||||
|
ToonLine toonLine = (ToonLine)i;
|
||||||
|
toonLineSelectBox->addItem(ToonLineToDispName(toonLine));
|
||||||
|
}
|
||||||
|
connect(toonLineSelectBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||||
|
Preferences::instance().setToonLine((ToonLine)index);
|
||||||
|
});
|
||||||
|
|
||||||
|
QHBoxLayout *toonShadingLayout = new QHBoxLayout;
|
||||||
|
toonShadingLayout->addWidget(toonShadingBox);
|
||||||
|
toonShadingLayout->addWidget(toonLineSelectBox);
|
||||||
|
toonShadingLayout->addStretch();
|
||||||
|
|
||||||
QComboBox *textureSizeSelectBox = new QComboBox;
|
QComboBox *textureSizeSelectBox = new QComboBox;
|
||||||
textureSizeSelectBox->addItem("512");
|
textureSizeSelectBox->addItem("512");
|
||||||
textureSizeSelectBox->addItem("1024");
|
textureSizeSelectBox->addItem("1024");
|
||||||
|
@ -84,13 +98,14 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
|
||||||
formLayout->addRow(tr("Part color:"), colorLayout);
|
formLayout->addRow(tr("Part color:"), colorLayout);
|
||||||
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
|
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
|
||||||
formLayout->addRow(tr("Flat shading:"), flatShadingBox);
|
formLayout->addRow(tr("Flat shading:"), flatShadingBox);
|
||||||
formLayout->addRow(tr("Toon shading:"), toonShadingBox);
|
formLayout->addRow(tr("Toon shading:"), toonShadingLayout);
|
||||||
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
|
formLayout->addRow(tr("Texture size:"), textureSizeSelectBox);
|
||||||
|
|
||||||
auto loadFromPreferences = [=]() {
|
auto loadFromPreferences = [=]() {
|
||||||
updatePickButtonColor();
|
updatePickButtonColor();
|
||||||
combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode());
|
combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode());
|
||||||
flatShadingBox->setChecked(Preferences::instance().flatShading());
|
flatShadingBox->setChecked(Preferences::instance().flatShading());
|
||||||
|
toonLineSelectBox->setCurrentIndex((int)Preferences::instance().toonLine());
|
||||||
toonShadingBox->setChecked(Preferences::instance().toonShading());
|
toonShadingBox->setChecked(Preferences::instance().toonShading());
|
||||||
textureSizeSelectBox->setCurrentIndex(
|
textureSizeSelectBox->setCurrentIndex(
|
||||||
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
|
textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize()))
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include <QObject>
|
||||||
|
#include "toonline.h"
|
||||||
|
|
||||||
|
IMPL_ToonLineToString
|
||||||
|
IMPL_ToonLineFromString
|
||||||
|
IMPL_ToonLineToDispName
|
|
@ -0,0 +1,57 @@
|
||||||
|
#ifndef DUST3D_TOON_LINE_H
|
||||||
|
#define DUST3D_TOON_LINE_H
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
enum class ToonLine
|
||||||
|
{
|
||||||
|
WithoutLine = 0,
|
||||||
|
WithLine,
|
||||||
|
LineOnly,
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
|
ToonLine ToonLineFromString(const char *lineString);
|
||||||
|
#define IMPL_ToonLineFromString \
|
||||||
|
ToonLine ToonLineFromString(const char *lineString) \
|
||||||
|
{ \
|
||||||
|
QString line = lineString; \
|
||||||
|
if (line == "WithoutLine") \
|
||||||
|
return ToonLine::WithoutLine; \
|
||||||
|
if (line == "WithLine") \
|
||||||
|
return ToonLine::WithLine; \
|
||||||
|
if (line == "LineOnly") \
|
||||||
|
return ToonLine::LineOnly; \
|
||||||
|
return ToonLine::WithoutLine; \
|
||||||
|
}
|
||||||
|
QString ToonLineToString(ToonLine toonLine);
|
||||||
|
#define IMPL_ToonLineToString \
|
||||||
|
QString ToonLineToString(ToonLine toonLine) \
|
||||||
|
{ \
|
||||||
|
switch (toonLine) { \
|
||||||
|
case ToonLine::WithoutLine: \
|
||||||
|
return "WithoutLine"; \
|
||||||
|
case ToonLine::WithLine: \
|
||||||
|
return "WithLine"; \
|
||||||
|
case ToonLine::LineOnly: \
|
||||||
|
return "LineOnly"; \
|
||||||
|
default: \
|
||||||
|
return ""; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
QString ToonLineToDispName(ToonLine toonLine);
|
||||||
|
#define IMPL_ToonLineToDispName \
|
||||||
|
QString ToonLineToDispName(ToonLine toonLine) \
|
||||||
|
{ \
|
||||||
|
switch (toonLine) { \
|
||||||
|
case ToonLine::WithoutLine: \
|
||||||
|
return QObject::tr("Without Line"); \
|
||||||
|
case ToonLine::WithLine: \
|
||||||
|
return QObject::tr("With Line"); \
|
||||||
|
case ToonLine::LineOnly: \
|
||||||
|
return QObject::tr("Line Only"); \
|
||||||
|
default: \
|
||||||
|
return QObject::tr("Without Line"); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue