From c0db22b2008c0d4bc255304e8e3ff32072d70618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sat, 2 Jun 2012 14:17:01 +0000 Subject: [PATCH] paysages : Finished material dialog + several improvements. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@333 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 3 +- gui_qt/basepreview.cpp | 26 +++++---- gui_qt/dialogmaterial.cpp | 4 +- gui_qt/dialogmaterial.h | 3 +- gui_qt/dialognoise.cpp | 2 +- gui_qt/dialognoise.h | 4 +- gui_qt/formmaterial.cpp | 25 +------- gui_qt/formrender.cpp | 2 +- gui_qt/formterrain.cpp | 4 +- gui_qt/formwater.cpp | 8 ++- gui_qt/inputmaterial.cpp | 37 +----------- gui_qt/previewmaterial.cpp | 116 +++++++++++++++++++++++++++++++++++++ gui_qt/previewmaterial.h | 41 +++++++++++++ gui_qt/tools.cpp | 18 ++++++ gui_qt/tools.h | 11 ++++ i18n/paysages_fr.ts | 36 ++++++------ 16 files changed, 239 insertions(+), 101 deletions(-) create mode 100644 gui_qt/previewmaterial.cpp create mode 100644 gui_qt/previewmaterial.h create mode 100644 gui_qt/tools.cpp diff --git a/TODO b/TODO index 13178d1..f912237 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,5 @@ Technology Preview 2 : - Fix the fog impression when cloud layer overlaps with ground range. -- Fix dialog previews not always updating at dialog open. - Fix forms with layers apply and revert buttons (when deleting last cloud layer, can't apply it). - Replace zone ranges with curves (with curve input and curve dialog). - Interface for textures thickness, slope_range and thickness_transparency (and correct slider ranges). @@ -11,7 +10,6 @@ Technology Preview 2 : - Add logarithmic sliders for some float values. - Save GUI config (views, render params). - Add an OSD ability on previews and use it for camera location and user landmarks. -- WIP : Add a material editor dialog. - Add a zone editor dialog for localized textures. - Add a terrain modifier dialog with zones. - Use the curve editor in noise editor @@ -49,6 +47,7 @@ Technology Preview 3 : - Multi threaded first pass. - Fix potential holes in land rendering. - Progressive final render. +- Propose several backgrounds for water rendering (grid, sinus...). - If we can't remove clouds artifacts, blur them. Release Candidate : diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index 32306ee..0f26635 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -24,6 +24,11 @@ public: _alive = true; } + inline bool isOnFront() + { + return _preview->isVisible() && _preview->window()->isActiveWindow(); + } + bool isFrom(BasePreview* preview) { return _preview == preview; @@ -46,11 +51,7 @@ public: if (_need_render) { - if (!_preview->isVisible()) - { - return false; - } - if (!_preview->window()->isActiveWindow()) + if (!isOnFront()) { return false; } @@ -209,13 +210,16 @@ void PreviewDrawingManager::updateAllChunks() { PreviewChunk* chunk; chunk = _chunks.at(i); - chunk->update(); - _lock.lock(); - if (!_updateQueue.contains(chunk)) - { - _updateQueue.prepend(chunk); + if (chunk->isOnFront()) + { + chunk->update(); + _lock.lock(); + if (!_updateQueue.contains(chunk)) + { + _updateQueue.prepend(chunk); + } + _lock.unlock(); } - _lock.unlock(); } } diff --git a/gui_qt/dialogmaterial.cpp b/gui_qt/dialogmaterial.cpp index fb3f8cb..38563d2 100644 --- a/gui_qt/dialogmaterial.cpp +++ b/gui_qt/dialogmaterial.cpp @@ -6,7 +6,7 @@ #include /**************** Dialog form ****************/ -DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : QDialog(parent) +DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : DialogWithPreview(parent) { QPushButton* button; QWidget* buttons; @@ -16,7 +16,7 @@ DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : QDi _form = new FormMaterial(this, material); _form->hideButtons(); layout()->addWidget(_form); - + buttons = new QWidget(this); buttons->setLayout(new QHBoxLayout()); layout()->addWidget(buttons); diff --git a/gui_qt/dialogmaterial.h b/gui_qt/dialogmaterial.h index 83f6519..5d47dd2 100644 --- a/gui_qt/dialogmaterial.h +++ b/gui_qt/dialogmaterial.h @@ -5,10 +5,11 @@ #include #include "basepreview.h" #include "formmaterial.h" +#include "tools.h" #include "../lib_paysages/shared/types.h" -class DialogMaterial : public QDialog +class DialogMaterial : public DialogWithPreview { Q_OBJECT public: diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index 4aa17ed..6906c57 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -82,7 +82,7 @@ private: /**************** Dialog form ****************/ DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value): - QDialog(parent) + DialogWithPreview(parent) { QWidget* previews; QWidget* form; diff --git a/gui_qt/dialognoise.h b/gui_qt/dialognoise.h index a6192ce..beccea3 100644 --- a/gui_qt/dialognoise.h +++ b/gui_qt/dialognoise.h @@ -1,13 +1,13 @@ #ifndef _PAYSAGES_QT_DIALOGNOISE_H_ #define _PAYSAGES_QT_DIALOGNOISE_H_ -#include #include #include "basepreview.h" +#include "tools.h" #include "../lib_paysages/noise.h" -class DialogNoise : public QDialog +class DialogNoise : public DialogWithPreview { Q_OBJECT public: diff --git a/gui_qt/formmaterial.cpp b/gui_qt/formmaterial.cpp index fc157ac..16a77f1 100644 --- a/gui_qt/formmaterial.cpp +++ b/gui_qt/formmaterial.cpp @@ -1,27 +1,6 @@ #include "formmaterial.h" -#include "../lib_paysages/lighting.h" - -/**************** Previews ****************/ -class PreviewMaterialColor:public BasePreview -{ -public: - PreviewMaterialColor(QWidget* parent, SurfaceMaterial* material) : BasePreview(parent) - { - configScaling(0.05, 2.0, 0.05, 2.0); - } -protected: - /*void updateData() - { - noiseCopy(_noise_original, _noise_preview); - }*/ - QColor getColor(double x, double y) - { - return QColor(0, 0, 0); - } -private: - SurfaceMaterial* _material; -}; +#include "previewmaterial.h" /**************** Form ****************/ FormMaterial::FormMaterial(QWidget* parent, SurfaceMaterial* material) : BaseForm(parent) @@ -33,7 +12,7 @@ FormMaterial::FormMaterial(QWidget* parent, SurfaceMaterial* material) : BaseFor addInputDouble(tr("Light reflection"), &_material.reflection, 0.0, 1.0, 0.01, 0.1); addInputDouble(tr("Light reflection shininess"), &_material.shininess, 0.0, 20.0, 0.1, 1.0); - _preview_color = new PreviewMaterialColor(this, &_material); + _preview_color = new PreviewMaterial(this, &_material); addPreview(_preview_color, tr("Lighting preview")); revertConfig(); diff --git a/gui_qt/formrender.cpp b/gui_qt/formrender.cpp index 5b1cd88..6a96bb0 100644 --- a/gui_qt/formrender.cpp +++ b/gui_qt/formrender.cpp @@ -33,7 +33,7 @@ public: _renderer.customData[2] = &_lighting; _renderer.customData[3] = &_water; - configScaling(0.5, 200.0, 1.0, 50.0); + configScaling(0.5, 200.0, 3.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 52711a4..4743162 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -19,7 +19,7 @@ public: { _preview_definition = terrainCreateDefinition(); - configScaling(0.5, 200.0, 1.0, 50.0); + configScaling(0.5, 200.0, 3.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: @@ -96,7 +96,7 @@ public: _renderer.customData[1] = &_textures; _renderer.customData[2] = &_lighting; - configScaling(0.5, 200.0, 1.0, 50.0); + configScaling(0.5, 200.0, 3.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: diff --git a/gui_qt/formwater.cpp b/gui_qt/formwater.cpp index 2e996e0..015ddaa 100644 --- a/gui_qt/formwater.cpp +++ b/gui_qt/formwater.cpp @@ -24,7 +24,7 @@ public: _water = waterCreateDefinition(); _terrain = terrainCreateDefinition(); - configScaling(0.5, 200.0, 1.0, 50.0); + configScaling(0.5, 200.0, 3.0, 50.0); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); } protected: @@ -81,6 +81,7 @@ public: _renderer.customData[1] = &_lighting; configScaling(10.0, 1000.0, 10.0, 250.0); + //configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0); } protected: QColor getColor(double x, double y) @@ -138,13 +139,14 @@ private: x = location.x + direction.x * (0.0 - location.z) / direction.z; y = location.y + direction.y * (0.0 - location.z) / direction.z; - if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0)) + //if (((int)ceil(x * 0.2) % 2 == 0) ^ ((int)ceil(y * 0.2 - 0.5) % 2 == 0)) + if (y * 0.1 > sin(x - M_PI_2)) { result.hit_color = COLOR_WHITE; } else { - result.hit_color = COLOR_GREY; + result.hit_color = COLOR_BLACK; } result.hit_location.x = x; result.hit_location.y = y; diff --git a/gui_qt/inputmaterial.cpp b/gui_qt/inputmaterial.cpp index a597c03..899c172 100644 --- a/gui_qt/inputmaterial.cpp +++ b/gui_qt/inputmaterial.cpp @@ -5,46 +5,13 @@ #include #include #include "dialogmaterial.h" - -class MaterialSmallPreview:public QWidget -{ -public: - MaterialSmallPreview(QWidget* parent, SurfaceMaterial* value) : QWidget(parent) - { - _value = value; - } - - void paintEvent(QPaintEvent* event) - { - if (!_value) - { - return; - } - - /*QPainter painter(this); - int width = this->width(); - int height = this->height(); - double value, factor; - - for (int x = 0; x < width; x++) - { - factor = ((double)(height / 2)) / noiseGetMaxValue(noise); - value = noiseGet1DTotal(noise, ((double)x) / factor) * factor; - painter.setPen(QColor(255, 255, 255)); - painter.drawLine(x, 0, x, height / 2 + value); - painter.setPen(QColor(0, 0, 0)); - painter.drawLine(x, height / 2 + value + 1, x, height); - }*/ - } - - SurfaceMaterial* _value; -}; +#include "previewmaterial.h" InputMaterial::InputMaterial(QWidget* form, QString label, SurfaceMaterial* value) : BaseInput(form, label) { _value = value; - _preview = new MaterialSmallPreview(form, value); + _preview = new SmallMaterialPreview(form, value); _preview->setMinimumSize(100, 40); _control = new QPushButton(tr("Edit"), form); diff --git a/gui_qt/previewmaterial.cpp b/gui_qt/previewmaterial.cpp new file mode 100644 index 0000000..1ebaeac --- /dev/null +++ b/gui_qt/previewmaterial.cpp @@ -0,0 +1,116 @@ +#include "previewmaterial.h" + +#include +#include +#include "tools.h" + +#include "../lib_paysages/lighting.h" +#include "../lib_paysages/color.h" + +/***** Small static preview *****/ + +SmallMaterialPreview::SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material) : QWidget(parent) +{ + LightDefinition light; + + _lighting = lightingCreateDefinition(); + light.color = COLOR_WHITE; + light.amplitude = 0.0; + light.direction.x = -0.5; + light.direction.y = -0.5; + light.direction.z = -0.5; + light.direction = v3Normalize(light.direction); + light.filtered = 0; + light.masked = 0; + light.reflection = 1.0; + lightingAddLight(&_lighting, light); + lightingValidateDefinition(&_lighting); + + _material = material; + + _renderer = rendererCreate(); + _renderer.camera_location.x = 0.0; + _renderer.camera_location.x = 0.0; + _renderer.camera_location.z = 10.0; +} + +SmallMaterialPreview::~SmallMaterialPreview() +{ + rendererDelete(&_renderer); +} + +QColor SmallMaterialPreview::getColor(double x, double y) +{ + double dist = sqrt(x * x + y * y); + Vector3 point; + + if (dist > 1.0) + { + return colorToQColor(COLOR_TRANSPARENT); + } + else + { + point.x = x; + point.y = -y; + if (dist == 0) + { + point.z = 1.0; + } + else + { + point.z = fabs(acos(dist)); + } + + point = v3Normalize(point); + + return colorToQColor(lightingApplyToSurface(&_lighting, &_renderer, point, point, *_material)); + } +} + +void SmallMaterialPreview::paintEvent(QPaintEvent* event) +{ + QPainter painter(this); + int width = this->width(); + int height = this->height(); + double factor, dx, dy; + + if (width > height) + { + factor = 2.0 / (double)height; + } + else + { + factor = 2.0 / (double)width; + } + dx = factor * (double)width / 2.0; + dy = factor * (double)height / 2.0; + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy)); + painter.drawPoint(x, y); + } + } +} + +/***** Large dynamic preview *****/ + +PreviewMaterial::PreviewMaterial(QWidget* parent, SurfaceMaterial* material) : BasePreview(parent) +{ + _small = new SmallMaterialPreview(this, material); + _small->hide(); + + configScaling(0.05, 2.0, 0.05, 2.0); +} + +PreviewMaterial::~PreviewMaterial() +{ + delete _small; +} + +QColor PreviewMaterial::getColor(double x, double y) +{ + return _small->getColor(x, y); +} diff --git a/gui_qt/previewmaterial.h b/gui_qt/previewmaterial.h new file mode 100644 index 0000000..e4dadda --- /dev/null +++ b/gui_qt/previewmaterial.h @@ -0,0 +1,41 @@ +#ifndef _PAYSAGES_QT_PREVIEWMATERIAL_H_ +#define _PAYSAGES_QT_PREVIEWMATERIAL_H_ + +#include "basepreview.h" + +#include "../lib_paysages/lighting.h" +#include "../lib_paysages/renderer.h" + +class SmallMaterialPreview:public QWidget +{ +public: + SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material); + ~SmallMaterialPreview(); + + QColor getColor(double x, double y); + +protected: + virtual void paintEvent(QPaintEvent* event); + +private: + SurfaceMaterial* _material; + LightingDefinition _lighting; + Renderer _renderer; +}; + +class PreviewMaterial:public BasePreview +{ + Q_OBJECT + +public: + PreviewMaterial(QWidget* parent, SurfaceMaterial* material); + ~PreviewMaterial(); + +protected: + virtual QColor getColor(double x, double y); + +private: + SmallMaterialPreview* _small; +}; + +#endif diff --git a/gui_qt/tools.cpp b/gui_qt/tools.cpp new file mode 100644 index 0000000..4136d0e --- /dev/null +++ b/gui_qt/tools.cpp @@ -0,0 +1,18 @@ +#include "tools.h" + +#include +#include "basepreview.h" + +DialogWithPreview::DialogWithPreview(QWidget* parent) : QDialog(parent) +{ +} + +bool DialogWithPreview::event(QEvent* event) +{ + if (event->type() == QEvent::WindowActivate) + { + BasePreview::reviveAll(); + } + + return QDialog::event(event); +} diff --git a/gui_qt/tools.h b/gui_qt/tools.h index 270442f..0b37208 100644 --- a/gui_qt/tools.h +++ b/gui_qt/tools.h @@ -2,6 +2,7 @@ #define _PAYSAGES_QT_TOOLS_H_ #include +#include #include "../lib_paysages/shared/types.h" #include "../lib_paysages/color.h" @@ -12,6 +13,16 @@ static inline QColor colorToQColor(Color color) return QColor(color.r * 255.0, color.g * 255.0, color.b * 255.0, color.a * 255.0); } +class DialogWithPreview:public QDialog +{ + Q_OBJECT +public: + DialogWithPreview(QWidget* parent); + +protected: + virtual bool event(QEvent* event); +}; + #ifndef NDEBUG #include static inline void logDebug(QString string) diff --git a/i18n/paysages_fr.ts b/i18n/paysages_fr.ts index 0e00320..5fdd80f 100644 --- a/i18n/paysages_fr.ts +++ b/i18n/paysages_fr.ts @@ -426,22 +426,22 @@ Maintenir Ctrl : Plus rapide FormMaterial - + Base color Couleur de base - + Light reflection - + Light reflection shininess - + Lighting preview @@ -689,17 +689,17 @@ Maintenir Ctrl : Plus rapide FormWater - + Coverage preview Aperçu de la couverture - + Rendered preview (without/with lighting) Aperçu du rendu (sans/avec éclairage) - + Height Hauteur @@ -716,47 +716,47 @@ Maintenir Ctrl : Plus rapide Concentration de la lumière réfléchie - + Surface material - + Transparency Transparence - + Reflection Reflets - + Transparency distance Distance maximale de transparence - + Depth color Couleur en profondeur - + Light-through distance Distance de filtrage de la lumière - + Waves noise Bruit des vagues - + Waves height Hauteur des vagues - + Waves scaling Echelle des vagues @@ -809,7 +809,7 @@ Maintenir Ctrl : Plus rapide InputMaterial - + Edit Editer @@ -916,7 +916,7 @@ rapide (F5) Do you want to load a scenery from file ? Any unsaved changes will be lost. - Voulez-vous charger une scène ? Les modifications nons sauvegardées seront perdues. + Voulez-vous charger une scène ? Les modifications non sauvegardées seront perdues.