paysages : HDR on previews + small fixes.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@496 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-01-16 14:26:46 +00:00 committed by ThunderK
parent 2a0e7851d9
commit 804ee6943f
18 changed files with 169 additions and 143 deletions

View file

@ -23,38 +23,38 @@ public:
_ystart = ystart; _ystart = ystart;
_xsize = xsize; _xsize = xsize;
_ysize = ysize; _ysize = ysize;
_need_render = true; _need_render = true;
_rendering = false; _rendering = false;
_alive = true; _alive = true;
_priority = xstart; _priority = xstart;
} }
inline BasePreview* preview() inline BasePreview* preview()
{ {
return _preview; return _preview;
} }
inline int priority() inline int priority()
{ {
return _priority; return _priority;
} }
inline bool isOnFront() inline bool isOnFront()
{ {
return _preview->isVisible() && _preview->window()->isActiveWindow(); return _preview->isVisible() && _preview->window()->isActiveWindow();
} }
bool isFrom(BasePreview* preview) bool isFrom(BasePreview* preview)
{ {
return _preview == preview; return _preview == preview;
} }
void interrupt() void interrupt()
{ {
_alive = false; _alive = false;
} }
void update() void update()
{ {
_priority = _xstart; _priority = _xstart;
@ -65,15 +65,15 @@ public:
{ {
bool changed = false; bool changed = false;
int revision; int revision;
if (_rendering) if (_rendering)
{ {
return false; return false;
} }
_rendering = true; _rendering = true;
_alive = true; _alive = true;
if (_need_render) if (_need_render)
{ {
if (!isOnFront()) if (!isOnFront())
@ -82,9 +82,9 @@ public:
_rendering = false; _rendering = false;
return false; return false;
} }
_need_render = false; _need_render = false;
QImage pixbuf = _preview->startChunkTransaction(_xstart, _ystart, _xsize, _ysize, &revision); QImage pixbuf = _preview->startChunkTransaction(_xstart, _ystart, _xsize, _ysize, &revision);
for (int x = 0; x < _xsize; x++) for (int x = 0; x < _xsize; x++)
@ -103,14 +103,14 @@ public:
{ {
QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y); QColor newcol = _preview->getPixelColor(_xstart + x, _ystart + y);
newcol.setAlpha(255); newcol.setAlpha(255);
pixbuf.setPixel(x, y, newcol.rgb()); pixbuf.setPixel(x, y, newcol.rgb());
changed = true; changed = true;
} }
} }
} }
if (changed) if (changed)
{ {
_need_render = not _preview->commitChunkTransaction(&pixbuf, _xstart, _ystart, _xsize, _ysize, revision); _need_render = not _preview->commitChunkTransaction(&pixbuf, _xstart, _ystart, _xsize, _ysize, revision);
@ -120,12 +120,12 @@ public:
_preview->rollbackChunkTransaction(); _preview->rollbackChunkTransaction();
} }
} }
if (not _need_render) if (not _need_render)
{ {
_priority = -1; _priority = -1;
} }
_rendering = false; _rendering = false;
return _need_render; return _need_render;
} }
@ -219,12 +219,12 @@ void PreviewDrawingManager::removeChunks(BasePreview* preview)
_chunks.remove(i); _chunks.remove(i);
_updateQueue.removeAll(chunk); _updateQueue.removeAll(chunk);
_lock.unlock(); _lock.unlock();
removed++; removed++;
i--; i--;
} }
} }
logDebug(QString("[Previews] %1 chunks removed, %2 remaining").arg(removed).arg(_chunks.size())); logDebug(QString("[Previews] %1 chunks removed, %2 remaining").arg(removed).arg(_chunks.size()));
} }
@ -317,7 +317,7 @@ void PreviewDrawingManager::performOneThreadJob()
} }
_lock.unlock(); _lock.unlock();
} }
} }
} }
int PreviewDrawingManager::chunkCount() int PreviewDrawingManager::chunkCount()
@ -353,11 +353,14 @@ QWidget(parent)
_revision = 0; _revision = 0;
_transactions_count = 0; _transactions_count = 0;
_redraw_requested = false; _redraw_requested = false;
_info = new QLabel(this); _info = new QLabel(this);
_info->setVisible(false); _info->setVisible(false);
_info->setStyleSheet("QLabel { background-color: white; color: black; }"); _info->setStyleSheet("QLabel { background-color: white; color: black; }");
_hdr_enabled = false;
_hdr_profile = colorProfileCreate();
this->alive = true; this->alive = true;
QObject::connect(this, SIGNAL(contentChange()), this, SLOT(update())); QObject::connect(this, SIGNAL(contentChange()), this, SLOT(update()));
@ -365,7 +368,7 @@ QWidget(parent)
this->setMinimumSize(256, 256); this->setMinimumSize(256, 256);
this->setMaximumSize(256, 256); this->setMaximumSize(256, 256);
this->resize(256, 256); this->resize(256, 256);
startTimer(50); startTimer(50);
} }
@ -373,6 +376,8 @@ BasePreview::~BasePreview()
{ {
alive = false; alive = false;
colorProfileDelete(_hdr_profile);
_drawing_manager->removeChunks(this); _drawing_manager->removeChunks(this);
delete _info; delete _info;
@ -380,6 +385,12 @@ BasePreview::~BasePreview()
delete _lock_drawing; delete _lock_drawing;
} }
void BasePreview::configHdrToneMapping(bool active)
{
_hdr_enabled = active;
redraw();
}
void BasePreview::addOsd(QString name) void BasePreview::addOsd(QString name)
{ {
_osd.append(PreviewOsd::getInstance(name)); _osd.append(PreviewOsd::getInstance(name));
@ -391,7 +402,7 @@ void BasePreview::savePack(PackStream* stream)
packWriteDouble(stream, &this->xoffset); packWriteDouble(stream, &this->xoffset);
packWriteDouble(stream, &this->yoffset); packWriteDouble(stream, &this->yoffset);
packWriteDouble(stream, &this->scalingbase); packWriteDouble(stream, &this->scalingbase);
// TODO Save choices and toggles // TODO Save choices and toggles
} }
@ -400,9 +411,9 @@ void BasePreview::loadPack(PackStream* stream)
packReadDouble(stream, &this->xoffset); packReadDouble(stream, &this->xoffset);
packReadDouble(stream, &this->yoffset); packReadDouble(stream, &this->yoffset);
packReadDouble(stream, &this->scalingbase); packReadDouble(stream, &this->scalingbase);
// TODO Save choices and toggles // TODO Save choices and toggles
updateScaling(); updateScaling();
emit contentChange(); emit contentChange();
} }
@ -427,9 +438,9 @@ void BasePreview::updateData()
{ {
} }
QColor BasePreview::getColor(double, double) Color BasePreview::getColor(double, double)
{ {
return QColor(0, 0, 0); return COLOR_BLACK;
} }
void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic) void BasePreview::configScaling(double min, double max, double step, double init, bool logarithmic)
@ -473,9 +484,9 @@ void BasePreview::addChoice(const QString& key, const QString& title, const QStr
choice.title = title; choice.title = title;
choice.items << choices; choice.items << choices;
choice.current = init_value; choice.current = init_value;
_choices.insert(key, choice); _choices.insert(key, choice);
choiceChangeEvent(key, init_value); choiceChangeEvent(key, init_value);
} }
@ -488,9 +499,9 @@ void BasePreview::addToggle(const QString& key, const QString& text, bool init_v
_ContextToggle toggle; _ContextToggle toggle;
toggle.title = text; toggle.title = text;
toggle.value = init_value; toggle.value = init_value;
_toggles.insert(key, toggle); _toggles.insert(key, toggle);
toggleChangeEvent(key, init_value); toggleChangeEvent(key, init_value);
} }
@ -507,24 +518,24 @@ void BasePreview::redraw()
QImage BasePreview::startChunkTransaction(int x, int y, int w, int h, int* revision) QImage BasePreview::startChunkTransaction(int x, int y, int w, int h, int* revision)
{ {
QImage result; QImage result;
_lock_drawing->lock(); _lock_drawing->lock();
*revision = _revision; *revision = _revision;
result = _pixbuf->copy(x, y, w, h); result = _pixbuf->copy(x, y, w, h);
_transactions_count++; _transactions_count++;
_lock_drawing->unlock(); _lock_drawing->unlock();
return result; return result;
} }
bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision) bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision)
{ {
bool result; bool result;
_lock_drawing->lock(); _lock_drawing->lock();
if (revision == _revision) if (revision == _revision)
{ {
for (int ix = 0; ix < w; ix++) for (int ix = 0; ix < w; ix++)
@ -541,26 +552,35 @@ bool BasePreview::commitChunkTransaction(QImage* chunk, int x, int y, int w, int
{ {
result = false; result = false;
} }
_transactions_count--; _transactions_count--;
_lock_drawing->unlock(); _lock_drawing->unlock();
return result; return result;
} }
void BasePreview::rollbackChunkTransaction() void BasePreview::rollbackChunkTransaction()
{ {
_lock_drawing->lock(); _lock_drawing->lock();
_transactions_count--; _transactions_count--;
_lock_drawing->unlock(); _lock_drawing->unlock();
} }
QColor BasePreview::getPixelColor(int x, int y) QColor BasePreview::getPixelColor(int x, int y)
{ {
return getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset); Color col = getColor((double) (x - _width / 2) * scaling + xoffset, (double) (y - _height / 2) * scaling + yoffset);
if (_hdr_enabled)
{
col = colorProfileApply(_hdr_profile, col);
}
else
{
colorNormalize(&col);
}
return colorToQColor(col);
} }
void BasePreview::timerEvent(QTimerEvent*) void BasePreview::timerEvent(QTimerEvent*)
@ -647,7 +667,7 @@ void BasePreview::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
painter.drawImage(0, 0, *this->_pixbuf); painter.drawImage(0, 0, *this->_pixbuf);
QImage osd(_pixbuf->size(), _pixbuf->format()); QImage osd(_pixbuf->size(), _pixbuf->format());
osd.fill(0x00000000); osd.fill(0x00000000);
for (int i = 0; i < _osd.size(); i++) for (int i = 0; i < _osd.size(); i++)
@ -705,10 +725,10 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event)
{ {
menu.addSeparator(); menu.addSeparator();
} }
iter1.next(); iter1.next();
menu.addAction(QString(" %1 ").arg(iter1.value().title))->setDisabled(true); menu.addAction(QString(" %1 ").arg(iter1.value().title))->setDisabled(true);
QStringList list = iter1.value().items; QStringList list = iter1.value().items;
for (int i = 0; i < list.count(); i++) for (int i = 0; i < list.count(); i++)
{ {
@ -732,7 +752,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event)
{ {
menu.addSeparator(); menu.addSeparator();
} }
iter2.next(); iter2.next();
QAction* action = menu.addAction(iter2.value().title); QAction* action = menu.addAction(iter2.value().title);
@ -749,7 +769,7 @@ void BasePreview::contextMenuEvent(QContextMenuEvent* event)
if (not menu.isEmpty()) if (not menu.isEmpty())
{ {
connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(choiceSelected(QAction*))); connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(choiceSelected(QAction*)));
menu.exec(event->globalPos()); menu.exec(event->globalPos());
event->accept(); event->accept();
} }
@ -767,7 +787,7 @@ void BasePreview::mousePressEvent(QMouseEvent* event)
void BasePreview::mouseMoveEvent(QMouseEvent* event) void BasePreview::mouseMoveEvent(QMouseEvent* event)
{ {
int width, height; int width, height;
width = this->width(); width = this->width();
height = this->height(); height = this->height();
@ -775,7 +795,7 @@ void BasePreview::mouseMoveEvent(QMouseEvent* event)
{ {
int dx, dy; int dx, dy;
int ndx, ndy; int ndx, ndy;
dx = event->x() - mousex; dx = event->x() - mousex;
dy = event->y() - mousey; dy = event->y() - mousey;

View file

@ -33,16 +33,16 @@ class BasePreview : public QWidget {
public: public:
BasePreview(QWidget* parent); BasePreview(QWidget* parent);
~BasePreview(); ~BasePreview();
virtual void savePack(PackStream* stream); virtual void savePack(PackStream* stream);
virtual void loadPack(PackStream* stream); virtual void loadPack(PackStream* stream);
static void initDrawers(); static void initDrawers();
static void stopDrawers(); static void stopDrawers();
static void reviveAll(); static void reviveAll();
void redraw(); void redraw();
QImage startChunkTransaction(int x, int y, int w, int h, int* revision); QImage startChunkTransaction(int x, int y, int w, int h, int* revision);
bool commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision); bool commitChunkTransaction(QImage* chunk, int x, int y, int w, int h, int revision);
void rollbackChunkTransaction(); void rollbackChunkTransaction();
@ -51,8 +51,9 @@ public:
protected: protected:
virtual void updateData(); virtual void updateData();
virtual QColor getColor(double x, double y); virtual Color getColor(double x, double y);
void configHdrToneMapping(bool active);
void configScaling(double min, double max, double step, double init, bool logarithmic = true); void configScaling(double min, double max, double step, double init, bool logarithmic = true);
void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit); void configScrolling(double xmin, double xmax, double xinit, double ymin, double ymax, double yinit);
@ -89,12 +90,12 @@ private:
QVector<PreviewOsd*> _osd; QVector<PreviewOsd*> _osd;
QHash<QString, _ContextChoice> _choices; QHash<QString, _ContextChoice> _choices;
QHash<QString, _ContextToggle> _toggles; QHash<QString, _ContextToggle> _toggles;
QLabel* _info; QLabel* _info;
int _width; int _width;
int _height; int _height;
int _revision; int _revision;
int _transactions_count; int _transactions_count;
bool _redraw_requested; bool _redraw_requested;
@ -105,6 +106,8 @@ private:
double scalingbase; double scalingbase;
bool alive; bool alive;
bool _hdr_enabled;
ColorProfile* _hdr_profile;
double conf_scroll_xmin; double conf_scroll_xmin;
double conf_scroll_xmax; double conf_scroll_xmax;

View file

@ -1,5 +1,6 @@
#include "dialognoise.h" #include "dialognoise.h"
#include <QWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QImage> #include <QImage>
#include <QLabel> #include <QLabel>
@ -9,7 +10,7 @@
#include <QScrollArea> #include <QScrollArea>
#include <QPushButton> #include <QPushButton>
#include <math.h> #include <math.h>
#include <qt4/QtGui/qwidget.h> #include "../lib_paysages/color.h"
/**************** Previews ****************/ /**************** Previews ****************/
class PreviewLevel:public BasePreview class PreviewLevel:public BasePreview
@ -34,15 +35,15 @@ protected:
{ {
noiseCopy(_noise_original, _noise_preview); noiseCopy(_noise_original, _noise_preview);
} }
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
if ((_level >= 0) && (-y > noiseGet1DLevel(_noise_preview, _level, x))) if ((_level >= 0) && (-y > noiseGet1DLevel(_noise_preview, _level, x)))
{ {
return Qt::black; return COLOR_WHITE;
} }
else else
{ {
return Qt::white; return COLOR_BLACK;
} }
} }
private: private:
@ -66,15 +67,15 @@ protected:
{ {
noiseCopy(_noise_original, _noise_preview); noiseCopy(_noise_original, _noise_preview);
} }
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
if (-y > noiseGet1DTotal(_noise_preview, x)) if (-y > noiseGet1DTotal(_noise_preview, x))
{ {
return Qt::black; return COLOR_WHITE;
} }
else else
{ {
return Qt::white; return COLOR_BLACK;
} }
} }
private: private:

View file

@ -21,12 +21,13 @@ public:
{ {
_renderer = atmosphereCreatePreviewRenderer(); _renderer = atmosphereCreatePreviewRenderer();
configHdrToneMapping(true);
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, M_PI_2)); return atmosphereGetPreview(&_renderer, x, -y, M_PI_2);
} }
void updateData() void updateData()
{ {
@ -44,12 +45,13 @@ public:
{ {
_renderer = atmosphereCreatePreviewRenderer(); _renderer = atmosphereCreatePreviewRenderer();
configHdrToneMapping(true);
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, -M_PI_2)); return atmosphereGetPreview(&_renderer, x, -y, -M_PI_2);
} }
void updateData() void updateData()
{ {

View file

@ -27,10 +27,9 @@ public:
cloudsLayerDeleteDefinition(_preview_layer); cloudsLayerDeleteDefinition(_preview_layer);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 eye, look; Vector3 eye, look;
Color color_layer;
eye.x = 0.0; eye.x = 0.0;
eye.y = scaling; eye.y = scaling;
@ -40,8 +39,7 @@ protected:
look.z = 1.0; look.z = 1.0;
look = v3Normalize(look); look = v3Normalize(look);
color_layer = cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0))); return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, eye, v3Add(eye, v3Scale(look, 1000.0)));
return colorToQColor(color_layer);
} }
void updateData() void updateData()
{ {
@ -90,10 +88,9 @@ public:
configScaling(0.5, 2.0, 0.1, 2.0); configScaling(0.5, 2.0, 0.1, 2.0);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 start, end; Vector3 start, end;
Color color_layer;
start.x = x * _preview_layer->thickness * 0.5; start.x = x * _preview_layer->thickness * 0.5;
start.y = -y * _preview_layer->thickness * 0.5; start.y = -y * _preview_layer->thickness * 0.5;
@ -103,8 +100,7 @@ protected:
end.y = -y * _preview_layer->thickness * 0.5; end.y = -y * _preview_layer->thickness * 0.5;
end.z = -_preview_layer->thickness * 0.5; end.z = -_preview_layer->thickness * 0.5;
color_layer = cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end); return cloudsApplyLayer(_preview_layer, COLOR_BLUE, &_renderer, start, end);
return colorToQColor(color_layer);
} }
void updateData() void updateData()
{ {

View file

@ -39,7 +39,7 @@ public:
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:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 down = {0.0, -1.0, 0.0}; Vector3 down = {0.0, -1.0, 0.0};
Vector3 location; Vector3 location;
@ -50,14 +50,14 @@ protected:
location.x = x; location.x = x;
location.y = _water.height; location.y = _water.height;
location.z = y; location.z = y;
return colorToQColor(waterGetColor(&_water, &_renderer, location, down)); return waterGetColor(&_water, &_renderer, location, down);
} }
else else
{ {
location.x = x; location.x = x;
location.y = height; location.y = height;
location.z = y; location.z = y;
return colorToQColor(_renderer.terrain->getFinalColor(&_renderer, location, scaling)); return _renderer.terrain->getFinalColor(&_renderer, location, scaling);
} }
} }
void updateData() void updateData()

View file

@ -22,9 +22,9 @@ public:
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:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling)); return terrainGetPreviewColor(&_renderer, x, -y, scaling);
} }
void updateData() void updateData()
{ {

View file

@ -35,15 +35,15 @@ public:
texturesLayerDeleteDefinition(_preview_layer); texturesLayerDeleteDefinition(_preview_layer);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 location; Vector3 location;
double coverage; Color result;
location.x = x; location.x = x;
location.y = _renderer.terrain->getHeight(&_renderer, x, y, 1); location.y = _renderer.terrain->getHeight(&_renderer, x, y, 1);
location.z = y; location.z = y;
coverage = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling); result.r = result.g = result.b = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling);
return QColor::fromRgbF(coverage, coverage, coverage, 1.0); return result;
} }
void updateData() void updateData()
{ {
@ -99,13 +99,13 @@ public:
texturesLayerDeleteDefinition(_preview_layer); texturesLayerDeleteDefinition(_preview_layer);
} }
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 location; Vector3 location;
location.x = x; location.x = x;
location.y = 0.0; location.y = 0.0;
location.z = y; location.z = y;
return colorToQColor(texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling)); return texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling);
} }
void updateData() void updateData()
{ {

View file

@ -31,14 +31,14 @@ public:
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:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
double height; double height;
height = _renderer.terrain->getHeight(&_renderer, x, -y, 1); height = _renderer.terrain->getHeight(&_renderer, x, -y, 1);
if (height > _definition.height) if (height > _definition.height)
{ {
return colorToQColor(terrainGetPreviewColor(&_renderer, x, -y, scaling)); return terrainGetPreviewColor(&_renderer, x, -y, scaling);
} }
else else
{ {
@ -61,7 +61,7 @@ protected:
colorMask(&base, &mask); colorMask(&base, &mask);
} }
return colorToQColor(base); return base;
} }
} }
void updateData() void updateData()
@ -127,7 +127,7 @@ public:
} }
int _background; int _background;
protected: protected:
QColor getColor(double x, double y) Color getColor(double x, double y)
{ {
Vector3 eye, look, location; Vector3 eye, look, location;
@ -141,7 +141,7 @@ protected:
if (look.y > -0.0001) if (look.y > -0.0001)
{ {
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color); return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color;
} }
location.x = eye.x - look.x * eye.y / look.y; location.x = eye.x - look.x * eye.y / look.y;
@ -150,10 +150,10 @@ protected:
if (location.z > 0.0) if (location.z > 0.0)
{ {
return colorToQColor(_rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color); return _rayWalking(&_renderer, eye, look, 0, 0, 0, 0).hit_color;
} }
return colorToQColor(waterGetColor(&_water, &_renderer, location, look)); return waterGetColor(&_water, &_renderer, location, look);
} }
void updateData() void updateData()
{ {
@ -183,7 +183,7 @@ private:
LightingDefinition _lighting; LightingDefinition _lighting;
bool _lighting_enabled; bool _lighting_enabled;
static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int terrain, int water, int sky, int clouds) static RayCastingResult _rayWalking(Renderer* renderer, Vector3 location, Vector3 direction, int, int, int, int)
{ {
RayCastingResult result; RayCastingResult result;
PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[2]; PreviewWaterColor* preview = (PreviewWaterColor*)renderer->customData[2];

View file

@ -16,7 +16,7 @@ public:
{ {
} }
void paintEvent(QPaintEvent* event) void paintEvent(QPaintEvent*)
{ {
if (!noise) if (!noise)
{ {

View file

@ -18,8 +18,8 @@ PreviewColorGradation::PreviewColorGradation(QWidget* parent, ColorGradation* gr
this->gradation = gradation; this->gradation = gradation;
this->band = band; this->band = band;
} }
void PreviewColorGradation::paintEvent(QPaintEvent* event) void PreviewColorGradation::paintEvent(QPaintEvent*)
{ {
Curve* curve; Curve* curve;
@ -67,7 +67,7 @@ void PreviewColorGradation::paintEvent(QPaintEvent* event)
curveDelete(curve); curveDelete(curve);
} }
void PreviewColorGradation::mouseReleaseEvent(QMouseEvent* event) void PreviewColorGradation::mouseReleaseEvent(QMouseEvent*)
{ {
emit clicked(); emit clicked();
} }

View file

@ -38,7 +38,7 @@ SmallMaterialPreview::~SmallMaterialPreview()
rendererDelete(&_renderer); rendererDelete(&_renderer);
} }
QColor SmallMaterialPreview::getColor(double x, double y) Color SmallMaterialPreview::getColor(double x, double y)
{ {
double dist = sqrt(x * x + y * y); double dist = sqrt(x * x + y * y);
Vector3 point; Vector3 point;
@ -46,7 +46,7 @@ QColor SmallMaterialPreview::getColor(double x, double y)
if (dist >= 1.0) if (dist >= 1.0)
{ {
return colorToQColor(COLOR_TRANSPARENT); return COLOR_TRANSPARENT;
} }
else else
{ {
@ -67,17 +67,17 @@ QColor SmallMaterialPreview::getColor(double x, double y)
{ {
color.a = (1.0 - dist) / 0.05; color.a = (1.0 - dist) / 0.05;
} }
return colorToQColor(color); return color;
} }
} }
void SmallMaterialPreview::paintEvent(QPaintEvent* event) void SmallMaterialPreview::paintEvent(QPaintEvent*)
{ {
QPainter painter(this); QPainter painter(this);
int width = this->width(); int width = this->width();
int height = this->height(); int height = this->height();
double factor, dx, dy; double factor, dx, dy;
if (width > height) if (width > height)
{ {
factor = 2.0 / (double)height; factor = 2.0 / (double)height;
@ -93,7 +93,7 @@ void SmallMaterialPreview::paintEvent(QPaintEvent* event)
{ {
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
painter.setPen(getColor((double)x * factor - dx, (double)y * factor - dy)); painter.setPen(colorToQColor(getColor((double)x * factor - dx, (double)y * factor - dy)));
painter.drawPoint(x, y); painter.drawPoint(x, y);
} }
} }
@ -105,7 +105,7 @@ PreviewMaterial::PreviewMaterial(QWidget* parent, SurfaceMaterial* material) : B
{ {
_small = new SmallMaterialPreview(this, material); _small = new SmallMaterialPreview(this, material);
_small->hide(); _small->hide();
configScaling(0.05, 2.0, 0.05, 2.0); configScaling(0.05, 2.0, 0.05, 2.0);
} }
@ -114,7 +114,7 @@ PreviewMaterial::~PreviewMaterial()
delete _small; delete _small;
} }
QColor PreviewMaterial::getColor(double x, double y) Color PreviewMaterial::getColor(double x, double y)
{ {
return _small->getColor(x, y); return _small->getColor(x, y);
} }

View file

@ -11,12 +11,12 @@ class SmallMaterialPreview:public QWidget
public: public:
SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material); SmallMaterialPreview(QWidget* parent, SurfaceMaterial* material);
~SmallMaterialPreview(); ~SmallMaterialPreview();
QColor getColor(double x, double y); Color getColor(double x, double y);
protected: protected:
virtual void paintEvent(QPaintEvent* event); virtual void paintEvent(QPaintEvent* event);
private: private:
SurfaceMaterial* _material; SurfaceMaterial* _material;
LightingDefinition _lighting; LightingDefinition _lighting;
@ -26,13 +26,13 @@ private:
class PreviewMaterial:public BasePreview class PreviewMaterial:public BasePreview
{ {
Q_OBJECT Q_OBJECT
public: public:
PreviewMaterial(QWidget* parent, SurfaceMaterial* material); PreviewMaterial(QWidget* parent, SurfaceMaterial* material);
~PreviewMaterial(); ~PreviewMaterial();
protected: protected:
virtual QColor getColor(double x, double y); virtual Color getColor(double x, double y);
private: private:
SmallMaterialPreview* _small; SmallMaterialPreview* _small;

View file

@ -10,12 +10,12 @@ WidgetCurveEditor::WidgetCurveEditor(QWidget *parent, double xmin, double xmax,
_curve = curveCreate(); _curve = curveCreate();
_dragged = -1; _dragged = -1;
_pen = QColor(0, 0, 0); _pen = QColor(0, 0, 0);
_xmin = xmin; _xmin = xmin;
_xmax = xmax; _xmax = xmax;
_ymin = ymin; _ymin = ymin;
_ymax = ymax; _ymax = ymax;
setMinimumSize(300, 300); setMinimumSize(300, 300);
} }
@ -47,22 +47,22 @@ void WidgetCurveEditor::setPenColor(QColor color)
update(); update();
} }
void WidgetCurveEditor::paintEvent(QPaintEvent* event) void WidgetCurveEditor::paintEvent(QPaintEvent*)
{ {
int i, n; int i, n;
int width, height; int width, height;
double dwidth, dheight; double dwidth, dheight;
CurvePoint point; CurvePoint point;
double position, value, prev_value, next_value; double position, value, prev_value, next_value;
width = this->width(); width = this->width();
height = this->height(); height = this->height();
dheight = (double)(height - 1); dheight = (double)(height - 1);
dwidth = (double)(width - 1); dwidth = (double)(width - 1);
QPainter painter(this); QPainter painter(this);
painter.fillRect(rect(), Qt::white); painter.fillRect(rect(), Qt::white);
// Draw grid // Draw grid
painter.setPen(QPen(Qt::lightGray)); painter.setPen(QPen(Qt::lightGray));
for (int x = 0; x <= 10; x++) for (int x = 0; x <= 10; x++)
@ -72,7 +72,7 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
vx = (x == 10) ? height - 1 : x * height / 10; vx = (x == 10) ? height - 1 : x * height / 10;
painter.drawLine(0, vx, width - 1, vx); painter.drawLine(0, vx, width - 1, vx);
} }
// Draw labels // Draw labels
painter.setPen(QColor(50, 50, 50)); painter.setPen(QColor(50, 50, 50));
if (not _xlabel.isEmpty()) if (not _xlabel.isEmpty())
@ -87,21 +87,21 @@ void WidgetCurveEditor::paintEvent(QPaintEvent* event)
painter.translate(height, 0.0); painter.translate(height, 0.0);
painter.rotate(90.0); painter.rotate(90.0);
} }
// Draw curve path // Draw curve path
painter.setPen(_pen); painter.setPen(_pen);
for (int x = 0; x < width; x++) for (int x = 0; x < width; x++)
{ {
position = ((double)x / dwidth) * (_xmax - _xmin) + _xmin; position = ((double)x / dwidth) * (_xmax - _xmin) + _xmin;
value = (curveGetValue(_curve, position) - _ymin) / (_ymax - _ymin); value = (curveGetValue(_curve, position) - _ymin) / (_ymax - _ymin);
prev_value = curveGetValue(_curve, position - (_xmax - _xmin) / dwidth); prev_value = curveGetValue(_curve, position - (_xmax - _xmin) / dwidth);
next_value = curveGetValue(_curve, position + (_xmax - _xmin) / dwidth); next_value = curveGetValue(_curve, position + (_xmax - _xmin) / dwidth);
painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * dheight), x, height - 1 - (int)((value + (next_value - value) / 2.0) * dheight)); painter.drawLine(x, height - 1 - (int)((value + (prev_value - value) / 2.0) * dheight), x, height - 1 - (int)((value + (next_value - value) / 2.0) * dheight));
painter.drawPoint(x, height - 1 - (int)(value * dheight)); painter.drawPoint(x, height - 1 - (int)(value * dheight));
} }
// Draw handles // Draw handles
n = curveGetPointCount(_curve); n = curveGetPointCount(_curve);
painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true); painter.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing, true);
@ -118,37 +118,37 @@ void WidgetCurveEditor::mousePressEvent(QMouseEvent* event)
{ {
_dragged = getPointAt(event->x(), event->y()); _dragged = getPointAt(event->x(), event->y());
} }
event->accept(); event->accept();
} }
void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event) void WidgetCurveEditor::mouseMoveEvent(QMouseEvent* event)
{ {
CurvePoint point; CurvePoint point;
if (_dragged >= 0 && (event->buttons() & Qt::LeftButton)) if (_dragged >= 0 && (event->buttons() & Qt::LeftButton))
{ {
screenToCurve(event->x(), event->y(), &point.position, &point.value); screenToCurve(event->x(), event->y(), &point.position, &point.value);
point.position = (point.position < _xmin) ? _xmin : point.position; point.position = (point.position < _xmin) ? _xmin : point.position;
point.position = (point.position > _xmax) ? _xmax : point.position; point.position = (point.position > _xmax) ? _xmax : point.position;
point.value = (point.value < _ymin) ? _ymin : point.value; point.value = (point.value < _ymin) ? _ymin : point.value;
point.value = (point.value > _ymax) ? _ymax : point.value; point.value = (point.value > _ymax) ? _ymax : point.value;
curveSetPoint(_curve, _dragged, &point); curveSetPoint(_curve, _dragged, &point);
update(); update();
emit liveChanged(); emit liveChanged();
} }
event->accept(); event->accept();
} }
void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event) void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event)
{ {
int clicked; int clicked;
if (event->button() == Qt::RightButton) if (event->button() == Qt::RightButton)
{ {
clicked = getPointAt(event->x(), event->y()); clicked = getPointAt(event->x(), event->y());
@ -165,14 +165,14 @@ void WidgetCurveEditor::mouseReleaseEvent(QMouseEvent* event)
curveValidate(_curve); curveValidate(_curve);
update(); update();
} }
event->accept(); event->accept();
} }
void WidgetCurveEditor::mouseDoubleClickEvent(QMouseEvent* event) void WidgetCurveEditor::mouseDoubleClickEvent(QMouseEvent* event)
{ {
CurvePoint point; CurvePoint point;
if (event->button() == Qt::LeftButton && _dragged < 0) if (event->button() == Qt::LeftButton && _dragged < 0)
{ {
if (getPointAt(event->x(), event->y()) < 0) if (getPointAt(event->x(), event->y()) < 0)
@ -205,7 +205,7 @@ int WidgetCurveEditor::getPointAt(int x, int y)
double distance, ndistance; double distance, ndistance;
CurvePoint point; CurvePoint point;
int dx, dy; int dx, dy;
n = curveGetPointCount(_curve); n = curveGetPointCount(_curve);
if (n < 1) if (n < 1)
{ {
@ -226,7 +226,7 @@ int WidgetCurveEditor::getPointAt(int x, int y)
nearest = i; nearest = i;
} }
} }
if (nearest >= 0 && distance < 5.0) if (nearest >= 0 && distance < 5.0)
{ {
return nearest; return nearest;

View file

@ -339,7 +339,7 @@ void WidgetExplorer::wheelEvent(QWheelEvent* event)
event->accept(); event->accept();
} }
void WidgetExplorer::timerEvent(QTimerEvent *event) void WidgetExplorer::timerEvent(QTimerEvent*)
{ {
if (_updated) if (_updated)
{ {

View file

@ -212,7 +212,7 @@ static double _opticalDepth(double H, double r, double mu, double d)
double ayq = ay * ay; double ayq = ay * ay;
double x = ays > axs ? exp(axq) : 0.0; double x = ays > axs ? exp(axq) : 0.0;
double yx = axs / (2.3193 * fabs(ax) + sqrt(1.52 * axq + 4.0)); double yx = axs / (2.3193 * fabs(ax) + sqrt(1.52 * axq + 4.0));
double yy = ays / (2.3193 * fabs(ay) + sqrt(1.52 * ayq + 4.0)) * exp(-d / H * (d / (2.0 * r) + mu)); double yy = ays / (2.3193 * fabs(ay) + sqrt(1.52 * ayq + 4.0)) * exp(-d / H * (d / (2.0 * r) + mu));
return sqrt((6.2831 * H) * r) * exp((Rg - r) / H) * (x + yx - yy); return sqrt((6.2831 * H) * r) * exp((Rg - r) / H) * (x + yx - yy);
} }
@ -286,11 +286,10 @@ static double _limit(double r, double mu)
static Vector3 _analyticTransmittance(double r, double mu, double d) static Vector3 _analyticTransmittance(double r, double mu, double d)
{ {
Vector3 result; Vector3 result;
double opt = _opticalDepth(HR, r, mu, d);
result.x = exp(-betaR.r * opt) - betaMEx.x * opt; result.x = exp(-betaR.r * _opticalDepth(HR, r, mu, d) - betaMEx.x * _opticalDepth(HM, r, mu, d));
result.y = exp(-betaR.g * opt) - betaMEx.y * opt; result.y = exp(-betaR.g * _opticalDepth(HR, r, mu, d) - betaMEx.y * _opticalDepth(HM, r, mu, d));
result.z = exp(-betaR.b * opt) - betaMEx.z * opt; result.z = exp(-betaR.b * _opticalDepth(HR, r, mu, d) - betaMEx.z * _opticalDepth(HM, r, mu, d));
return result; return result;
} }

View file

@ -135,6 +135,11 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
normal = m4Transform(rotation, normal); normal = m4Transform(rotation, normal);
hit = m4Transform(rotation, hit); hit = m4Transform(rotation, hit);
if (y == 0.0)
{
y = 0.0;
}
renderer->getLightStatus(renderer, &light, hit); renderer->getLightStatus(renderer, &light, hit);
color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL); color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL);

View file

@ -1,6 +1,6 @@
#include "memory.h" #include "memory.h"
#include <assert.h> #include <stdlib.h>
void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset) void* memory2dRealloc(void* data, int datasize, int oldxsize, int oldysize, int newxsize, int newysize, int xoffset, int yoffset)
{ {