From 8657714d9d6cf1d2d48161edc6f426f2938b3771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 6 Feb 2012 20:54:23 +0000 Subject: [PATCH] paysages: Fixed cloud rendering. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@259 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 2 ++ gui_qt/dialognoise.cpp | 14 +++++++++++++- gui_qt/preview.cpp | 24 ++++++++++++++++++++++++ gui_qt/preview.h | 2 ++ lib_paysages/auto.c | 28 ++++++++++++++-------------- lib_paysages/clouds.c | 30 +++++++++++++++--------------- lib_paysages/render.c | 2 +- 7 files changed, 71 insertions(+), 31 deletions(-) diff --git a/TODO b/TODO index efddbf5..0af89ef 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +- Camera looses its orientation when changing render quality. +- Choosing New in Scene menu makes the daytime at 0.0. - All noises should use the same entropy pool (saved separately), and avoid reallocs. - Implement light multi-sampling (mainly for skydome). - Implement scaling and scrolling on previews. diff --git a/gui_qt/dialognoise.cpp b/gui_qt/dialognoise.cpp index e510f94..48f44b7 100644 --- a/gui_qt/dialognoise.cpp +++ b/gui_qt/dialognoise.cpp @@ -227,7 +227,7 @@ void DialogNoise::revertToCurrent() void DialogNoise::addLevel() { NoiseLevel level; - + level.height = 0.1; level.scaling = 0.1; level.xoffset = 0.0; @@ -236,13 +236,25 @@ void DialogNoise::addLevel() noiseAddLevel(_current, level); revertToCurrent(); + + levels->setCurrentRow(levels->count() - 1); } void DialogNoise::removeLevel() { + int row; + + row = levels->currentRow(); + noiseRemoveLevel(_current, _current_level); revertToCurrent(); + + if (row >= levels->count()) + { + row--; + } + levels->setCurrentRow(row); } void DialogNoise::levelChanged(int row) diff --git a/gui_qt/preview.cpp b/gui_qt/preview.cpp index 26e004e..3f9e422 100644 --- a/gui_qt/preview.cpp +++ b/gui_qt/preview.cpp @@ -1,7 +1,9 @@ #include "preview.h" + #include #include #include +#include class PreviewDrawer:public QThread { @@ -203,6 +205,28 @@ void Preview::renderPixbuf() } } +void Preview::wheelEvent(QWheelEvent* event) +{ + if (event->orientation() == Qt::Vertical) + { + if (event->delta() > 0 && scaling > 0.19) + { + scaling -= 0.1; + redraw(); + } + else if (event->delta() < 0 && scaling < 10.0) + { + scaling += 0.1; + redraw(); + } + event->accept(); + } + else + { + event->ignore(); + } +} + //static void _scrollPixbuf(SmallPreview* preview, int dx, int dy) //{ // int xstart, ystart, xsize, ysize, y; diff --git a/gui_qt/preview.h b/gui_qt/preview.h index 6bc8f38..3ed0981 100644 --- a/gui_qt/preview.h +++ b/gui_qt/preview.h @@ -34,6 +34,8 @@ private: void resizeEvent(QResizeEvent* event); void paintEvent(QPaintEvent* event); + + void wheelEvent(QWheelEvent* event); QThread* updater; diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index 273826b..cc34eea 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -89,20 +89,20 @@ void autoGenRealisticLandscape(int seed) cloud->scaling = 50.0; cloud->coverage = 0.5; noiseGenerateBaseNoise(cloud->noise, 262144); - noiseAddLevelSimple(cloud->noise, 50.0, 0.3); - noiseAddLevelSimple(cloud->noise, 50.0 / 2.0, 0.2); - noiseAddLevelSimple(cloud->noise, 50.0 / 4.0, 0.1); - noiseAddLevelSimple(cloud->noise, 50.0 / 10.0, 0.05); - noiseAddLevelSimple(cloud->noise, 50.0 / 20.0, 0.03); - noiseAddLevelSimple(cloud->noise, 50.0 / 40.0, 0.02); - noiseAddLevelSimple(cloud->noise, 50.0 / 60.0, 0.01); - noiseAddLevelSimple(cloud->noise, 50.0 / 80.0, 0.005); - noiseAddLevelSimple(cloud->noise, 50.0 / 100.0, 0.02); - noiseAddLevelSimple(cloud->noise, 50.0 / 150.0, 0.005); - noiseAddLevelSimple(cloud->noise, 50.0 / 200.0, 0.003); - noiseAddLevelSimple(cloud->noise, 50.0 / 400.0, 0.008); - noiseAddLevelSimple(cloud->noise, 50.0 / 800.0, 0.001); - noiseAddLevelSimple(cloud->noise, 50.0 / 1000.0, 0.0005); + noiseAddLevelSimple(cloud->noise, 1.0, 1.0); + noiseAddLevelSimple(cloud->noise, 1.0 / 2.0, 0.6); + noiseAddLevelSimple(cloud->noise, 1.0 / 4.0, 0.3); + noiseAddLevelSimple(cloud->noise, 1.0 / 10.0, 0.15); + noiseAddLevelSimple(cloud->noise, 1.0 / 20.0, 0.09); + noiseAddLevelSimple(cloud->noise, 1.0 / 40.0, 0.06); + noiseAddLevelSimple(cloud->noise, 1.0 / 60.0, 0.03); + noiseAddLevelSimple(cloud->noise, 1.0 / 80.0, 0.015); + noiseAddLevelSimple(cloud->noise, 1.0 / 100.0, 0.06); + noiseAddLevelSimple(cloud->noise, 1.0 / 150.0, 0.015); + noiseAddLevelSimple(cloud->noise, 1.0 / 200.0, 0.009); + noiseAddLevelSimple(cloud->noise, 1.0 / 400.0, 0.024); + noiseAddLevelSimple(cloud->noise, 1.0 / 800.0, 0.003); + noiseAddLevelSimple(cloud->noise, 1.0 / 1000.0, 0.0015); scenerySetClouds(&clouds); cloudsDeleteDefinition(&clouds); diff --git a/lib_paysages/clouds.c b/lib_paysages/clouds.c index 954d373..f962b6c 100644 --- a/lib_paysages/clouds.c +++ b/lib_paysages/clouds.c @@ -143,14 +143,14 @@ void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinit void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition) { - if (definition->coverage < 0.5) + /*if (definition->coverage < 0.5) { noiseNormalizeHeight(definition->noise, -1.0, definition->coverage * 2.0, 0); } else { noiseNormalizeHeight(definition->noise, -(1.0 - definition->coverage) * 2.0, 1.0, 0); - } + }*/ } int cloudsGetLayerCount(CloudsDefinition* definition) @@ -201,7 +201,7 @@ void cloudsDeleteLayer(CloudsDefinition* definition, int layer) } } -static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position, double detail) +static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 position) { double val, min; @@ -214,34 +214,34 @@ static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3 min = (layer->ycenter - position.y) / (layer->ycenter - layer->ymin); } - val = noiseGet3DDetail(layer->noise, position.x, position.y, position.z, detail); + val = 0.5 * noiseGet3DTotal(layer->noise, position.x / layer->scaling, position.y / layer->scaling, position.z / layer->scaling) / noiseGetMaxValue(layer->noise); - return (val - min) * layer->scaling; + return (val - 0.5 - min + layer->coverage) * layer->scaling; } static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, double detail) { Vector3 result = {0.0, 0.0, 0.0}; double val, dval; + + val = noiseGet3DDetail(layer->noise, position.x / layer->scaling, position.y / layer->scaling, position.z / layer->scaling, detail); - val = noiseGet3DDetail(layer->noise, position.x, position.y, position.z, detail); - - dval = val - noiseGet3DDetail(layer->noise, position.x + detail, position.y, position.z, detail); + dval = val - noiseGet3DDetail(layer->noise, (position.x + detail) / layer->scaling, position.y / layer->scaling, position.z / layer->scaling, detail); result.x += dval; - dval = val - noiseGet3DDetail(layer->noise, position.x - detail, position.y, position.z, detail); + dval = val - noiseGet3DDetail(layer->noise, (position.x - detail) / layer->scaling, position.y / layer->scaling, position.z / layer->scaling, detail); result.x -= dval; - dval = val - noiseGet3DDetail(layer->noise, position.x, position.y + detail, position.z, detail); + dval = val - noiseGet3DDetail(layer->noise, position.x / layer->scaling, (position.y + detail) / layer->scaling, position.z / layer->scaling, detail); result.y += dval; - dval = val - noiseGet3DDetail(layer->noise, position.x, position.y - detail, position.z, detail); + dval = val - noiseGet3DDetail(layer->noise, position.x / layer->scaling, (position.y - detail) / layer->scaling, position.z / layer->scaling, detail); result.y -= dval; - dval = val - noiseGet3DDetail(layer->noise, position.x, position.y, position.z + detail, detail); + dval = val - noiseGet3DDetail(layer->noise, position.x / layer->scaling, position.y / layer->scaling, (position.z + detail) / layer->scaling, detail); result.z += dval; - dval = val - noiseGet3DDetail(layer->noise, position.x, position.y, position.z - detail, detail); + dval = val - noiseGet3DDetail(layer->noise, position.x / layer->scaling, position.y / layer->scaling, (position.z - detail) / layer->scaling, detail); result.z -= dval; return v3Normalize(result); @@ -345,7 +345,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, current_inside_length = 0.0; segment_length = 0.0; walker = start; - noise_distance = _getDistanceToBorder(definition, start, detail) * render_precision; + noise_distance = _getDistanceToBorder(definition, start) * render_precision; inside = (noise_distance > 0.0) ? 1 : 0; step = v3Scale(direction, render_precision); @@ -354,7 +354,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer, walker = v3Add(walker, step); step_length = v3Norm(step); last_noise_distance = noise_distance; - noise_distance = _getDistanceToBorder(definition, walker, detail) * render_precision; + noise_distance = _getDistanceToBorder(definition, walker) * render_precision; current_total_length += step_length; if (noise_distance > 0.0) diff --git a/lib_paysages/render.c b/lib_paysages/render.c index 9e0fc20..d196258 100644 --- a/lib_paysages/render.c +++ b/lib_paysages/render.c @@ -33,7 +33,7 @@ struct RenderArea RenderCallbackUpdate callback_update; }; -/*#define RENDER_INVERSE 1*/ +#define RENDER_INVERSE 1 #define RENDER_WIREFRAME 1 static void _callbackStart(int width, int height, Color background) {}