paysages: Fixed cloud rendering.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@259 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
007c5769e5
commit
8657714d9d
7 changed files with 71 additions and 31 deletions
2
TODO
2
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.
|
- All noises should use the same entropy pool (saved separately), and avoid reallocs.
|
||||||
- Implement light multi-sampling (mainly for skydome).
|
- Implement light multi-sampling (mainly for skydome).
|
||||||
- Implement scaling and scrolling on previews.
|
- Implement scaling and scrolling on previews.
|
||||||
|
|
|
@ -227,7 +227,7 @@ void DialogNoise::revertToCurrent()
|
||||||
void DialogNoise::addLevel()
|
void DialogNoise::addLevel()
|
||||||
{
|
{
|
||||||
NoiseLevel level;
|
NoiseLevel level;
|
||||||
|
|
||||||
level.height = 0.1;
|
level.height = 0.1;
|
||||||
level.scaling = 0.1;
|
level.scaling = 0.1;
|
||||||
level.xoffset = 0.0;
|
level.xoffset = 0.0;
|
||||||
|
@ -236,13 +236,25 @@ void DialogNoise::addLevel()
|
||||||
noiseAddLevel(_current, level);
|
noiseAddLevel(_current, level);
|
||||||
|
|
||||||
revertToCurrent();
|
revertToCurrent();
|
||||||
|
|
||||||
|
levels->setCurrentRow(levels->count() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogNoise::removeLevel()
|
void DialogNoise::removeLevel()
|
||||||
{
|
{
|
||||||
|
int row;
|
||||||
|
|
||||||
|
row = levels->currentRow();
|
||||||
|
|
||||||
noiseRemoveLevel(_current, _current_level);
|
noiseRemoveLevel(_current, _current_level);
|
||||||
|
|
||||||
revertToCurrent();
|
revertToCurrent();
|
||||||
|
|
||||||
|
if (row >= levels->count())
|
||||||
|
{
|
||||||
|
row--;
|
||||||
|
}
|
||||||
|
levels->setCurrentRow(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogNoise::levelChanged(int row)
|
void DialogNoise::levelChanged(int row)
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#include "preview.h"
|
#include "preview.h"
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QWheelEvent>
|
||||||
|
|
||||||
class PreviewDrawer:public QThread
|
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)
|
//static void _scrollPixbuf(SmallPreview* preview, int dx, int dy)
|
||||||
//{
|
//{
|
||||||
// int xstart, ystart, xsize, ysize, y;
|
// int xstart, ystart, xsize, ysize, y;
|
||||||
|
|
|
@ -34,6 +34,8 @@ private:
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent* event);
|
void resizeEvent(QResizeEvent* event);
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
QThread* updater;
|
QThread* updater;
|
||||||
|
|
||||||
|
|
|
@ -89,20 +89,20 @@ void autoGenRealisticLandscape(int seed)
|
||||||
cloud->scaling = 50.0;
|
cloud->scaling = 50.0;
|
||||||
cloud->coverage = 0.5;
|
cloud->coverage = 0.5;
|
||||||
noiseGenerateBaseNoise(cloud->noise, 262144);
|
noiseGenerateBaseNoise(cloud->noise, 262144);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0, 0.3);
|
noiseAddLevelSimple(cloud->noise, 1.0, 1.0);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 2.0, 0.2);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 2.0, 0.6);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 4.0, 0.1);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 4.0, 0.3);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 10.0, 0.05);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 10.0, 0.15);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 20.0, 0.03);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 20.0, 0.09);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 40.0, 0.02);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 40.0, 0.06);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 60.0, 0.01);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 60.0, 0.03);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 80.0, 0.005);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 80.0, 0.015);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 100.0, 0.02);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 100.0, 0.06);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 150.0, 0.005);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 150.0, 0.015);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 200.0, 0.003);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 200.0, 0.009);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 400.0, 0.008);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 400.0, 0.024);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 800.0, 0.001);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 800.0, 0.003);
|
||||||
noiseAddLevelSimple(cloud->noise, 50.0 / 1000.0, 0.0005);
|
noiseAddLevelSimple(cloud->noise, 1.0 / 1000.0, 0.0015);
|
||||||
scenerySetClouds(&clouds);
|
scenerySetClouds(&clouds);
|
||||||
cloudsDeleteDefinition(&clouds);
|
cloudsDeleteDefinition(&clouds);
|
||||||
|
|
||||||
|
|
|
@ -143,14 +143,14 @@ void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinit
|
||||||
|
|
||||||
void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
|
void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
|
||||||
{
|
{
|
||||||
if (definition->coverage < 0.5)
|
/*if (definition->coverage < 0.5)
|
||||||
{
|
{
|
||||||
noiseNormalizeHeight(definition->noise, -1.0, definition->coverage * 2.0, 0);
|
noiseNormalizeHeight(definition->noise, -1.0, definition->coverage * 2.0, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
noiseNormalizeHeight(definition->noise, -(1.0 - definition->coverage) * 2.0, 1.0, 0);
|
noiseNormalizeHeight(definition->noise, -(1.0 - definition->coverage) * 2.0, 1.0, 0);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int cloudsGetLayerCount(CloudsDefinition* definition)
|
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;
|
double val, min;
|
||||||
|
|
||||||
|
@ -214,34 +214,34 @@ static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3
|
||||||
min = (layer->ycenter - position.y) / (layer->ycenter - layer->ymin);
|
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)
|
static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position, double detail)
|
||||||
{
|
{
|
||||||
Vector3 result = {0.0, 0.0, 0.0};
|
Vector3 result = {0.0, 0.0, 0.0};
|
||||||
double val, dval;
|
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) / layer->scaling, position.y / layer->scaling, position.z / layer->scaling, detail);
|
||||||
|
|
||||||
dval = val - noiseGet3DDetail(layer->noise, position.x + detail, position.y, position.z, detail);
|
|
||||||
result.x += dval;
|
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;
|
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;
|
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;
|
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;
|
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;
|
result.z -= dval;
|
||||||
|
|
||||||
return v3Normalize(result);
|
return v3Normalize(result);
|
||||||
|
@ -345,7 +345,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
|
||||||
current_inside_length = 0.0;
|
current_inside_length = 0.0;
|
||||||
segment_length = 0.0;
|
segment_length = 0.0;
|
||||||
walker = start;
|
walker = start;
|
||||||
noise_distance = _getDistanceToBorder(definition, start, detail) * render_precision;
|
noise_distance = _getDistanceToBorder(definition, start) * render_precision;
|
||||||
inside = (noise_distance > 0.0) ? 1 : 0;
|
inside = (noise_distance > 0.0) ? 1 : 0;
|
||||||
step = v3Scale(direction, render_precision);
|
step = v3Scale(direction, render_precision);
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
|
||||||
walker = v3Add(walker, step);
|
walker = v3Add(walker, step);
|
||||||
step_length = v3Norm(step);
|
step_length = v3Norm(step);
|
||||||
last_noise_distance = noise_distance;
|
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;
|
current_total_length += step_length;
|
||||||
|
|
||||||
if (noise_distance > 0.0)
|
if (noise_distance > 0.0)
|
||||||
|
|
|
@ -33,7 +33,7 @@ struct RenderArea
|
||||||
RenderCallbackUpdate callback_update;
|
RenderCallbackUpdate callback_update;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*#define RENDER_INVERSE 1*/
|
#define RENDER_INVERSE 1
|
||||||
#define RENDER_WIREFRAME 1
|
#define RENDER_WIREFRAME 1
|
||||||
|
|
||||||
static void _callbackStart(int width, int height, Color background) {}
|
static void _callbackStart(int width, int height, Color background) {}
|
||||||
|
|
Loading…
Reference in a new issue