From 7cd74b2c8a9466530e7a2e71801e5e9715331488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sat, 24 Aug 2013 00:51:27 +0200 Subject: [PATCH] WIP on texture previews --- src/editing/common/freeformhelper.cpp | 2 +- src/editing/editing.pro | 8 +++- src/editing/textures/PreviewCumul.cpp | 44 +++++++++++++++++++ src/editing/textures/PreviewCumul.h | 24 ++++++++++ src/editing/textures/PreviewLayerCoverage.cpp | 4 ++ src/editing/textures/PreviewLayerLook.cpp | 42 ++++++++++++++++++ src/editing/textures/PreviewLayerLook.h | 24 ++++++++++ src/editing/textures/maintexturesform.cpp | 10 +++++ src/editing/textures/maintexturesform.h | 4 ++ src/rendering/atmosphere/atm_render.c | 6 +-- src/rendering/textures/tex_preview.c | 34 +++++++++++++- src/rendering/textures/tex_preview.h | 8 ++++ 12 files changed, 203 insertions(+), 7 deletions(-) create mode 100644 src/editing/textures/PreviewCumul.cpp create mode 100644 src/editing/textures/PreviewCumul.h create mode 100644 src/editing/textures/PreviewLayerLook.cpp create mode 100644 src/editing/textures/PreviewLayerLook.h diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp index 3fbde3b..acb9490 100644 --- a/src/editing/common/freeformhelper.cpp +++ b/src/editing/common/freeformhelper.cpp @@ -43,7 +43,7 @@ bool FreeFormHelper::eventFilter(QObject* object, QEvent* event) { preview_size = QSize(320, 320); } - else if (form_size.width() < 1000 || form_size.height() < 700) + else if (form_size.width() < 1100 || form_size.height() < 750) { preview_size = QSize(200, 200); } diff --git a/src/editing/editing.pro b/src/editing/editing.pro index fdc4810..2a7b4fa 100644 --- a/src/editing/editing.pro +++ b/src/editing/editing.pro @@ -70,7 +70,9 @@ HEADERS += \ common/DrawingWidget.h \ lighting/SmallPreviewColor.h \ lighting/SmallPreviewHues.h \ - textures/PreviewLayerCoverage.h + textures/PreviewLayerCoverage.h \ + textures/PreviewLayerLook.h \ + textures/PreviewCumul.h SOURCES += \ terrain/widgetheightmap.cpp \ @@ -126,7 +128,9 @@ SOURCES += \ common/DrawingWidget.cpp \ lighting/SmallPreviewColor.cpp \ lighting/SmallPreviewHues.cpp \ - textures/PreviewLayerCoverage.cpp + textures/PreviewLayerCoverage.cpp \ + textures/PreviewLayerLook.cpp \ + textures/PreviewCumul.cpp FORMS += \ terrain/dialogterrainpainting.ui \ diff --git a/src/editing/textures/PreviewCumul.cpp b/src/editing/textures/PreviewCumul.cpp new file mode 100644 index 0000000..0306cd2 --- /dev/null +++ b/src/editing/textures/PreviewCumul.cpp @@ -0,0 +1,44 @@ +#include "PreviewCumul.h" + +#include "editing/basepreview.h" +#include "rendering/textures/tex_preview.h" + +void PreviewCumul::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void PreviewCumul::setLayer(int layer) +{ + this->layer = layer; +} + +void PreviewCumul::bindEvent(BasePreview* preview) +{ + preview->addOsd(QString("geolocation")); + + //preview->configHdrToneMapping(true); + + preview->configScaling(20.0, 1000.0, 20.0, 200.0); + preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); +} + +void PreviewCumul::updateEvent() +{ + if (textures) + { + TexturesPreviewCumul_bind(renderer, textures); + } +} + +Color PreviewCumul::getColor2D(double x, double y, double scaling) +{ + if (textures) + { + return TexturesPreviewCumul_getColor(renderer, x, y, scaling, layer); + } + else + { + return COLOR_BLACK; + } +} diff --git a/src/editing/textures/PreviewCumul.h b/src/editing/textures/PreviewCumul.h new file mode 100644 index 0000000..fc69bc2 --- /dev/null +++ b/src/editing/textures/PreviewCumul.h @@ -0,0 +1,24 @@ +#ifndef EDITING_TEXTURES_PREVIEWCUMUL_H +#define EDITING_TEXTURES_PREVIEWCUMUL_H + +#include "editing/common/previewrenderer.h" + +class BasePreview; + +class PreviewCumul : public PreviewRenderer +{ +public: + void setTextures(TexturesDefinition* textures); + void setLayer(int layer); + +protected: + virtual void bindEvent(BasePreview* preview); + virtual void updateEvent(); + virtual Color getColor2D(double x, double y, double scaling); + +private: + TexturesDefinition* textures = 0; + int layer; +}; + +#endif diff --git a/src/editing/textures/PreviewLayerCoverage.cpp b/src/editing/textures/PreviewLayerCoverage.cpp index 156173f..7eb334d 100644 --- a/src/editing/textures/PreviewLayerCoverage.cpp +++ b/src/editing/textures/PreviewLayerCoverage.cpp @@ -35,4 +35,8 @@ Color PreviewLayerCoverage::getColor2D(double x, double y, double scaling) { return TexturesPreviewLayerCoverage_getColor(renderer, x, y, scaling, layer); } + else + { + return COLOR_BLACK; + } } diff --git a/src/editing/textures/PreviewLayerLook.cpp b/src/editing/textures/PreviewLayerLook.cpp new file mode 100644 index 0000000..4b70ccb --- /dev/null +++ b/src/editing/textures/PreviewLayerLook.cpp @@ -0,0 +1,42 @@ +#include "PreviewLayerLook.h" + +#include "editing/basepreview.h" +#include "rendering/textures/tex_preview.h" + +void PreviewLayerLook::setTextures(TexturesDefinition* textures) +{ + this->textures = textures; +} + +void PreviewLayerLook::setLayer(int layer) +{ + this->layer = layer; +} + +void PreviewLayerLook::bindEvent(BasePreview* preview) +{ + //preview->configHdrToneMapping(true); + + preview->configScaling(0.01, 1.0, 0.01, 0.1); +} + +void PreviewLayerLook::updateEvent() +{ + if (textures) + { + TexturesPreviewLayerLook_bind(renderer, textures); + } +} + +Color PreviewLayerLook::getColor2D(double x, double y, double scaling) +{ + if (textures) + { + return TexturesPreviewLayerLook_getColor(renderer, x, y, scaling, layer); + } + else + { + return COLOR_BLACK; + } +} + diff --git a/src/editing/textures/PreviewLayerLook.h b/src/editing/textures/PreviewLayerLook.h new file mode 100644 index 0000000..e9ed9f2 --- /dev/null +++ b/src/editing/textures/PreviewLayerLook.h @@ -0,0 +1,24 @@ +#ifndef EDITING_TEXTURES_PREVIEWLAYERLOOK_H +#define EDITING_TEXTURES_PREVIEWLAYERLOOK_H + +#include "editing/common/previewrenderer.h" + +class BasePreview; + +class PreviewLayerLook : public PreviewRenderer +{ +public: + void setTextures(TexturesDefinition* textures); + void setLayer(int layer); + +protected: + virtual void bindEvent(BasePreview* preview); + virtual void updateEvent(); + virtual Color getColor2D(double x, double y, double scaling); + +private: + TexturesDefinition* textures = 0; + int layer; +}; + +#endif diff --git a/src/editing/textures/maintexturesform.cpp b/src/editing/textures/maintexturesform.cpp index 3a2564a..1242074 100644 --- a/src/editing/textures/maintexturesform.cpp +++ b/src/editing/textures/maintexturesform.cpp @@ -6,6 +6,8 @@ #include "rendering/scenery.h" #include "previewmaterial.h" #include "editing/textures/PreviewLayerCoverage.h" +#include "editing/textures/PreviewLayerLook.h" +#include "editing/textures/PreviewCumul.h" MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm) { @@ -33,6 +35,14 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui preview_layer_coverage->setTextures(textures); form_helper->addPreview(ui->preview_coverage, preview_layer_coverage); + preview_layer_look = new PreviewLayerLook(); + preview_layer_look->setTextures(textures); + form_helper->addPreview(ui->preview_texture, preview_layer_look); + + preview_cumul = new PreviewCumul(); + preview_cumul->setTextures(textures); + form_helper->addPreview(ui->preview_cumul, preview_cumul); + form_helper->addPreset(tr("Rocks with grass")); form_helper->addPreset(tr("Snow covered mountains")); form_helper->addPreset(tr("Arid canyons")); diff --git a/src/editing/textures/maintexturesform.h b/src/editing/textures/maintexturesform.h index 496427e..bb78c3e 100644 --- a/src/editing/textures/maintexturesform.h +++ b/src/editing/textures/maintexturesform.h @@ -11,6 +11,8 @@ class MainTexturesForm; class FreeFormHelper; class FreeLayerHelper; class PreviewLayerCoverage; +class PreviewLayerLook; +class PreviewCumul; class MainTexturesForm : public QWidget { @@ -37,6 +39,8 @@ private: FreeFormHelper* form_helper; FreeLayerHelper* layer_helper; PreviewLayerCoverage* preview_layer_coverage; + PreviewLayerLook* preview_layer_look; + PreviewCumul* preview_cumul; }; #endif // MAINTEXTURESFORM_H diff --git a/src/rendering/atmosphere/atm_render.c b/src/rendering/atmosphere/atm_render.c index 61148a3..4c1414e 100644 --- a/src/rendering/atmosphere/atm_render.c +++ b/src/rendering/atmosphere/atm_render.c @@ -36,9 +36,9 @@ static void _fakeGetLightingStatus(Renderer* renderer, LightStatus* status, Vect UNUSED(normal); UNUSED(opaque); - light.color.r = 0.8; - light.color.g = 0.8; - light.color.b = 0.8; + light.color.r = 1.0; + light.color.g = 1.0; + light.color.b = 1.0; light.direction.x = -0.7; light.direction.y = -0.7; light.direction.z = 0.7; diff --git a/src/rendering/textures/tex_preview.c b/src/rendering/textures/tex_preview.c index 477b95e..d7e652e 100644 --- a/src/rendering/textures/tex_preview.c +++ b/src/rendering/textures/tex_preview.c @@ -7,7 +7,7 @@ void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition) { TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); - sceneryGetTerrain(renderer->terrain->definition); + sceneryGetTerrain(terrain); TerrainRendererClass.bind(renderer, terrain); TerrainDefinitionClass.destroy(terrain); @@ -39,3 +39,35 @@ Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double return result; } + +void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition) +{ + TexturesRendererClass.bind(renderer, definition); +} + +Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer) +{ + UNUSED(scaling); + UNUSED(layer); + + return renderer->textures->applyToTerrain(renderer, x, y).final_color; +} + + +void TexturesPreviewCumul_bind(Renderer* renderer, TexturesDefinition* definition) +{ + TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); + sceneryGetTerrain(terrain); + TerrainRendererClass.bind(renderer, terrain); + TerrainDefinitionClass.destroy(terrain); + + TexturesRendererClass.bind(renderer, definition); +} + +Color TexturesPreviewCumul_getColor(Renderer* renderer, double x, double y, double scaling, int layer) +{ + UNUSED(scaling); + UNUSED(layer); + + return renderer->textures->applyToTerrain(renderer, x, y).final_color; +} diff --git a/src/rendering/textures/tex_preview.h b/src/rendering/textures/tex_preview.h index 17ef7da..74c7d4f 100644 --- a/src/rendering/textures/tex_preview.h +++ b/src/rendering/textures/tex_preview.h @@ -12,6 +12,14 @@ extern "C" { void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition); Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double y, double scaling, int layer); +/* Single layer look */ +void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition); +Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer); + +/* Cumulative color preview */ +void TexturesPreviewCumul_bind(Renderer* renderer, TexturesDefinition* definition); +Color TexturesPreviewCumul_getColor(Renderer* renderer, double x, double y, double scaling, int layer); + #ifdef __cplusplus } #endif