paysages : Finished material dialog + several improvements.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@333 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-06-02 14:17:01 +00:00 committed by ThunderK
parent d204a2c294
commit c0db22b200
16 changed files with 239 additions and 101 deletions

3
TODO
View file

@ -1,6 +1,5 @@
Technology Preview 2 : Technology Preview 2 :
- Fix the fog impression when cloud layer overlaps with ground range. - 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). - 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). - Replace zone ranges with curves (with curve input and curve dialog).
- Interface for textures thickness, slope_range and thickness_transparency (and correct slider ranges). - 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. - Add logarithmic sliders for some float values.
- Save GUI config (views, render params). - Save GUI config (views, render params).
- Add an OSD ability on previews and use it for camera location and user landmarks. - 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 zone editor dialog for localized textures.
- Add a terrain modifier dialog with zones. - Add a terrain modifier dialog with zones.
- Use the curve editor in noise editor - Use the curve editor in noise editor
@ -49,6 +47,7 @@ Technology Preview 3 :
- Multi threaded first pass. - Multi threaded first pass.
- Fix potential holes in land rendering. - Fix potential holes in land rendering.
- Progressive final render. - Progressive final render.
- Propose several backgrounds for water rendering (grid, sinus...).
- If we can't remove clouds artifacts, blur them. - If we can't remove clouds artifacts, blur them.
Release Candidate : Release Candidate :

View file

@ -24,6 +24,11 @@ public:
_alive = true; _alive = true;
} }
inline bool isOnFront()
{
return _preview->isVisible() && _preview->window()->isActiveWindow();
}
bool isFrom(BasePreview* preview) bool isFrom(BasePreview* preview)
{ {
return _preview == preview; return _preview == preview;
@ -46,11 +51,7 @@ public:
if (_need_render) if (_need_render)
{ {
if (!_preview->isVisible()) if (!isOnFront())
{
return false;
}
if (!_preview->window()->isActiveWindow())
{ {
return false; return false;
} }
@ -209,6 +210,8 @@ void PreviewDrawingManager::updateAllChunks()
{ {
PreviewChunk* chunk; PreviewChunk* chunk;
chunk = _chunks.at(i); chunk = _chunks.at(i);
if (chunk->isOnFront())
{
chunk->update(); chunk->update();
_lock.lock(); _lock.lock();
if (!_updateQueue.contains(chunk)) if (!_updateQueue.contains(chunk))
@ -218,6 +221,7 @@ void PreviewDrawingManager::updateAllChunks()
_lock.unlock(); _lock.unlock();
} }
} }
}
void PreviewDrawingManager::performOneThreadJob() void PreviewDrawingManager::performOneThreadJob()
{ {

View file

@ -6,7 +6,7 @@
#include <QWidget> #include <QWidget>
/**************** Dialog form ****************/ /**************** Dialog form ****************/
DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : QDialog(parent) DialogMaterial::DialogMaterial(QWidget *parent, SurfaceMaterial* material) : DialogWithPreview(parent)
{ {
QPushButton* button; QPushButton* button;
QWidget* buttons; QWidget* buttons;

View file

@ -5,10 +5,11 @@
#include <QListWidget> #include <QListWidget>
#include "basepreview.h" #include "basepreview.h"
#include "formmaterial.h" #include "formmaterial.h"
#include "tools.h"
#include "../lib_paysages/shared/types.h" #include "../lib_paysages/shared/types.h"
class DialogMaterial : public QDialog class DialogMaterial : public DialogWithPreview
{ {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -82,7 +82,7 @@ private:
/**************** Dialog form ****************/ /**************** Dialog form ****************/
DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value): DialogNoise::DialogNoise(QWidget *parent, NoiseGenerator* value):
QDialog(parent) DialogWithPreview(parent)
{ {
QWidget* previews; QWidget* previews;
QWidget* form; QWidget* form;

View file

@ -1,13 +1,13 @@
#ifndef _PAYSAGES_QT_DIALOGNOISE_H_ #ifndef _PAYSAGES_QT_DIALOGNOISE_H_
#define _PAYSAGES_QT_DIALOGNOISE_H_ #define _PAYSAGES_QT_DIALOGNOISE_H_
#include <QDialog>
#include <QListWidget> #include <QListWidget>
#include "basepreview.h" #include "basepreview.h"
#include "tools.h"
#include "../lib_paysages/noise.h" #include "../lib_paysages/noise.h"
class DialogNoise : public QDialog class DialogNoise : public DialogWithPreview
{ {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -1,27 +1,6 @@
#include "formmaterial.h" #include "formmaterial.h"
#include "../lib_paysages/lighting.h" #include "previewmaterial.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;
};
/**************** Form ****************/ /**************** Form ****************/
FormMaterial::FormMaterial(QWidget* parent, SurfaceMaterial* material) : BaseForm(parent) 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"), &_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); 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")); addPreview(_preview_color, tr("Lighting preview"));
revertConfig(); revertConfig();

View file

@ -33,7 +33,7 @@ public:
_renderer.customData[2] = &_lighting; _renderer.customData[2] = &_lighting;
_renderer.customData[3] = &_water; _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); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:

View file

@ -19,7 +19,7 @@ public:
{ {
_preview_definition = terrainCreateDefinition(); _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); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
@ -96,7 +96,7 @@ public:
_renderer.customData[1] = &_textures; _renderer.customData[1] = &_textures;
_renderer.customData[2] = &_lighting; _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); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:

View file

@ -24,7 +24,7 @@ public:
_water = waterCreateDefinition(); _water = waterCreateDefinition();
_terrain = terrainCreateDefinition(); _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); configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
} }
protected: protected:
@ -81,6 +81,7 @@ public:
_renderer.customData[1] = &_lighting; _renderer.customData[1] = &_lighting;
configScaling(10.0, 1000.0, 10.0, 250.0); configScaling(10.0, 1000.0, 10.0, 250.0);
//configScrolling(-30.0, 30.0, 0.0, -20.0, 20.0, 0.0);
} }
protected: protected:
QColor getColor(double x, double y) QColor getColor(double x, double y)
@ -138,13 +139,14 @@ private:
x = location.x + direction.x * (0.0 - location.z) / direction.z; x = location.x + direction.x * (0.0 - location.z) / direction.z;
y = location.y + direction.y * (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; result.hit_color = COLOR_WHITE;
} }
else else
{ {
result.hit_color = COLOR_GREY; result.hit_color = COLOR_BLACK;
} }
result.hit_location.x = x; result.hit_location.x = x;
result.hit_location.y = y; result.hit_location.y = y;

View file

@ -5,46 +5,13 @@
#include <QPainter> #include <QPainter>
#include <QColorDialog> #include <QColorDialog>
#include "dialogmaterial.h" #include "dialogmaterial.h"
#include "previewmaterial.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;
};
InputMaterial::InputMaterial(QWidget* form, QString label, SurfaceMaterial* value) : BaseInput(form, label) InputMaterial::InputMaterial(QWidget* form, QString label, SurfaceMaterial* value) : BaseInput(form, label)
{ {
_value = value; _value = value;
_preview = new MaterialSmallPreview(form, value); _preview = new SmallMaterialPreview(form, value);
_preview->setMinimumSize(100, 40); _preview->setMinimumSize(100, 40);
_control = new QPushButton(tr("Edit"), form); _control = new QPushButton(tr("Edit"), form);

116
gui_qt/previewmaterial.cpp Normal file
View file

@ -0,0 +1,116 @@
#include "previewmaterial.h"
#include <math.h>
#include <QPainter>
#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);
}

41
gui_qt/previewmaterial.h Normal file
View file

@ -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

18
gui_qt/tools.cpp Normal file
View file

@ -0,0 +1,18 @@
#include "tools.h"
#include <QEvent>
#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);
}

View file

@ -2,6 +2,7 @@
#define _PAYSAGES_QT_TOOLS_H_ #define _PAYSAGES_QT_TOOLS_H_
#include <QColor> #include <QColor>
#include <QDialog>
#include "../lib_paysages/shared/types.h" #include "../lib_paysages/shared/types.h"
#include "../lib_paysages/color.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); 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 #ifndef NDEBUG
#include <QDebug> #include <QDebug>
static inline void logDebug(QString string) static inline void logDebug(QString string)

View file

@ -426,22 +426,22 @@ Maintenir Ctrl : Plus rapide</translation>
<context> <context>
<name>FormMaterial</name> <name>FormMaterial</name>
<message> <message>
<location filename="../gui_qt/formmaterial.cpp" line="32"/> <location filename="../gui_qt/formmaterial.cpp" line="11"/>
<source>Base color</source> <source>Base color</source>
<translation type="unfinished">Couleur de base</translation> <translation type="unfinished">Couleur de base</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formmaterial.cpp" line="33"/> <location filename="../gui_qt/formmaterial.cpp" line="12"/>
<source>Light reflection</source> <source>Light reflection</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formmaterial.cpp" line="34"/> <location filename="../gui_qt/formmaterial.cpp" line="13"/>
<source>Light reflection shininess</source> <source>Light reflection shininess</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formmaterial.cpp" line="37"/> <location filename="../gui_qt/formmaterial.cpp" line="16"/>
<source>Lighting preview</source> <source>Lighting preview</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
@ -689,17 +689,17 @@ Maintenir Ctrl : Plus rapide</translation>
<context> <context>
<name>FormWater</name> <name>FormWater</name>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="177"/> <location filename="../gui_qt/formwater.cpp" line="179"/>
<source>Coverage preview</source> <source>Coverage preview</source>
<translation>Aperçu de la couverture</translation> <translation>Aperçu de la couverture</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="178"/> <location filename="../gui_qt/formwater.cpp" line="180"/>
<source>Rendered preview (without/with lighting)</source> <source>Rendered preview (without/with lighting)</source>
<translation>Aperçu du rendu (sans/avec éclairage)</translation> <translation>Aperçu du rendu (sans/avec éclairage)</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="180"/> <location filename="../gui_qt/formwater.cpp" line="182"/>
<source>Height</source> <source>Height</source>
<translation>Hauteur</translation> <translation>Hauteur</translation>
</message> </message>
@ -716,47 +716,47 @@ Maintenir Ctrl : Plus rapide</translation>
<translation type="obsolete">Concentration de la lumière réfléchie</translation> <translation type="obsolete">Concentration de la lumière réfléchie</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="181"/> <location filename="../gui_qt/formwater.cpp" line="183"/>
<source>Surface material</source> <source>Surface material</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="183"/> <location filename="../gui_qt/formwater.cpp" line="185"/>
<source>Transparency</source> <source>Transparency</source>
<translation>Transparence</translation> <translation>Transparence</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="184"/> <location filename="../gui_qt/formwater.cpp" line="186"/>
<source>Reflection</source> <source>Reflection</source>
<translation>Reflets</translation> <translation>Reflets</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="185"/> <location filename="../gui_qt/formwater.cpp" line="187"/>
<source>Transparency distance</source> <source>Transparency distance</source>
<translation>Distance maximale de transparence</translation> <translation>Distance maximale de transparence</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="182"/> <location filename="../gui_qt/formwater.cpp" line="184"/>
<source>Depth color</source> <source>Depth color</source>
<translation>Couleur en profondeur</translation> <translation>Couleur en profondeur</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="186"/> <location filename="../gui_qt/formwater.cpp" line="188"/>
<source>Light-through distance</source> <source>Light-through distance</source>
<translation>Distance de filtrage de la lumière</translation> <translation>Distance de filtrage de la lumière</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="187"/> <location filename="../gui_qt/formwater.cpp" line="189"/>
<source>Waves noise</source> <source>Waves noise</source>
<translation>Bruit des vagues</translation> <translation>Bruit des vagues</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="188"/> <location filename="../gui_qt/formwater.cpp" line="190"/>
<source>Waves height</source> <source>Waves height</source>
<translation>Hauteur des vagues</translation> <translation>Hauteur des vagues</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/formwater.cpp" line="189"/> <location filename="../gui_qt/formwater.cpp" line="191"/>
<source>Waves scaling</source> <source>Waves scaling</source>
<translation>Echelle des vagues</translation> <translation>Echelle des vagues</translation>
</message> </message>
@ -809,7 +809,7 @@ Maintenir Ctrl : Plus rapide</translation>
<context> <context>
<name>InputMaterial</name> <name>InputMaterial</name>
<message> <message>
<location filename="../gui_qt/inputmaterial.cpp" line="50"/> <location filename="../gui_qt/inputmaterial.cpp" line="17"/>
<source>Edit</source> <source>Edit</source>
<translation type="unfinished">Editer</translation> <translation type="unfinished">Editer</translation>
</message> </message>
@ -916,7 +916,7 @@ rapide (F5)</translation>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="189"/> <location filename="../gui_qt/mainwindow.cpp" line="189"/>
<source>Do you want to load a scenery from file ? Any unsaved changes will be lost.</source> <source>Do you want to load a scenery from file ? Any unsaved changes will be lost.</source>
<translation>Voulez-vous charger une scène ? Les modifications nons sauvegardées seront perdues.</translation> <translation>Voulez-vous charger une scène ? Les modifications non sauvegardées seront perdues.</translation>
</message> </message>
<message> <message>
<location filename="../gui_qt/mainwindow.cpp" line="189"/> <location filename="../gui_qt/mainwindow.cpp" line="189"/>