diff --git a/dust3d.pro b/dust3d.pro index 8a52a1c3..ab302d23 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -135,6 +135,9 @@ include(thirdparty/qtsingleapplication/src/qtsingleapplication.pri) INCLUDEPATH += src +SOURCES += src/toonline.cpp +HEADERS += src/toonline.h + SOURCES += src/meshstroketifier.cpp HEADERS += src/meshstroketifier.h diff --git a/shaders/default.core.frag b/shaders/default.core.frag index 6a1e6800..cdd985f6 100644 --- a/shaders/default.core.frag +++ b/shaders/default.core.frag @@ -537,11 +537,13 @@ vec4 metalRoughFunction(const in vec4 baseColor, else cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1)); - if (toonEdgeEnabled == 1) { + if (toonEdgeEnabled > 0) { float depthEdge = depthEdgeSobel(); float normalEdge = normalEdgeSobel(); if (depthEdge >= 0.009 || normalEdge >= 0.6) { 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); } } } diff --git a/shaders/default.frag b/shaders/default.frag index 162bf6d7..7bf85e6b 100644 --- a/shaders/default.frag +++ b/shaders/default.frag @@ -425,11 +425,13 @@ vec4 metalRoughFunction(const in vec4 baseColor, else cLinear = hsv2rgb(vec3(hsv.r, hsv.g, hsv.b * 0.1)); - if (toonEdgeEnabled == 1) { + if (toonEdgeEnabled > 0) { float depthEdge = depthEdgeSobel(); float normalEdge = normalEdgeSobel(); if (depthEdge >= 0.009 || normalEdge >= 0.6) { 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); } } } diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index 9046e1b3..566344d9 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -2135,7 +2135,8 @@ void DocumentWindow::delayedGenerateNormalAndDepthMaps() { if (!Preferences::instance().toonShading()) return; - + if (ToonLine::WithoutLine == Preferences::instance().toonLine()) + return; generateNormalAndDepthMaps(); } diff --git a/src/modelmeshbinder.cpp b/src/modelmeshbinder.cpp index 3a83dbe9..f4acf7eb 100644 --- a/src/modelmeshbinder.cpp +++ b/src/modelmeshbinder.cpp @@ -8,6 +8,7 @@ #include #include "modelmeshbinder.h" #include "ddsfile.h" +#include "preferences.h" ModelMeshBinder::ModelMeshBinder(bool toolEnabled) : m_toolEnabled(toolEnabled) @@ -321,7 +322,7 @@ void ModelMeshBinder::paint(ModelShaderProgram *program) if (nullptr != m_toonNormalMap && nullptr != m_toonDepthMap) { m_toonNormalMap->bind(5); m_toonDepthMap->bind(6); - program->setUniformValue(program->toonEdgeEnabledLoc(), 1); + program->setUniformValue(program->toonEdgeEnabledLoc(), (int)Preferences::instance().toonLine()); } f->glDrawArrays(GL_TRIANGLES, 0, m_renderTriangleVertexCount); } diff --git a/src/modeloffscreenrender.cpp b/src/modeloffscreenrender.cpp index 1cd21105..810e8ff5 100644 --- a/src/modeloffscreenrender.cpp +++ b/src/modeloffscreenrender.cpp @@ -180,7 +180,9 @@ QImage ModelOffscreenRender::toImage(const QSize &size) qDebug() << "bindDefault end"; delete renderFbo; + qDebug() << "doneCurrent begin..."; m_context->doneCurrent(); + qDebug() << "doneCurrent end"; delete m_context; m_context = nullptr; diff --git a/src/modelwidget.cpp b/src/modelwidget.cpp index 20bc4dc4..b7f22b87 100644 --- a/src/modelwidget.cpp +++ b/src/modelwidget.cpp @@ -53,6 +53,7 @@ ModelWidget::ModelWidget(QWidget *parent) : zoom(200); connect(&Preferences::instance(), &Preferences::toonShadingChanged, this, &ModelWidget::reRender); + connect(&Preferences::instance(), &Preferences::toonLineChanged, this, &ModelWidget::reRender); } void ModelWidget::reRender() diff --git a/src/normalanddepthmapsgenerator.cpp b/src/normalanddepthmapsgenerator.cpp index bfdb12f9..87c30363 100644 --- a/src/normalanddepthmapsgenerator.cpp +++ b/src/normalanddepthmapsgenerator.cpp @@ -47,8 +47,13 @@ NormalAndDepthMapsGenerator::~NormalAndDepthMapsGenerator() void NormalAndDepthMapsGenerator::generate() { + qDebug() << "Normap map generation begin..."; 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)); + qDebug() << "Depth map generation done"; } void NormalAndDepthMapsGenerator::process() diff --git a/src/preferences.cpp b/src/preferences.cpp index 3facd8ff..77cee31f 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -16,6 +16,7 @@ void Preferences::loadDefault() m_partColor = Qt::white; m_flatShading = false; m_toonShading = false; + m_toonLine = ToonLine::WithoutLine; m_textureSize = 1024; } @@ -46,6 +47,11 @@ Preferences::Preferences() else 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(); if (!value.isEmpty()) @@ -73,6 +79,11 @@ bool Preferences::toonShading() const return m_toonShading; } +ToonLine Preferences::toonLine() const +{ + return m_toonLine; +} + int Preferences::textureSize() const { return m_textureSize; @@ -114,6 +125,15 @@ void Preferences::setToonShading(bool toonShading) 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) { if (m_textureSize == textureSize) @@ -141,5 +161,6 @@ void Preferences::reset() emit partColorChanged(); emit flatShadingChanged(); emit toonShadingChanged(); + emit toonLineChanged(); emit textureSizeChanged(); } diff --git a/src/preferences.h b/src/preferences.h index cb360700..52e762ae 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -4,6 +4,7 @@ #include #include #include "combinemode.h" +#include "toonline.h" class Preferences : public QObject { @@ -15,6 +16,7 @@ public: const QColor &partColor() const; bool flatShading() const; bool toonShading() const; + ToonLine toonLine() const; QSize documentWindowSize() const; void setDocumentWindowSize(const QSize&); int textureSize() const; @@ -23,12 +25,14 @@ signals: void partColorChanged(); void flatShadingChanged(); void toonShadingChanged(); + void toonLineChanged(); void textureSizeChanged(); public slots: void setComponentCombineMode(CombineMode mode); void setPartColor(const QColor &color); void setFlatShading(bool flatShading); void setToonShading(bool toonShading); + void setToonLine(ToonLine toonLine); void setTextureSize(int textureSize); void reset(); private: @@ -36,6 +40,7 @@ private: QColor m_partColor; bool m_flatShading; bool m_toonShading; + ToonLine m_toonLine; QSettings m_settings; int m_textureSize; private: diff --git a/src/preferenceswidget.cpp b/src/preferenceswidget.cpp index 42c020e7..efd8907b 100644 --- a/src/preferenceswidget.cpp +++ b/src/preferenceswidget.cpp @@ -71,6 +71,20 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent) 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(&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; textureSizeSelectBox->addItem("512"); textureSizeSelectBox->addItem("1024"); @@ -84,13 +98,14 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent) formLayout->addRow(tr("Part color:"), colorLayout); formLayout->addRow(tr("Combine mode:"), combineModeSelectBox); formLayout->addRow(tr("Flat shading:"), flatShadingBox); - formLayout->addRow(tr("Toon shading:"), toonShadingBox); + formLayout->addRow(tr("Toon shading:"), toonShadingLayout); formLayout->addRow(tr("Texture size:"), textureSizeSelectBox); auto loadFromPreferences = [=]() { updatePickButtonColor(); combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode()); flatShadingBox->setChecked(Preferences::instance().flatShading()); + toonLineSelectBox->setCurrentIndex((int)Preferences::instance().toonLine()); toonShadingBox->setChecked(Preferences::instance().toonShading()); textureSizeSelectBox->setCurrentIndex( textureSizeSelectBox->findText(QString::number(Preferences::instance().textureSize())) diff --git a/src/toonline.cpp b/src/toonline.cpp new file mode 100644 index 00000000..c41cec98 --- /dev/null +++ b/src/toonline.cpp @@ -0,0 +1,6 @@ +#include +#include "toonline.h" + +IMPL_ToonLineToString +IMPL_ToonLineFromString +IMPL_ToonLineToDispName \ No newline at end of file diff --git a/src/toonline.h b/src/toonline.h new file mode 100644 index 00000000..e17fc7de --- /dev/null +++ b/src/toonline.h @@ -0,0 +1,57 @@ +#ifndef DUST3D_TOON_LINE_H +#define DUST3D_TOON_LINE_H +#include + +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