Refactoring color
This commit is contained in:
parent
aed4f9d80e
commit
5be3231ab9
50 changed files with 779 additions and 624 deletions
28
src/basics/Color.cpp
Normal file
28
src/basics/Color.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include "Color.inline.cpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include "PackStream.h"
|
||||||
|
|
||||||
|
const Color paysages::basics::COLOR_TRANSPARENT = {0.0, 0.0, 0.0, 0.0};
|
||||||
|
const Color paysages::basics::COLOR_BLACK = {0.0, 0.0, 0.0, 1.0};
|
||||||
|
const Color paysages::basics::COLOR_RED = {1.0, 0.0, 0.0, 1.0};
|
||||||
|
const Color paysages::basics::COLOR_GREEN = {0.0, 1.0, 0.0, 1.0};
|
||||||
|
const Color paysages::basics::COLOR_BLUE = {0.0, 0.0, 1.0, 1.0};
|
||||||
|
const Color paysages::basics::COLOR_WHITE = {1.0, 1.0, 1.0, 1.0};
|
||||||
|
const Color paysages::basics::COLOR_GREY = {0.5, 0.5, 0.5, 1.0};
|
||||||
|
|
||||||
|
void Color::save(PackStream* stream) const
|
||||||
|
{
|
||||||
|
stream->write(&r);
|
||||||
|
stream->write(&g);
|
||||||
|
stream->write(&b);
|
||||||
|
stream->write(&a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Color::load(PackStream* stream)
|
||||||
|
{
|
||||||
|
stream->read(&r);
|
||||||
|
stream->read(&g);
|
||||||
|
stream->read(&b);
|
||||||
|
stream->read(&a);
|
||||||
|
}
|
126
src/basics/Color.h
Normal file
126
src/basics/Color.h
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
#ifndef COLOR_H
|
||||||
|
#define COLOR_H
|
||||||
|
|
||||||
|
#include "basics_global.h"
|
||||||
|
|
||||||
|
namespace paysages {
|
||||||
|
namespace basics {
|
||||||
|
|
||||||
|
class Color
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Color();
|
||||||
|
Color(double r, double g, double b, double a);
|
||||||
|
|
||||||
|
void save(PackStream* stream) const;
|
||||||
|
void load(PackStream* stream);
|
||||||
|
|
||||||
|
unsigned int to32BitRGBA() const;
|
||||||
|
unsigned int to32BitBGRA() const;
|
||||||
|
unsigned int to32BitARGB() const;
|
||||||
|
unsigned int to32BitABGR() const;
|
||||||
|
|
||||||
|
static Color from32BitRGBA(unsigned int col);
|
||||||
|
static Color from32BitBGRA(unsigned int col);
|
||||||
|
static Color from32BitARGB(unsigned int col);
|
||||||
|
static Color from32BitABGR(unsigned int col);
|
||||||
|
|
||||||
|
void mask(const Color& mask);
|
||||||
|
double normalize();
|
||||||
|
double getValue() const;
|
||||||
|
double getPower() const;
|
||||||
|
void limitPower(double max_power);
|
||||||
|
|
||||||
|
public:
|
||||||
|
double r;
|
||||||
|
double g;
|
||||||
|
double b;
|
||||||
|
double a;
|
||||||
|
};
|
||||||
|
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_TRANSPARENT;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_BLACK;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_RED;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_GREEN;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_BLUE;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_WHITE;
|
||||||
|
BASICSSHARED_EXPORT extern const Color COLOR_GREY;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inlining
|
||||||
|
#if PAYSAGES_USE_INLINING
|
||||||
|
#ifndef COLOR_INLINE_CPP
|
||||||
|
#include "Color.inline.cpp"
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Compat API
|
||||||
|
|
||||||
|
static inline void colorSave(PackStream* stream, Color* col)
|
||||||
|
{
|
||||||
|
col->save(stream);
|
||||||
|
}
|
||||||
|
static inline void colorLoad(PackStream* stream, Color* col)
|
||||||
|
{
|
||||||
|
col->load(stream);
|
||||||
|
}
|
||||||
|
static inline Color colorFromValues(double r, double g, double b, double a)
|
||||||
|
{
|
||||||
|
return Color(r, g, b, a);
|
||||||
|
}
|
||||||
|
static inline unsigned int colorTo32BitRGBA(Color* col)
|
||||||
|
{
|
||||||
|
return col->to32BitRGBA();
|
||||||
|
}
|
||||||
|
static inline unsigned int colorTo32BitBGRA(Color* col)
|
||||||
|
{
|
||||||
|
return col->to32BitBGRA();
|
||||||
|
}
|
||||||
|
static inline unsigned int colorTo32BitARGB(Color* col)
|
||||||
|
{
|
||||||
|
return col->to32BitARGB();
|
||||||
|
}
|
||||||
|
static inline unsigned int colorTo32BitABGR(Color* col)
|
||||||
|
{
|
||||||
|
return col->to32BitABGR();
|
||||||
|
}
|
||||||
|
static inline Color colorFrom32BitRGBA(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color::from32BitRGBA(col);
|
||||||
|
}
|
||||||
|
static inline Color colorFrom32BitBGRA(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color::from32BitBGRA(col);
|
||||||
|
}
|
||||||
|
static inline Color colorFrom32BitARGB(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color::from32BitARGB(col);
|
||||||
|
}
|
||||||
|
static inline Color colorFrom32BitABGR(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color::from32BitABGR(col);
|
||||||
|
}
|
||||||
|
static inline void colorMask(Color* base, Color* mask)
|
||||||
|
{
|
||||||
|
base->mask(*mask);
|
||||||
|
}
|
||||||
|
static inline double colorNormalize(Color* col)
|
||||||
|
{
|
||||||
|
return col->normalize();
|
||||||
|
}
|
||||||
|
static inline double colorGetValue(Color* col)
|
||||||
|
{
|
||||||
|
return col->getValue();
|
||||||
|
}
|
||||||
|
static inline double colorGetPower(Color* col)
|
||||||
|
{
|
||||||
|
return col->getPower();
|
||||||
|
}
|
||||||
|
static inline void colorLimitPower(Color* col, double max_power)
|
||||||
|
{
|
||||||
|
col->limitPower(max_power);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // COLOR_H
|
179
src/basics/Color.inline.cpp
Normal file
179
src/basics/Color.inline.cpp
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
#define COLOR_INLINE_CPP
|
||||||
|
|
||||||
|
#ifdef COLOR_H
|
||||||
|
# define METHSPEC inline
|
||||||
|
#else
|
||||||
|
# include "Color.h"
|
||||||
|
# define METHSPEC
|
||||||
|
#endif
|
||||||
|
|
||||||
|
METHSPEC Color::Color():
|
||||||
|
r(0.0), g(0.0), b(0.0), a(0.0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC Color::Color(double r, double g, double b, double a):
|
||||||
|
r(r), g(g), b(b), a(a)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC unsigned int Color::to32BitRGBA() const
|
||||||
|
{
|
||||||
|
return (((unsigned int) (a * 255.0)) << 24) | (((unsigned int) (b * 255.0)) << 16) | (((unsigned int) (g * 255.0)) << 8) | ((unsigned int) (r * 255.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC unsigned int Color::to32BitBGRA() const
|
||||||
|
{
|
||||||
|
return (((unsigned int) (a * 255.0)) << 24) | (((unsigned int) (r * 255.0)) << 16) | (((unsigned int) (g * 255.0)) << 8) | ((unsigned int) (b * 255.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC unsigned int Color::to32BitARGB() const
|
||||||
|
{
|
||||||
|
return (((unsigned int) (b * 255.0)) << 24) | (((unsigned int) (g * 255.0)) << 16) | (((unsigned int) (r * 255.0)) << 8) | ((unsigned int) (a * 255.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC unsigned int Color::to32BitABGR() const
|
||||||
|
{
|
||||||
|
return (((unsigned int) (r * 255.0)) << 24) | (((unsigned int) (g * 255.0)) << 16) | (((unsigned int) (b * 255.0)) << 8) | ((unsigned int) (a * 255.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC Color Color::from32BitRGBA(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color(
|
||||||
|
((double) (col & 0x000000FF)) / 255.0,
|
||||||
|
((double) ((col & 0x0000FF00) >> 8)) / 255.0,
|
||||||
|
((double) ((col & 0x00FF0000) >> 16)) / 255.0,
|
||||||
|
((double) ((col & 0xFF000000) >> 24)) / 255.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC Color Color::from32BitBGRA(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color(
|
||||||
|
((double) (col & 0x000000FF)) / 255.0,
|
||||||
|
((double) ((col & 0x0000FF00) >> 8)) / 255.0,
|
||||||
|
((double) ((col & 0x00FF0000) >> 16)) / 255.0,
|
||||||
|
((double) ((col & 0xFF000000) >> 24)) / 255.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC Color Color::from32BitARGB(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color(
|
||||||
|
((double) (col & 0x000000FF)) / 255.0,
|
||||||
|
((double) ((col & 0x0000FF00) >> 8)) / 255.0,
|
||||||
|
((double) ((col & 0x00FF0000) >> 16)) / 255.0,
|
||||||
|
((double) ((col & 0xFF000000) >> 24)) / 255.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC Color Color::from32BitABGR(unsigned int col)
|
||||||
|
{
|
||||||
|
return Color(
|
||||||
|
((double) (col & 0x000000FF)) / 255.0,
|
||||||
|
((double) ((col & 0x0000FF00) >> 8)) / 255.0,
|
||||||
|
((double) ((col & 0x00FF0000) >> 16)) / 255.0,
|
||||||
|
((double) ((col & 0xFF000000) >> 24)) / 255.0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC void Color::mask(const Color& mask)
|
||||||
|
{
|
||||||
|
double new_a;
|
||||||
|
new_a = a + mask.a - (a * mask.a);
|
||||||
|
r = (mask.r * mask.a + r * a - r * a * mask.a) / new_a;
|
||||||
|
g = (mask.g * mask.a + g * a - g * a * mask.a) / new_a;
|
||||||
|
b = (mask.b * mask.a + b * a - b * a * mask.a) / new_a;
|
||||||
|
a = new_a;
|
||||||
|
|
||||||
|
/*double mask_weight = mask->a;
|
||||||
|
double base_weight = 1.0 - mask_weight;
|
||||||
|
|
||||||
|
base->r = mask->r * mask_weight + base->r * base_weight;
|
||||||
|
base->g = mask->g * mask_weight + base->g * base_weight;
|
||||||
|
base->b = mask->b * mask_weight + base->b * base_weight;
|
||||||
|
base->a = base->a + mask_weight * (1.0 - base->a);*/
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC double Color::normalize()
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
assert(col->r >= 0.0);
|
||||||
|
assert(col->g >= 0.0);
|
||||||
|
assert(col->b >= 0.0);
|
||||||
|
assert(col->a >= 0.0);
|
||||||
|
#ifdef isnan
|
||||||
|
assert(!isnan(col->r));
|
||||||
|
assert(!isnan(col->g));
|
||||||
|
assert(!isnan(col->b));
|
||||||
|
assert(!isnan(col->a));
|
||||||
|
#endif
|
||||||
|
#ifdef isfinite
|
||||||
|
assert(isfinite(col->r));
|
||||||
|
assert(isfinite(col->g));
|
||||||
|
assert(isfinite(col->b));
|
||||||
|
assert(isfinite(col->a));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (r > 1.0)
|
||||||
|
{
|
||||||
|
r = 1.0;
|
||||||
|
}
|
||||||
|
if (g > 1.0)
|
||||||
|
{
|
||||||
|
g = 1.0;
|
||||||
|
}
|
||||||
|
if (b > 1.0)
|
||||||
|
{
|
||||||
|
b = 1.0;
|
||||||
|
}
|
||||||
|
return 1.0;
|
||||||
|
/*double max = colorGetValue(col);
|
||||||
|
|
||||||
|
assert(max >= 0.0);
|
||||||
|
|
||||||
|
if (max > 1.0)
|
||||||
|
{
|
||||||
|
col->r /= max;
|
||||||
|
col->g /= max;
|
||||||
|
col->b /= max;
|
||||||
|
}
|
||||||
|
return max;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC double Color::getValue() const
|
||||||
|
{
|
||||||
|
double max;
|
||||||
|
|
||||||
|
max = r;
|
||||||
|
if (g > max)
|
||||||
|
{
|
||||||
|
max = g;
|
||||||
|
}
|
||||||
|
if (b > max)
|
||||||
|
{
|
||||||
|
max = b;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC double Color::getPower() const
|
||||||
|
{
|
||||||
|
return r + g + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHSPEC void Color::limitPower(double max_power)
|
||||||
|
{
|
||||||
|
double power = r + g + b;
|
||||||
|
|
||||||
|
if (power > max_power)
|
||||||
|
{
|
||||||
|
double factor = max_power / power;
|
||||||
|
|
||||||
|
r *= factor;
|
||||||
|
g *= factor;
|
||||||
|
b *= factor;
|
||||||
|
}
|
||||||
|
}
|
88
src/basics/ColorHSL.cpp
Normal file
88
src/basics/ColorHSL.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "ColorHSL.h"
|
||||||
|
|
||||||
|
#include "Color.h"
|
||||||
|
|
||||||
|
static double _hue2rgb(double p, double q, double t)
|
||||||
|
{
|
||||||
|
if (t < 0.0) t += 1;
|
||||||
|
if (t > 1.0) t -= 1;
|
||||||
|
if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;
|
||||||
|
if (t < 1.0 / 2.0) return q;
|
||||||
|
if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color colorFromHSL(ColorHSL col)
|
||||||
|
{
|
||||||
|
Color result;
|
||||||
|
|
||||||
|
if (col.s == 0)
|
||||||
|
{
|
||||||
|
result.r = result.g = result.b = col.l;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double q = col.l < 0.5 ? col.l * (1.0 + col.s) : col.l + col.s - col.l * col.s;
|
||||||
|
double p = 2 * col.l - q;
|
||||||
|
result.r = _hue2rgb(p, q, col.h + 1.0 / 3.0);
|
||||||
|
result.g = _hue2rgb(p, q, col.h);
|
||||||
|
result.b = _hue2rgb(p, q, col.h - 1.0 / 3.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.a = col.a;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorHSL colorToHSL(Color col)
|
||||||
|
{
|
||||||
|
ColorHSL result;
|
||||||
|
double min, max;
|
||||||
|
|
||||||
|
max = col.r > col.g ? col.r : col.g;
|
||||||
|
max = col.b > max ? col.b : max;
|
||||||
|
|
||||||
|
min = col.r < col.g ? col.r : col.g;
|
||||||
|
min = col.b < min ? col.b : min;
|
||||||
|
|
||||||
|
result.h = result.s = result.l = (max + min) / 2.0;
|
||||||
|
|
||||||
|
if (max == min)
|
||||||
|
{
|
||||||
|
result.h = result.s = 0.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double d = max - min;
|
||||||
|
result.s = result.l > 0.5 ? d / (2.0 - max - min) : d / (max + min);
|
||||||
|
if (max == col.r)
|
||||||
|
{
|
||||||
|
result.h = (col.g - col.b) / d + (col.g < col.b ? 6.0 : 0);
|
||||||
|
}
|
||||||
|
else if (max == col.g)
|
||||||
|
{
|
||||||
|
result.h = (col.b - col.r) / d + 2.0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.h = (col.r - col.g) / d + 4.0;
|
||||||
|
}
|
||||||
|
result.h /= 6.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.a = col.a;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
ColorHSL colorHSLFromValues(double h, double s, double l, double a)
|
||||||
|
{
|
||||||
|
ColorHSL result;
|
||||||
|
|
||||||
|
result.h = h;
|
||||||
|
result.s = s;
|
||||||
|
result.l = l;
|
||||||
|
result.a = a;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
19
src/basics/ColorHSL.h
Normal file
19
src/basics/ColorHSL.h
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef COLORHSL_H
|
||||||
|
#define COLORHSL_H
|
||||||
|
|
||||||
|
#include "basics_global.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
double h;
|
||||||
|
double s;
|
||||||
|
double l;
|
||||||
|
double a;
|
||||||
|
} ColorHSL;
|
||||||
|
|
||||||
|
BASICSSHARED_EXPORT Color colorFromHSL(ColorHSL col);
|
||||||
|
BASICSSHARED_EXPORT ColorHSL colorToHSL(Color col);
|
||||||
|
|
||||||
|
BASICSSHARED_EXPORT ColorHSL colorHSLFromValues(double h, double s, double l, double a);
|
||||||
|
|
||||||
|
#endif // COLORHSL_H
|
|
@ -21,7 +21,10 @@ SOURCES += \
|
||||||
Interpolation.cpp \
|
Interpolation.cpp \
|
||||||
Vector3.cpp \
|
Vector3.cpp \
|
||||||
Vector3.inline.cpp \
|
Vector3.inline.cpp \
|
||||||
SpaceSegment.cpp
|
SpaceSegment.cpp \
|
||||||
|
Color.cpp \
|
||||||
|
Color.inline.cpp \
|
||||||
|
ColorHSL.cpp
|
||||||
|
|
||||||
HEADERS +=\
|
HEADERS +=\
|
||||||
basics_global.h \
|
basics_global.h \
|
||||||
|
@ -31,7 +34,9 @@ HEADERS +=\
|
||||||
NoiseFunctionSimplex.h \
|
NoiseFunctionSimplex.h \
|
||||||
Interpolation.h \
|
Interpolation.h \
|
||||||
Vector3.h \
|
Vector3.h \
|
||||||
SpaceSegment.h
|
SpaceSegment.h \
|
||||||
|
Color.h \
|
||||||
|
ColorHSL.h
|
||||||
|
|
||||||
unix:!symbian {
|
unix:!symbian {
|
||||||
maemo5 {
|
maemo5 {
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace paysages {
|
||||||
namespace basics {
|
namespace basics {
|
||||||
class Vector3;
|
class Vector3;
|
||||||
class SpaceSegment;
|
class SpaceSegment;
|
||||||
|
class Color;
|
||||||
class NoiseGenerator;
|
class NoiseGenerator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ void BaseDefinition::setName(QString name)
|
||||||
this->name = name;
|
this->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseDefinition::save(PackStream* pack)
|
void BaseDefinition::save(PackStream* pack) const
|
||||||
{
|
{
|
||||||
pack->write(name);
|
pack->write(name);
|
||||||
QListIterator<BaseDefinition*> it(children);
|
QListIterator<BaseDefinition*> it(children);
|
||||||
|
@ -49,7 +49,7 @@ void BaseDefinition::load(PackStream* pack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseDefinition::copy(BaseDefinition* destination)
|
void BaseDefinition::copy(BaseDefinition* destination) const
|
||||||
{
|
{
|
||||||
destination->setName(name);
|
destination->setName(name);
|
||||||
// can't copy children as we don't know their types...
|
// can't copy children as we don't know their types...
|
||||||
|
|
|
@ -19,17 +19,17 @@ public:
|
||||||
BaseDefinition(BaseDefinition* parent);
|
BaseDefinition(BaseDefinition* parent);
|
||||||
virtual ~BaseDefinition();
|
virtual ~BaseDefinition();
|
||||||
|
|
||||||
virtual void save(PackStream* pack);
|
virtual void save(PackStream* pack) const;
|
||||||
virtual void load(PackStream* pack);
|
virtual void load(PackStream* pack);
|
||||||
|
|
||||||
virtual void copy(BaseDefinition* destination);
|
virtual void copy(BaseDefinition* destination) const;
|
||||||
virtual void validate();
|
virtual void validate();
|
||||||
|
|
||||||
inline const QString& getName() {return name;}
|
inline const QString& getName() const {return name;}
|
||||||
virtual void setName(QString name);
|
virtual void setName(QString name);
|
||||||
|
|
||||||
inline const BaseDefinition* getParent() {return parent;}
|
inline const BaseDefinition* getParent() const {return parent;}
|
||||||
inline const BaseDefinition* getRoot() {return root;}
|
inline const BaseDefinition* getRoot() const {return root;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addChild(BaseDefinition* child);
|
void addChild(BaseDefinition* child);
|
||||||
|
|
|
@ -17,7 +17,7 @@ Layers::~Layers()
|
||||||
delete null_layer;
|
delete null_layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layers::copy(BaseDefinition* destination_)
|
void Layers::copy(BaseDefinition* destination_) const
|
||||||
{
|
{
|
||||||
Layers* destination = (Layers*)destination_;
|
Layers* destination = (Layers*)destination_;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
Layers(BaseDefinition* parent, LayerConstructor layer_constructor, LayerType* legacy_type=0);
|
Layers(BaseDefinition* parent, LayerConstructor layer_constructor, LayerType* legacy_type=0);
|
||||||
virtual ~Layers();
|
virtual ~Layers();
|
||||||
|
|
||||||
virtual void copy(BaseDefinition* destination);
|
virtual void copy(BaseDefinition* destination) const override;
|
||||||
|
|
||||||
void setMaxLayerCount(int max_layer_count);
|
void setMaxLayerCount(int max_layer_count);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ LegacyLayer::~LegacyLayer()
|
||||||
type.callback_delete(legacy);
|
type.callback_delete(legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyLayer::save(PackStream* pack)
|
void LegacyLayer::save(PackStream* pack) const
|
||||||
{
|
{
|
||||||
BaseDefinition::save(pack);
|
BaseDefinition::save(pack);
|
||||||
type.callback_save(pack, legacy);
|
type.callback_save(pack, legacy);
|
||||||
|
@ -24,7 +24,7 @@ void LegacyLayer::load(PackStream* pack)
|
||||||
type.callback_load(pack, legacy);
|
type.callback_load(pack, legacy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyLayer::copy(BaseDefinition* destination)
|
void LegacyLayer::copy(BaseDefinition* destination) const
|
||||||
{
|
{
|
||||||
BaseDefinition::copy(destination);
|
BaseDefinition::copy(destination);
|
||||||
type.callback_copy(legacy, ((LegacyLayer*)destination)->legacy);
|
type.callback_copy(legacy, ((LegacyLayer*)destination)->legacy);
|
||||||
|
|
|
@ -32,10 +32,10 @@ public:
|
||||||
LegacyLayer(BaseDefinition* parent, LayerType* type);
|
LegacyLayer(BaseDefinition* parent, LayerType* type);
|
||||||
virtual ~LegacyLayer();
|
virtual ~LegacyLayer();
|
||||||
|
|
||||||
virtual void save(PackStream* pack);
|
virtual void save(PackStream* pack) const;
|
||||||
virtual void load(PackStream* pack);
|
virtual void load(PackStream* pack);
|
||||||
|
|
||||||
virtual void copy(BaseDefinition* destination);
|
virtual void copy(BaseDefinition* destination) const;
|
||||||
virtual void validate();
|
virtual void validate();
|
||||||
|
|
||||||
virtual void setName(QString name);
|
virtual void setName(QString name);
|
||||||
|
|
36
src/definition/SurfaceMaterial.cpp
Normal file
36
src/definition/SurfaceMaterial.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
|
#include "PackStream.h"
|
||||||
|
|
||||||
|
void materialSave(PackStream* stream, SurfaceMaterial* material)
|
||||||
|
{
|
||||||
|
stream->write(&material->base.h);
|
||||||
|
stream->write(&material->base.l);
|
||||||
|
stream->write(&material->base.s);
|
||||||
|
|
||||||
|
stream->write(&material->hardness);
|
||||||
|
stream->write(&material->reflection);
|
||||||
|
stream->write(&material->shininess);
|
||||||
|
|
||||||
|
stream->write(&material->receive_shadows);
|
||||||
|
}
|
||||||
|
|
||||||
|
void materialLoad(PackStream* stream, SurfaceMaterial* material)
|
||||||
|
{
|
||||||
|
stream->read(&material->base.h);
|
||||||
|
stream->read(&material->base.l);
|
||||||
|
stream->read(&material->base.s);
|
||||||
|
|
||||||
|
stream->read(&material->hardness);
|
||||||
|
stream->read(&material->reflection);
|
||||||
|
stream->read(&material->shininess);
|
||||||
|
|
||||||
|
stream->read(&material->receive_shadows);
|
||||||
|
|
||||||
|
materialValidate(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
void materialValidate(SurfaceMaterial* material)
|
||||||
|
{
|
||||||
|
material->_rgb = colorFromHSL(material->base);
|
||||||
|
}
|
34
src/definition/SurfaceMaterial.h
Normal file
34
src/definition/SurfaceMaterial.h
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#ifndef SURFACEMATERIAL_H
|
||||||
|
#define SURFACEMATERIAL_H
|
||||||
|
|
||||||
|
#include "definition_global.h"
|
||||||
|
|
||||||
|
// TODO Change to pointers and forward declaration
|
||||||
|
#include "ColorHSL.h"
|
||||||
|
#include "Color.h"
|
||||||
|
|
||||||
|
namespace paysages {
|
||||||
|
namespace definition {
|
||||||
|
|
||||||
|
class DEFINITIONSHARED_EXPORT SurfaceMaterial
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ColorHSL base;
|
||||||
|
|
||||||
|
double hardness;
|
||||||
|
double reflection;
|
||||||
|
double shininess;
|
||||||
|
|
||||||
|
double receive_shadows;
|
||||||
|
|
||||||
|
Color _rgb;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DEFINITIONSHARED_EXPORT void materialSave(PackStream* stream, SurfaceMaterial* material);
|
||||||
|
DEFINITIONSHARED_EXPORT void materialLoad(PackStream* stream, SurfaceMaterial* material);
|
||||||
|
DEFINITIONSHARED_EXPORT void materialValidate(SurfaceMaterial* material);
|
||||||
|
|
||||||
|
#endif // SURFACEMATERIAL_H
|
113
src/definition/WaterDefinition.cpp
Normal file
113
src/definition/WaterDefinition.cpp
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
|
||||||
|
#include "PackStream.h"
|
||||||
|
#include "NoiseGenerator.h"
|
||||||
|
#include "Color.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
|
WaterDefinition::WaterDefinition(BaseDefinition* parent):
|
||||||
|
BaseDefinition(parent)
|
||||||
|
{
|
||||||
|
material = new SurfaceMaterial;
|
||||||
|
depth_color = new Color;
|
||||||
|
foam_material = new SurfaceMaterial;
|
||||||
|
_waves_noise = new NoiseGenerator;
|
||||||
|
|
||||||
|
//waterAutoPreset(this, WATER_PRESET_LAKE);
|
||||||
|
}
|
||||||
|
|
||||||
|
WaterDefinition::~WaterDefinition()
|
||||||
|
{
|
||||||
|
delete material;
|
||||||
|
delete depth_color;
|
||||||
|
delete foam_material;
|
||||||
|
delete _waves_noise;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaterDefinition::save(PackStream* stream) const
|
||||||
|
{
|
||||||
|
BaseDefinition::save(stream);
|
||||||
|
|
||||||
|
materialSave(stream, material);
|
||||||
|
colorSave(stream, depth_color);
|
||||||
|
stream->write(&transparency_depth);
|
||||||
|
stream->write(&transparency);
|
||||||
|
stream->write(&reflection);
|
||||||
|
stream->write(&lighting_depth);
|
||||||
|
|
||||||
|
stream->write(&scaling);
|
||||||
|
stream->write(&waves_height);
|
||||||
|
stream->write(&detail_height);
|
||||||
|
stream->write(&turbulence);
|
||||||
|
|
||||||
|
stream->write(&foam_coverage);
|
||||||
|
materialSave(stream, foam_material);
|
||||||
|
|
||||||
|
_waves_noise->save(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaterDefinition::load(PackStream* stream)
|
||||||
|
{
|
||||||
|
BaseDefinition::load(stream);
|
||||||
|
|
||||||
|
materialLoad(stream, material);
|
||||||
|
colorLoad(stream, depth_color);
|
||||||
|
stream->read(&transparency_depth);
|
||||||
|
stream->read(&transparency);
|
||||||
|
stream->read(&reflection);
|
||||||
|
stream->read(&lighting_depth);
|
||||||
|
|
||||||
|
stream->read(&scaling);
|
||||||
|
stream->read(&waves_height);
|
||||||
|
stream->read(&detail_height);
|
||||||
|
stream->read(&turbulence);
|
||||||
|
|
||||||
|
stream->read(&foam_coverage);
|
||||||
|
materialLoad(stream, foam_material);
|
||||||
|
|
||||||
|
_waves_noise->load(stream);
|
||||||
|
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaterDefinition::copy(BaseDefinition* _destination) const
|
||||||
|
{
|
||||||
|
BaseDefinition::copy(_destination);
|
||||||
|
|
||||||
|
WaterDefinition* destination = (WaterDefinition*)_destination;
|
||||||
|
*destination->material = *material;
|
||||||
|
*destination->depth_color = *depth_color;
|
||||||
|
destination->transparency_depth = transparency_depth;
|
||||||
|
destination->transparency = transparency;
|
||||||
|
destination->reflection = reflection;
|
||||||
|
destination->lighting_depth = lighting_depth;
|
||||||
|
destination->scaling = scaling;
|
||||||
|
destination->waves_height = waves_height;
|
||||||
|
destination->detail_height = detail_height;
|
||||||
|
destination->turbulence = turbulence;
|
||||||
|
destination->foam_coverage = foam_coverage;
|
||||||
|
*destination->foam_material = *foam_material;
|
||||||
|
_waves_noise->copy(destination->_waves_noise);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaterDefinition::validate()
|
||||||
|
{
|
||||||
|
BaseDefinition::validate();
|
||||||
|
|
||||||
|
double scaling = this->scaling * 0.3;
|
||||||
|
|
||||||
|
_waves_noise->clearLevels();
|
||||||
|
if (waves_height > 0.0)
|
||||||
|
{
|
||||||
|
_waves_noise->addLevelsSimple(2, scaling, -waves_height * scaling * 0.015, waves_height * scaling * 0.015, 0.5);
|
||||||
|
}
|
||||||
|
if (detail_height > 0.0)
|
||||||
|
{
|
||||||
|
_waves_noise->addLevelsSimple(3, scaling * 0.1, -detail_height * scaling * 0.015, detail_height * scaling * 0.015, 0.5);
|
||||||
|
}
|
||||||
|
_waves_noise->setFunctionParams(NOISE_FUNCTION_SIMPLEX, -turbulence, 0.0);
|
||||||
|
_waves_noise->validate();
|
||||||
|
|
||||||
|
materialValidate(material);
|
||||||
|
materialValidate(foam_material);
|
||||||
|
}
|
45
src/definition/WaterDefinition.h
Normal file
45
src/definition/WaterDefinition.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef WATERDEFINITION_H
|
||||||
|
#define WATERDEFINITION_H
|
||||||
|
|
||||||
|
#include "definition_global.h"
|
||||||
|
|
||||||
|
#include "BaseDefinition.h"
|
||||||
|
|
||||||
|
namespace paysages {
|
||||||
|
namespace definition {
|
||||||
|
|
||||||
|
class WaterDefinition: public BaseDefinition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WaterDefinition(BaseDefinition* parent);
|
||||||
|
virtual ~WaterDefinition();
|
||||||
|
|
||||||
|
virtual void save(PackStream* stream) const override;
|
||||||
|
virtual void load(PackStream* stream) override;
|
||||||
|
|
||||||
|
virtual void copy(BaseDefinition* destination) const override;
|
||||||
|
virtual void validate() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
double transparency;
|
||||||
|
double reflection;
|
||||||
|
SurfaceMaterial* material;
|
||||||
|
Color* depth_color;
|
||||||
|
double transparency_depth;
|
||||||
|
double lighting_depth;
|
||||||
|
|
||||||
|
double scaling;
|
||||||
|
double turbulence;
|
||||||
|
double waves_height;
|
||||||
|
double detail_height;
|
||||||
|
|
||||||
|
double foam_coverage;
|
||||||
|
SurfaceMaterial* foam_material;
|
||||||
|
|
||||||
|
NoiseGenerator* _waves_noise;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WATERDEFINITION_H
|
|
@ -16,13 +16,17 @@ include(../common.pri)
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
BaseDefinition.cpp \
|
BaseDefinition.cpp \
|
||||||
Layers.cpp \
|
Layers.cpp \
|
||||||
LegacyLayer.cpp
|
LegacyLayer.cpp \
|
||||||
|
WaterDefinition.cpp \
|
||||||
|
SurfaceMaterial.cpp
|
||||||
|
|
||||||
HEADERS +=\
|
HEADERS +=\
|
||||||
definition_global.h \
|
definition_global.h \
|
||||||
BaseDefinition.h \
|
BaseDefinition.h \
|
||||||
Layers.h \
|
Layers.h \
|
||||||
LegacyLayer.h
|
LegacyLayer.h \
|
||||||
|
WaterDefinition.h \
|
||||||
|
SurfaceMaterial.h
|
||||||
|
|
||||||
unix:!symbian {
|
unix:!symbian {
|
||||||
maemo5 {
|
maemo5 {
|
||||||
|
|
|
@ -10,9 +10,12 @@
|
||||||
|
|
||||||
#include "basics_global.h"
|
#include "basics_global.h"
|
||||||
|
|
||||||
namespace paysages
|
namespace paysages {
|
||||||
{
|
namespace definition {
|
||||||
namespace definition {}
|
class BaseDefinition;
|
||||||
|
class SurfaceMaterial;
|
||||||
|
class WaterDefinition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
using namespace paysages::definition;
|
using namespace paysages::definition;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "BasePreview.h"
|
#include "BasePreview.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
|
||||||
static WaterDefinition* _definition;
|
static WaterDefinition* _definition;
|
||||||
|
|
||||||
|
@ -236,7 +237,7 @@ BaseForm(parent)
|
||||||
addAutoPreset(tr("Lake surface"));
|
addAutoPreset(tr("Lake surface"));
|
||||||
addAutoPreset(tr("Standard sea"));
|
addAutoPreset(tr("Standard sea"));
|
||||||
|
|
||||||
_definition = (WaterDefinition*) WaterDefinitionClass.create();
|
_definition = new WaterDefinition(NULL);
|
||||||
|
|
||||||
previewCoverage = new PreviewWaterCoverage(this);
|
previewCoverage = new PreviewWaterCoverage(this);
|
||||||
previewColor = new PreviewWaterColor(this);
|
previewColor = new PreviewWaterColor(this);
|
||||||
|
@ -244,8 +245,8 @@ BaseForm(parent)
|
||||||
addPreview(previewColor, tr("Rendered preview"));
|
addPreview(previewColor, tr("Rendered preview"));
|
||||||
|
|
||||||
//addInputDouble(tr("Height"), &_definition->height, -15.0, 15.0, 0.1, 1.0);
|
//addInputDouble(tr("Height"), &_definition->height, -15.0, 15.0, 0.1, 1.0);
|
||||||
addInputMaterial(tr("Surface material"), &_definition->material);
|
addInputMaterial(tr("Surface material"), _definition->material);
|
||||||
addInputColor(tr("Depth color"), &_definition->depth_color);
|
addInputColor(tr("Depth color"), _definition->depth_color);
|
||||||
addInputDouble(tr("Transparency"), &_definition->transparency, 0.0, 1.0, 0.001, 0.1);
|
addInputDouble(tr("Transparency"), &_definition->transparency, 0.0, 1.0, 0.001, 0.1);
|
||||||
addInputDouble(tr("Reflection"), &_definition->reflection, 0.0, 1.0, 0.001, 0.1);
|
addInputDouble(tr("Reflection"), &_definition->reflection, 0.0, 1.0, 0.001, 0.1);
|
||||||
addInputDouble(tr("Transparency distance"), &_definition->transparency_depth, 0.0, 20.0, 0.1, 1.0);
|
addInputDouble(tr("Transparency distance"), &_definition->transparency_depth, 0.0, 20.0, 0.1, 1.0);
|
||||||
|
@ -255,7 +256,7 @@ BaseForm(parent)
|
||||||
addInputDouble(tr("Waves detail"), &_definition->detail_height, 0.0, 0.3, 0.003, 0.03);
|
addInputDouble(tr("Waves detail"), &_definition->detail_height, 0.0, 0.3, 0.003, 0.03);
|
||||||
addInputDouble(tr("Waves turbulence"), &_definition->turbulence, 0.0, 0.5, 0.005, 0.05);
|
addInputDouble(tr("Waves turbulence"), &_definition->turbulence, 0.0, 0.5, 0.005, 0.05);
|
||||||
addInputDouble(tr("Foam coverage"), &_definition->foam_coverage, 0.0, 1.0, 0.01, 0.1);
|
addInputDouble(tr("Foam coverage"), &_definition->foam_coverage, 0.0, 1.0, 0.01, 0.1);
|
||||||
addInputMaterial(tr("Foam material"), &_definition->foam_material);
|
addInputMaterial(tr("Foam material"), _definition->foam_material);
|
||||||
|
|
||||||
revertConfig();
|
revertConfig();
|
||||||
}
|
}
|
||||||
|
@ -274,7 +275,7 @@ void FormWater::applyConfig()
|
||||||
|
|
||||||
void FormWater::configChangeEvent()
|
void FormWater::configChangeEvent()
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.validate(_definition);
|
_definition->validate();
|
||||||
BaseForm::configChangeEvent();
|
BaseForm::configChangeEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "tools/lighting.h"
|
#include "tools/lighting.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class DialogMaterialEditor;
|
class DialogMaterialEditor;
|
||||||
|
|
|
@ -388,7 +388,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BasePreview</class>
|
<class>BasePreview</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>basepreview.h</header>
|
<header>BasePreview.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
#include "ColorHSL.h"
|
||||||
|
|
||||||
SmallPreviewHues::SmallPreviewHues(QWidget* parent) : DrawingWidget(parent)
|
SmallPreviewHues::SmallPreviewHues(QWidget* parent) : DrawingWidget(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -516,7 +516,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BasePreview</class>
|
<class>BasePreview</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>basepreview.h</header>
|
<header>BasePreview.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include <GL/glu.h>
|
#include <GL/glu.h>
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "water/public.h"
|
#include "WaterDefinition.h"
|
||||||
|
|
||||||
#define HEIGHTMAP_RESOLUTION 256
|
#define HEIGHTMAP_RESOLUTION 256
|
||||||
|
|
||||||
|
@ -29,10 +29,7 @@ QGLWidget(parent)
|
||||||
_water = true;
|
_water = true;
|
||||||
_wireframe = true;
|
_wireframe = true;
|
||||||
_painted_area = true;
|
_painted_area = true;
|
||||||
WaterDefinition* water_definition = (WaterDefinition*)WaterDefinitionClass.create();
|
|
||||||
sceneryGetWater(water_definition);
|
|
||||||
_water_height = 0.0;
|
_water_height = 0.0;
|
||||||
WaterDefinitionClass.destroy(water_definition);
|
|
||||||
|
|
||||||
_average_frame_time = 0.0;
|
_average_frame_time = 0.0;
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BasePreview</class>
|
<class>BasePreview</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>basepreview.h</header>
|
<header>BasePreview.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -440,7 +440,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>BasePreview</class>
|
<class>BasePreview</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>basepreview.h</header>
|
<header>BasePreview.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include "Scenery.h"
|
#include "Scenery.h"
|
||||||
#include "SoftwareRenderer.h"
|
#include "SoftwareRenderer.h"
|
||||||
#include "OpenGLRenderer.h"
|
#include "OpenGLRenderer.h"
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
#include "rendering/tools/euclid.h"
|
#include "rendering/tools/euclid.h"
|
||||||
#include "rendering/renderer.h"
|
#include "rendering/renderer.h"
|
||||||
#include "rendering/camera.h"
|
#include "rendering/camera.h"
|
||||||
|
@ -422,7 +424,7 @@ void WidgetExplorer::paintGL()
|
||||||
// Render water
|
// Render water
|
||||||
double water_height = _renderer->terrain->getWaterHeight(_renderer);
|
double water_height = _renderer->terrain->getWaterHeight(_renderer);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glColor3f(water->material._rgb.r, water->material._rgb.g, water->material._rgb.b);
|
glColor3f(water->material->_rgb.r, water->material->_rgb.g, water->material->_rgb.b);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glVertex3f(camera_location.x - 500.0, water_height, camera_location.z - 500.0);
|
glVertex3f(camera_location.x - 500.0, water_height, camera_location.z - 500.0);
|
||||||
glVertex3f(camera_location.x - 500.0, water_height, camera_location.z + 500.0);
|
glVertex3f(camera_location.x - 500.0, water_height, camera_location.z + 500.0);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "AtmosphereRenderer.h"
|
#include "AtmosphereRenderer.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "tools/lighting.h"
|
#include "tools/lighting.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Atmosphere previews.
|
* Atmosphere previews.
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "water/public.h"
|
#include "water/public.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "terrain/ter_raster.h"
|
#include "terrain/ter_raster.h"
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
|
||||||
static Scenery* _main_scenery;
|
static Scenery* _main_scenery;
|
||||||
static SceneryCustomDataCallback _custom_save = NULL;
|
static SceneryCustomDataCallback _custom_save = NULL;
|
||||||
|
@ -26,17 +27,21 @@ Scenery::Scenery():
|
||||||
clouds = (CloudsDefinition*)CloudsDefinitionClass.create();
|
clouds = (CloudsDefinition*)CloudsDefinitionClass.create();
|
||||||
terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
|
||||||
textures = (TexturesDefinition*)TexturesDefinitionClass.create();
|
textures = (TexturesDefinition*)TexturesDefinitionClass.create();
|
||||||
water = (WaterDefinition*)WaterDefinitionClass.create();
|
water = new WaterDefinition(this);
|
||||||
|
|
||||||
|
addChild(water);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenery::~Scenery()
|
Scenery::~Scenery()
|
||||||
{
|
{
|
||||||
|
removeChild(water);
|
||||||
|
|
||||||
AtmosphereDefinitionClass.destroy(atmosphere);
|
AtmosphereDefinitionClass.destroy(atmosphere);
|
||||||
cameraDeleteDefinition(camera);
|
cameraDeleteDefinition(camera);
|
||||||
CloudsDefinitionClass.destroy(clouds);
|
CloudsDefinitionClass.destroy(clouds);
|
||||||
TerrainDefinitionClass.destroy(terrain);
|
TerrainDefinitionClass.destroy(terrain);
|
||||||
TexturesDefinitionClass.destroy(textures);
|
TexturesDefinitionClass.destroy(textures);
|
||||||
WaterDefinitionClass.destroy(water);
|
delete water;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scenery* Scenery::getCurrent()
|
Scenery* Scenery::getCurrent()
|
||||||
|
@ -44,7 +49,7 @@ Scenery* Scenery::getCurrent()
|
||||||
return _main_scenery;
|
return _main_scenery;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::save(PackStream* stream)
|
void Scenery::save(PackStream* stream) const
|
||||||
{
|
{
|
||||||
BaseDefinition::save(stream);
|
BaseDefinition::save(stream);
|
||||||
|
|
||||||
|
@ -53,7 +58,6 @@ void Scenery::save(PackStream* stream)
|
||||||
CloudsDefinitionClass.save(stream, clouds);
|
CloudsDefinitionClass.save(stream, clouds);
|
||||||
TerrainDefinitionClass.save(stream, terrain);
|
TerrainDefinitionClass.save(stream, terrain);
|
||||||
TexturesDefinitionClass.save(stream, textures);
|
TexturesDefinitionClass.save(stream, textures);
|
||||||
WaterDefinitionClass.save(stream, water);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::load(PackStream* stream)
|
void Scenery::load(PackStream* stream)
|
||||||
|
@ -65,7 +69,6 @@ void Scenery::load(PackStream* stream)
|
||||||
CloudsDefinitionClass.load(stream, clouds);
|
CloudsDefinitionClass.load(stream, clouds);
|
||||||
TerrainDefinitionClass.load(stream, terrain);
|
TerrainDefinitionClass.load(stream, terrain);
|
||||||
TexturesDefinitionClass.load(stream, textures);
|
TexturesDefinitionClass.load(stream, textures);
|
||||||
WaterDefinitionClass.load(stream, water);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::autoPreset(int seed)
|
void Scenery::autoPreset(int seed)
|
||||||
|
@ -139,12 +142,12 @@ void Scenery::getTextures(TexturesDefinition* textures)
|
||||||
|
|
||||||
void Scenery::setWater(WaterDefinition* water)
|
void Scenery::setWater(WaterDefinition* water)
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.copy(water, this->water);
|
water->copy(this->water);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::getWater(WaterDefinition* water)
|
void Scenery::getWater(WaterDefinition* water)
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.copy(this->water, water);
|
this->water->copy(water);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scenery::bindToRenderer(Renderer* renderer)
|
void Scenery::bindToRenderer(Renderer* renderer)
|
||||||
|
|
|
@ -10,7 +10,6 @@ class CameraDefinition;
|
||||||
class CloudsDefinition;
|
class CloudsDefinition;
|
||||||
class TerrainDefinition;
|
class TerrainDefinition;
|
||||||
class TexturesDefinition;
|
class TexturesDefinition;
|
||||||
class WaterDefinition;
|
|
||||||
class Renderer;
|
class Renderer;
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
|
@ -32,33 +31,33 @@ public:
|
||||||
|
|
||||||
static Scenery* getCurrent();
|
static Scenery* getCurrent();
|
||||||
|
|
||||||
virtual void save(PackStream* stream);
|
virtual void save(PackStream* stream) const override;
|
||||||
virtual void load(PackStream* stream);
|
virtual void load(PackStream* stream) override;
|
||||||
|
|
||||||
void autoPreset(int seed);
|
void autoPreset(int seed);
|
||||||
|
|
||||||
void setAtmosphere(AtmosphereDefinition* atmosphere);
|
void setAtmosphere(AtmosphereDefinition* atmosphere);
|
||||||
inline AtmosphereDefinition* getAtmosphere() {return atmosphere;}
|
inline AtmosphereDefinition* getAtmosphere() const {return atmosphere;}
|
||||||
void getAtmosphere(AtmosphereDefinition* atmosphere);
|
void getAtmosphere(AtmosphereDefinition* atmosphere);
|
||||||
|
|
||||||
void setCamera(CameraDefinition* camera);
|
void setCamera(CameraDefinition* camera);
|
||||||
inline CameraDefinition* getCamera() {return camera;}
|
inline CameraDefinition* getCamera() const {return camera;}
|
||||||
void getCamera(CameraDefinition* camera);
|
void getCamera(CameraDefinition* camera);
|
||||||
|
|
||||||
void setClouds(CloudsDefinition* clouds);
|
void setClouds(CloudsDefinition* clouds);
|
||||||
inline CloudsDefinition* getClouds() {return clouds;}
|
inline CloudsDefinition* getClouds() const {return clouds;}
|
||||||
void getClouds(CloudsDefinition* clouds);
|
void getClouds(CloudsDefinition* clouds);
|
||||||
|
|
||||||
void setTerrain(TerrainDefinition* terrain);
|
void setTerrain(TerrainDefinition* terrain);
|
||||||
inline TerrainDefinition* getTerrain() {return terrain;}
|
inline TerrainDefinition* getTerrain() const {return terrain;}
|
||||||
void getTerrain(TerrainDefinition* terrain);
|
void getTerrain(TerrainDefinition* terrain);
|
||||||
|
|
||||||
void setTextures(TexturesDefinition* textures);
|
void setTextures(TexturesDefinition* textures);
|
||||||
inline TexturesDefinition* getTextures() {return textures;}
|
inline TexturesDefinition* getTextures() const {return textures;}
|
||||||
void getTextures(TexturesDefinition* textures);
|
void getTextures(TexturesDefinition* textures);
|
||||||
|
|
||||||
void setWater(WaterDefinition* water);
|
void setWater(WaterDefinition* water);
|
||||||
inline WaterDefinition* getWater() {return water;}
|
inline WaterDefinition* getWater() const {return water;}
|
||||||
void getWater(WaterDefinition* water);
|
void getWater(WaterDefinition* water);
|
||||||
|
|
||||||
void bindToRenderer(Renderer* renderer);
|
void bindToRenderer(Renderer* renderer);
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "../tools/curve.h"
|
#include "../tools/curve.h"
|
||||||
#include "../tools/euclid.h"
|
#include "../tools/euclid.h"
|
||||||
#include "Layers.h"
|
#include "Layers.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
namespace paysages {
|
namespace paysages {
|
||||||
namespace basics {
|
namespace basics {
|
||||||
|
|
|
@ -178,9 +178,9 @@ void renderSetToneMapping(RenderArea* area, ToneMappingOperator tonemapper, doub
|
||||||
renderUpdate(area);
|
renderUpdate(area);
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSetBackgroundColor(RenderArea* area, Color* col)
|
void renderSetBackgroundColor(RenderArea* area, const Color &col)
|
||||||
{
|
{
|
||||||
area->background_color = *col;
|
area->background_color = col;
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderClear(RenderArea* area)
|
void renderClear(RenderArea* area)
|
||||||
|
|
|
@ -30,7 +30,7 @@ RENDERINGSHARED_EXPORT void renderDeleteArea(RenderArea* area);
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT void renderSetParams(RenderArea* area, RenderParams params);
|
RENDERINGSHARED_EXPORT void renderSetParams(RenderArea* area, RenderParams params);
|
||||||
RENDERINGSHARED_EXPORT void renderSetToneMapping(RenderArea* area, ToneMappingOperator tonemapper, double exposure);
|
RENDERINGSHARED_EXPORT void renderSetToneMapping(RenderArea* area, ToneMappingOperator tonemapper, double exposure);
|
||||||
RENDERINGSHARED_EXPORT void renderSetBackgroundColor(RenderArea* area, Color* col);
|
RENDERINGSHARED_EXPORT void renderSetBackgroundColor(RenderArea* area, const Color& col);
|
||||||
RENDERINGSHARED_EXPORT void renderClear(RenderArea* area);
|
RENDERINGSHARED_EXPORT void renderClear(RenderArea* area);
|
||||||
RENDERINGSHARED_EXPORT void renderUpdate(RenderArea* area);
|
RENDERINGSHARED_EXPORT void renderUpdate(RenderArea* area);
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,7 @@ void rendererStart(Renderer* renderer, RenderParams params)
|
||||||
|
|
||||||
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
|
cameraSetRenderSize(renderer->render_camera, renderer->render_width, renderer->render_height);
|
||||||
|
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
|
||||||
renderSetParams(renderer->render_area, params);
|
renderSetParams(renderer->render_area, params);
|
||||||
renderClear(renderer->render_area);
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
class CameraDefinition;
|
class CameraDefinition;
|
||||||
class LightingManager;
|
class LightingManager;
|
||||||
class SurfaceMaterial;
|
|
||||||
class AtmosphereRenderer;
|
class AtmosphereRenderer;
|
||||||
class TerrainRenderer;
|
class TerrainRenderer;
|
||||||
class TexturesRenderer;
|
class TexturesRenderer;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef RENDERING_GLOBAL_H
|
#ifndef RENDERING_GLOBAL_H
|
||||||
#define RENDERING_GLOBAL_H
|
#define RENDERING_GLOBAL_H
|
||||||
|
|
||||||
/* Shared object helpers */
|
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#if defined(RENDERING_LIBRARY)
|
#if defined(RENDERING_LIBRARY)
|
||||||
# define RENDERINGSHARED_EXPORT Q_DECL_EXPORT
|
# define RENDERINGSHARED_EXPORT Q_DECL_EXPORT
|
||||||
|
@ -9,15 +8,6 @@
|
||||||
# define RENDERINGSHARED_EXPORT Q_DECL_IMPORT
|
# define RENDERINGSHARED_EXPORT Q_DECL_IMPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Namespace using */
|
#include "definition_global.h"
|
||||||
namespace paysages
|
|
||||||
{
|
|
||||||
namespace system {}
|
|
||||||
namespace basics {}
|
|
||||||
namespace definition {}
|
|
||||||
}
|
|
||||||
using namespace paysages::system;
|
|
||||||
using namespace paysages::basics;
|
|
||||||
using namespace paysages::definition;
|
|
||||||
|
|
||||||
#endif // RENDERING_GLOBAL_H
|
#endif // RENDERING_GLOBAL_H
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "tools/zone.h"
|
#include "tools/zone.h"
|
||||||
#include "tools/lighting.h"
|
#include "tools/lighting.h"
|
||||||
#include "terrain/public.h"
|
#include "terrain/public.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
#define TEXTURES_MAX_LAYERS 50
|
#define TEXTURES_MAX_LAYERS 50
|
||||||
|
|
||||||
|
|
|
@ -7,210 +7,6 @@
|
||||||
#include "../tools.h"
|
#include "../tools.h"
|
||||||
#include "PackStream.h"
|
#include "PackStream.h"
|
||||||
|
|
||||||
/******************************** Color ********************************/
|
|
||||||
|
|
||||||
Color COLOR_TRANSPARENT = {0.0, 0.0, 0.0, 0.0};
|
|
||||||
Color COLOR_BLACK = {0.0, 0.0, 0.0, 1.0};
|
|
||||||
Color COLOR_RED = {1.0, 0.0, 0.0, 1.0};
|
|
||||||
Color COLOR_GREEN = {0.0, 1.0, 0.0, 1.0};
|
|
||||||
Color COLOR_BLUE = {0.0, 0.0, 1.0, 1.0};
|
|
||||||
Color COLOR_WHITE = {1.0, 1.0, 1.0, 1.0};
|
|
||||||
Color COLOR_GREY = {0.5, 0.5, 0.5, 1.0};
|
|
||||||
|
|
||||||
void colorSave(PackStream* stream, Color* col)
|
|
||||||
{
|
|
||||||
stream->write(&col->r);
|
|
||||||
stream->write(&col->g);
|
|
||||||
stream->write(&col->b);
|
|
||||||
stream->write(&col->a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void colorLoad(PackStream* stream, Color* col)
|
|
||||||
{
|
|
||||||
stream->read(&col->r);
|
|
||||||
stream->read(&col->g);
|
|
||||||
stream->read(&col->b);
|
|
||||||
stream->read(&col->a);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFromValues(double r, double g, double b, double a)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
result.r = r;
|
|
||||||
result.g = g;
|
|
||||||
result.b = b;
|
|
||||||
result.a = a;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int colorTo32BitRGBA(Color* col)
|
|
||||||
{
|
|
||||||
return (((unsigned int) (col->a * 255.0)) << 24) | (((unsigned int) (col->b * 255.0)) << 16) | (((unsigned int) (col->g * 255.0)) << 8) | ((unsigned int) (col->r * 255.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int colorTo32BitBGRA(Color* col)
|
|
||||||
{
|
|
||||||
return (((unsigned int) (col->a * 255.0)) << 24) | (((unsigned int) (col->r * 255.0)) << 16) | (((unsigned int) (col->g * 255.0)) << 8) | ((unsigned int) (col->b * 255.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int colorTo32BitARGB(Color* col)
|
|
||||||
{
|
|
||||||
return (((unsigned int) (col->b * 255.0)) << 24) | (((unsigned int) (col->g * 255.0)) << 16) | (((unsigned int) (col->r * 255.0)) << 8) | ((unsigned int) (col->a * 255.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int colorTo32BitABGR(Color* col)
|
|
||||||
{
|
|
||||||
return (((unsigned int) (col->r * 255.0)) << 24) | (((unsigned int) (col->g * 255.0)) << 16) | (((unsigned int) (col->b * 255.0)) << 8) | ((unsigned int) (col->a * 255.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFrom32BitRGBA(unsigned int col)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
result.r = ((double) (col & 0x000000FF)) / 255.0;
|
|
||||||
result.g = ((double) ((col & 0x0000FF00) >> 8)) / 255.0;
|
|
||||||
result.b = ((double) ((col & 0x00FF0000) >> 16)) / 255.0;
|
|
||||||
result.a = ((double) ((col & 0xFF000000) >> 24)) / 255.0;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFrom32BitBGRA(unsigned int col)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
result.b = ((double) (col & 0x000000FF)) / 255.0;
|
|
||||||
result.g = ((double) ((col & 0x0000FF00) >> 8)) / 255.0;
|
|
||||||
result.r = ((double) ((col & 0x00FF0000) >> 16)) / 255.0;
|
|
||||||
result.a = ((double) ((col & 0xFF000000) >> 24)) / 255.0;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFrom32BitARGB(unsigned int col)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
result.a = ((double) (col & 0x000000FF)) / 255.0;
|
|
||||||
result.r = ((double) ((col & 0x0000FF00) >> 8)) / 255.0;
|
|
||||||
result.g = ((double) ((col & 0x00FF0000) >> 16)) / 255.0;
|
|
||||||
result.b = ((double) ((col & 0xFF000000) >> 24)) / 255.0;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFrom32BitABGR(unsigned int col)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
result.a = ((double) (col & 0x000000FF)) / 255.0;
|
|
||||||
result.b = ((double) ((col & 0x0000FF00) >> 8)) / 255.0;
|
|
||||||
result.g = ((double) ((col & 0x00FF0000) >> 16)) / 255.0;
|
|
||||||
result.r = ((double) ((col & 0xFF000000) >> 24)) / 255.0;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void colorMask(Color* base, Color* mask)
|
|
||||||
{
|
|
||||||
double new_a;
|
|
||||||
new_a = base->a + mask->a - (base->a * mask->a);
|
|
||||||
base->r = (mask->r * mask->a + base->r * base->a - base->r * base->a * mask->a) / new_a;
|
|
||||||
base->g = (mask->g * mask->a + base->g * base->a - base->g * base->a * mask->a) / new_a;
|
|
||||||
base->b = (mask->b * mask->a + base->b * base->a - base->b * base->a * mask->a) / new_a;
|
|
||||||
base->a = new_a;
|
|
||||||
|
|
||||||
/*double mask_weight = mask->a;
|
|
||||||
double base_weight = 1.0 - mask_weight;
|
|
||||||
|
|
||||||
base->r = mask->r * mask_weight + base->r * base_weight;
|
|
||||||
base->g = mask->g * mask_weight + base->g * base_weight;
|
|
||||||
base->b = mask->b * mask_weight + base->b * base_weight;
|
|
||||||
base->a = base->a + mask_weight * (1.0 - base->a);*/
|
|
||||||
}
|
|
||||||
|
|
||||||
double colorNormalize(Color* col)
|
|
||||||
{
|
|
||||||
assert(col->r >= 0.0);
|
|
||||||
assert(col->g >= 0.0);
|
|
||||||
assert(col->b >= 0.0);
|
|
||||||
assert(col->a >= 0.0);
|
|
||||||
#ifdef isnan
|
|
||||||
assert(!isnan(col->r));
|
|
||||||
assert(!isnan(col->g));
|
|
||||||
assert(!isnan(col->b));
|
|
||||||
assert(!isnan(col->a));
|
|
||||||
#endif
|
|
||||||
#ifdef isfinite
|
|
||||||
assert(isfinite(col->r));
|
|
||||||
assert(isfinite(col->g));
|
|
||||||
assert(isfinite(col->b));
|
|
||||||
assert(isfinite(col->a));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (col->r > 1.0)
|
|
||||||
{
|
|
||||||
col->r = 1.0;
|
|
||||||
}
|
|
||||||
if (col->g > 1.0)
|
|
||||||
{
|
|
||||||
col->g = 1.0;
|
|
||||||
}
|
|
||||||
if (col->b > 1.0)
|
|
||||||
{
|
|
||||||
col->b = 1.0;
|
|
||||||
}
|
|
||||||
return 1.0;
|
|
||||||
/*double max = colorGetValue(col);
|
|
||||||
|
|
||||||
assert(max >= 0.0);
|
|
||||||
|
|
||||||
if (max > 1.0)
|
|
||||||
{
|
|
||||||
col->r /= max;
|
|
||||||
col->g /= max;
|
|
||||||
col->b /= max;
|
|
||||||
}
|
|
||||||
return max;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
double colorGetValue(Color* col)
|
|
||||||
{
|
|
||||||
double max;
|
|
||||||
|
|
||||||
max = col->r;
|
|
||||||
if (col->g > max)
|
|
||||||
{
|
|
||||||
max = col->g;
|
|
||||||
}
|
|
||||||
if (col->b > max)
|
|
||||||
{
|
|
||||||
max = col->b;
|
|
||||||
}
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
double colorGetPower(Color* col)
|
|
||||||
{
|
|
||||||
return col->r + col->g + col->b;
|
|
||||||
}
|
|
||||||
|
|
||||||
void colorLimitPower(Color* col, double max_power)
|
|
||||||
{
|
|
||||||
double power = colorGetPower(col);
|
|
||||||
|
|
||||||
if (power > max_power)
|
|
||||||
{
|
|
||||||
double factor = max_power / power;
|
|
||||||
|
|
||||||
col->r *= factor;
|
|
||||||
col->g *= factor;
|
|
||||||
col->b *= factor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************** ColorProfile ********************************/
|
/******************************** ColorProfile ********************************/
|
||||||
class ColorProfile
|
class ColorProfile
|
||||||
{
|
{
|
||||||
|
@ -454,89 +250,3 @@ Color colorGradationGet(ColorGradation* gradation, double value)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************** HSL Color Space ********************************/
|
|
||||||
static double _hue2rgb(double p, double q, double t)
|
|
||||||
{
|
|
||||||
if (t < 0.0) t += 1;
|
|
||||||
if (t > 1.0) t -= 1;
|
|
||||||
if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;
|
|
||||||
if (t < 1.0 / 2.0) return q;
|
|
||||||
if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
Color colorFromHSL(ColorHSL col)
|
|
||||||
{
|
|
||||||
Color result;
|
|
||||||
|
|
||||||
if (col.s == 0)
|
|
||||||
{
|
|
||||||
result.r = result.g = result.b = col.l;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double q = col.l < 0.5 ? col.l * (1.0 + col.s) : col.l + col.s - col.l * col.s;
|
|
||||||
double p = 2 * col.l - q;
|
|
||||||
result.r = _hue2rgb(p, q, col.h + 1.0 / 3.0);
|
|
||||||
result.g = _hue2rgb(p, q, col.h);
|
|
||||||
result.b = _hue2rgb(p, q, col.h - 1.0 / 3.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.a = col.a;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorHSL colorToHSL(Color col)
|
|
||||||
{
|
|
||||||
ColorHSL result;
|
|
||||||
double min, max;
|
|
||||||
|
|
||||||
max = col.r > col.g ? col.r : col.g;
|
|
||||||
max = col.b > max ? col.b : max;
|
|
||||||
|
|
||||||
min = col.r < col.g ? col.r : col.g;
|
|
||||||
min = col.b < min ? col.b : min;
|
|
||||||
|
|
||||||
result.h = result.s = result.l = (max + min) / 2.0;
|
|
||||||
|
|
||||||
if (max == min)
|
|
||||||
{
|
|
||||||
result.h = result.s = 0.0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
double d = max - min;
|
|
||||||
result.s = result.l > 0.5 ? d / (2.0 - max - min) : d / (max + min);
|
|
||||||
if (max == col.r)
|
|
||||||
{
|
|
||||||
result.h = (col.g - col.b) / d + (col.g < col.b ? 6.0 : 0);
|
|
||||||
}
|
|
||||||
else if (max == col.g)
|
|
||||||
{
|
|
||||||
result.h = (col.b - col.r) / d + 2.0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result.h = (col.r - col.g) / d + 4.0;
|
|
||||||
}
|
|
||||||
result.h /= 6.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
result.a = col.a;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
ColorHSL colorHSLFromValues(double h, double s, double l, double a)
|
|
||||||
{
|
|
||||||
ColorHSL result;
|
|
||||||
|
|
||||||
result.h = h;
|
|
||||||
result.s = s;
|
|
||||||
result.l = l;
|
|
||||||
result.a = a;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,49 +4,6 @@
|
||||||
#include "../rendering_global.h"
|
#include "../rendering_global.h"
|
||||||
#include "curve.h"
|
#include "curve.h"
|
||||||
|
|
||||||
namespace paysages {
|
|
||||||
namespace system {class PackStream;}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TYPEDEF_COLOR
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double r;
|
|
||||||
double g;
|
|
||||||
double b;
|
|
||||||
double a;
|
|
||||||
} Color;
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_TRANSPARENT;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_BLACK;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_RED;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_GREEN;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_BLUE;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_WHITE;
|
|
||||||
RENDERINGSHARED_EXPORT extern Color COLOR_GREY;
|
|
||||||
|
|
||||||
/* Color */
|
|
||||||
RENDERINGSHARED_EXPORT void colorSave(PackStream* stream, Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT void colorLoad(PackStream* stream, Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFromValues(double r, double g, double b, double a);
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT unsigned int colorTo32BitRGBA(Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT unsigned int colorTo32BitBGRA(Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT unsigned int colorTo32BitARGB(Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT unsigned int colorTo32BitABGR(Color* col);
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFrom32BitRGBA(unsigned int col);
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFrom32BitBGRA(unsigned int col);
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFrom32BitARGB(unsigned int col);
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFrom32BitABGR(unsigned int col);
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT void colorMask(Color* base, Color* mask);
|
|
||||||
RENDERINGSHARED_EXPORT double colorNormalize(Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT double colorGetValue(Color* col);
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT double colorGetPower(Color* col);
|
|
||||||
RENDERINGSHARED_EXPORT void colorLimitPower(Color* col, double max_power);
|
|
||||||
|
|
||||||
/* HDR profile for tone-mapping */
|
/* HDR profile for tone-mapping */
|
||||||
class ColorProfile;
|
class ColorProfile;
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -92,18 +49,8 @@ RENDERINGSHARED_EXPORT void colorGradationQuickAddRgb(ColorGradation* gradation,
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT Color colorGradationGet(ColorGradation* gradation, double value);
|
RENDERINGSHARED_EXPORT Color colorGradationGet(ColorGradation* gradation, double value);
|
||||||
|
|
||||||
/* HSL color space */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
double h;
|
|
||||||
double s;
|
|
||||||
double l;
|
|
||||||
double a;
|
|
||||||
} ColorHSL;
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT Color colorFromHSL(ColorHSL col);
|
// TEMP
|
||||||
RENDERINGSHARED_EXPORT ColorHSL colorToHSL(Color col);
|
#include "Color.h"
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT ColorHSL colorHSLFromValues(double h, double s, double l, double a);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "PackStream.h"
|
#include "PackStream.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
|
|
||||||
#define MAX_CALLBACK_COUNT 10
|
#define MAX_CALLBACK_COUNT 10
|
||||||
#define MAX_LIGHT_COUNT 30
|
#define MAX_LIGHT_COUNT 30
|
||||||
|
@ -214,36 +215,3 @@ Vector3 lightingGetStatusLocation(LightStatus* status)
|
||||||
{
|
{
|
||||||
return status->location;
|
return status->location;
|
||||||
}
|
}
|
||||||
|
|
||||||
void materialSave(PackStream* stream, SurfaceMaterial* material)
|
|
||||||
{
|
|
||||||
stream->write(&material->base.h);
|
|
||||||
stream->write(&material->base.l);
|
|
||||||
stream->write(&material->base.s);
|
|
||||||
|
|
||||||
stream->write(&material->hardness);
|
|
||||||
stream->write(&material->reflection);
|
|
||||||
stream->write(&material->shininess);
|
|
||||||
|
|
||||||
stream->write(&material->receive_shadows);
|
|
||||||
}
|
|
||||||
|
|
||||||
void materialLoad(PackStream* stream, SurfaceMaterial* material)
|
|
||||||
{
|
|
||||||
stream->read(&material->base.h);
|
|
||||||
stream->read(&material->base.l);
|
|
||||||
stream->read(&material->base.s);
|
|
||||||
|
|
||||||
stream->read(&material->hardness);
|
|
||||||
stream->read(&material->reflection);
|
|
||||||
stream->read(&material->shininess);
|
|
||||||
|
|
||||||
stream->read(&material->receive_shadows);
|
|
||||||
|
|
||||||
materialValidate(material);
|
|
||||||
}
|
|
||||||
|
|
||||||
void materialValidate(SurfaceMaterial* material)
|
|
||||||
{
|
|
||||||
material->_rgb = colorFromHSL(material->base);
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,20 +9,6 @@ namespace paysages {
|
||||||
namespace system {class PackStream;}
|
namespace system {class PackStream;}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SurfaceMaterial
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ColorHSL base;
|
|
||||||
|
|
||||||
double hardness;
|
|
||||||
double reflection;
|
|
||||||
double shininess;
|
|
||||||
|
|
||||||
double receive_shadows;
|
|
||||||
|
|
||||||
Color _rgb;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Vector3 direction; /* Global direction of the light */
|
Vector3 direction; /* Global direction of the light */
|
||||||
|
@ -49,8 +35,4 @@ RENDERINGSHARED_EXPORT Vector3 lightingGetStatusLocation(LightStatus* status);
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material);
|
RENDERINGSHARED_EXPORT Color lightingApplyOneLight(LightDefinition* light, Vector3 eye, Vector3 location, Vector3 normal, SurfaceMaterial* material);
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT void materialSave(PackStream* stream, SurfaceMaterial* material);
|
|
||||||
RENDERINGSHARED_EXPORT void materialLoad(PackStream* stream, SurfaceMaterial* material);
|
|
||||||
RENDERINGSHARED_EXPORT void materialValidate(SurfaceMaterial* material);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,27 +19,6 @@ typedef enum
|
||||||
WATER_PRESET_SEA
|
WATER_PRESET_SEA
|
||||||
} WaterPreset;
|
} WaterPreset;
|
||||||
|
|
||||||
class WaterDefinition
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
double transparency;
|
|
||||||
double reflection;
|
|
||||||
SurfaceMaterial material;
|
|
||||||
Color depth_color;
|
|
||||||
double transparency_depth;
|
|
||||||
double lighting_depth;
|
|
||||||
|
|
||||||
double scaling;
|
|
||||||
double turbulence;
|
|
||||||
double waves_height;
|
|
||||||
double detail_height;
|
|
||||||
|
|
||||||
double foam_coverage;
|
|
||||||
SurfaceMaterial foam_material;
|
|
||||||
|
|
||||||
NoiseGenerator* _waves_noise;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Vector3 location;
|
Vector3 location;
|
||||||
|
@ -65,7 +44,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT extern StandardDefinition WaterDefinitionClass;
|
|
||||||
RENDERINGSHARED_EXPORT extern StandardRenderer WaterRendererClass;
|
RENDERINGSHARED_EXPORT extern StandardRenderer WaterRendererClass;
|
||||||
|
|
||||||
RENDERINGSHARED_EXPORT void waterRenderSurface(Renderer* renderer);
|
RENDERINGSHARED_EXPORT void waterRenderSurface(Renderer* renderer);
|
||||||
|
|
|
@ -1,101 +1 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
#include "PackStream.h"
|
|
||||||
#include "NoiseGenerator.h"
|
|
||||||
|
|
||||||
static void _validateDefinition(WaterDefinition* definition)
|
|
||||||
{
|
|
||||||
double scaling = definition->scaling * 0.3;
|
|
||||||
definition->_waves_noise->clearLevels();
|
|
||||||
if (definition->waves_height > 0.0)
|
|
||||||
{
|
|
||||||
definition->_waves_noise->addLevelsSimple(2, scaling, -definition->waves_height * scaling * 0.015, definition->waves_height * scaling * 0.015, 0.5);
|
|
||||||
}
|
|
||||||
if (definition->detail_height > 0.0)
|
|
||||||
{
|
|
||||||
definition->_waves_noise->addLevelsSimple(3, scaling * 0.1, -definition->detail_height * scaling * 0.015, definition->detail_height * scaling * 0.015, 0.5);
|
|
||||||
}
|
|
||||||
definition->_waves_noise->setFunctionParams(NOISE_FUNCTION_SIMPLEX, -definition->turbulence, 0.0);
|
|
||||||
definition->_waves_noise->validate();
|
|
||||||
|
|
||||||
materialValidate(&definition->material);
|
|
||||||
materialValidate(&definition->foam_material);
|
|
||||||
}
|
|
||||||
|
|
||||||
static WaterDefinition* _createDefinition()
|
|
||||||
{
|
|
||||||
WaterDefinition* definition = new WaterDefinition;
|
|
||||||
|
|
||||||
definition->_waves_noise = new NoiseGenerator();
|
|
||||||
|
|
||||||
waterAutoPreset(definition, WATER_PRESET_LAKE);
|
|
||||||
|
|
||||||
return definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _deleteDefinition(WaterDefinition* definition)
|
|
||||||
{
|
|
||||||
delete definition->_waves_noise;
|
|
||||||
delete definition;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _copyDefinition(WaterDefinition* source, WaterDefinition* destination)
|
|
||||||
{
|
|
||||||
NoiseGenerator* noise;
|
|
||||||
|
|
||||||
noise = destination->_waves_noise;
|
|
||||||
*destination = *source;
|
|
||||||
destination->_waves_noise = noise;
|
|
||||||
source->_waves_noise->copy(destination->_waves_noise);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _saveDefinition(PackStream* stream, WaterDefinition* definition)
|
|
||||||
{
|
|
||||||
materialSave(stream, &definition->material);
|
|
||||||
colorSave(stream, &definition->depth_color);
|
|
||||||
stream->write(&definition->transparency_depth);
|
|
||||||
stream->write(&definition->transparency);
|
|
||||||
stream->write(&definition->reflection);
|
|
||||||
stream->write(&definition->lighting_depth);
|
|
||||||
|
|
||||||
stream->write(&definition->scaling);
|
|
||||||
stream->write(&definition->waves_height);
|
|
||||||
stream->write(&definition->detail_height);
|
|
||||||
stream->write(&definition->turbulence);
|
|
||||||
|
|
||||||
stream->write(&definition->foam_coverage);
|
|
||||||
materialSave(stream, &definition->foam_material);
|
|
||||||
|
|
||||||
definition->_waves_noise->save(stream);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _loadDefinition(PackStream* stream, WaterDefinition* definition)
|
|
||||||
{
|
|
||||||
materialLoad(stream, &definition->material);
|
|
||||||
colorLoad(stream, &definition->depth_color);
|
|
||||||
stream->read(&definition->transparency_depth);
|
|
||||||
stream->read(&definition->transparency);
|
|
||||||
stream->read(&definition->reflection);
|
|
||||||
stream->read(&definition->lighting_depth);
|
|
||||||
|
|
||||||
stream->read(&definition->scaling);
|
|
||||||
stream->read(&definition->waves_height);
|
|
||||||
stream->read(&definition->detail_height);
|
|
||||||
stream->read(&definition->turbulence);
|
|
||||||
|
|
||||||
stream->read(&definition->foam_coverage);
|
|
||||||
materialLoad(stream, &definition->foam_material);
|
|
||||||
|
|
||||||
definition->_waves_noise->load(stream);
|
|
||||||
|
|
||||||
_validateDefinition(definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
StandardDefinition WaterDefinitionClass = {
|
|
||||||
(FuncObjectCreate)_createDefinition,
|
|
||||||
(FuncObjectDelete)_deleteDefinition,
|
|
||||||
(FuncObjectCopy)_copyDefinition,
|
|
||||||
(FuncObjectValidate)_validateDefinition,
|
|
||||||
(FuncObjectSave)_saveDefinition,
|
|
||||||
(FuncObjectLoad)_loadDefinition
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
#include "NoiseGenerator.h"
|
#include "NoiseGenerator.h"
|
||||||
|
|
||||||
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
||||||
|
@ -11,10 +13,10 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
||||||
definition->transparency = 0.5;
|
definition->transparency = 0.5;
|
||||||
definition->reflection = 0.4;
|
definition->reflection = 0.4;
|
||||||
definition->transparency_depth = 4.0;
|
definition->transparency_depth = 4.0;
|
||||||
definition->material.base = colorToHSL(colorFromValues(0.08, 0.15, 0.2, 1.0));
|
definition->material->base = colorToHSL(colorFromValues(0.08, 0.15, 0.2, 1.0));
|
||||||
definition->depth_color.r = 0.0;
|
definition->depth_color->r = 0.0;
|
||||||
definition->depth_color.g = 0.1;
|
definition->depth_color->g = 0.1;
|
||||||
definition->depth_color.b = 0.1;
|
definition->depth_color->b = 0.1;
|
||||||
definition->lighting_depth = 6.0;
|
definition->lighting_depth = 6.0;
|
||||||
definition->scaling = 1.0;
|
definition->scaling = 1.0;
|
||||||
definition->waves_height = 0.8;
|
definition->waves_height = 0.8;
|
||||||
|
@ -27,10 +29,10 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
||||||
definition->transparency = 0.4;
|
definition->transparency = 0.4;
|
||||||
definition->reflection = 0.35;
|
definition->reflection = 0.35;
|
||||||
definition->transparency_depth = 3.0;
|
definition->transparency_depth = 3.0;
|
||||||
definition->material.base = colorToHSL(colorFromValues(0.05, 0.18, 0.2, 1.0));
|
definition->material->base = colorToHSL(colorFromValues(0.05, 0.18, 0.2, 1.0));
|
||||||
definition->depth_color.r = 0.0;
|
definition->depth_color->r = 0.0;
|
||||||
definition->depth_color.g = 0.18;
|
definition->depth_color->g = 0.18;
|
||||||
definition->depth_color.b = 0.15;
|
definition->depth_color->b = 0.15;
|
||||||
definition->lighting_depth = 4.0;
|
definition->lighting_depth = 4.0;
|
||||||
definition->scaling = 1.5;
|
definition->scaling = 1.5;
|
||||||
definition->waves_height = 1.0;
|
definition->waves_height = 1.0;
|
||||||
|
@ -39,13 +41,13 @@ void waterAutoPreset(WaterDefinition* definition, WaterPreset preset)
|
||||||
definition->foam_coverage = 0.4;
|
definition->foam_coverage = 0.4;
|
||||||
}
|
}
|
||||||
|
|
||||||
definition->depth_color.a = 1.0;
|
definition->depth_color->a = 1.0;
|
||||||
definition->material.base.a = 1.0;
|
definition->material->base.a = 1.0;
|
||||||
definition->material.reflection = 1.0;
|
definition->material->reflection = 1.0;
|
||||||
definition->material.shininess = 16.0;
|
definition->material->shininess = 16.0;
|
||||||
definition->foam_material.base = colorToHSL(colorFromValues(0.8, 0.8, 0.8, 1.0));
|
definition->foam_material->base = colorToHSL(colorFromValues(0.8, 0.8, 0.8, 1.0));
|
||||||
definition->foam_material.reflection = 0.1;
|
definition->foam_material->reflection = 0.1;
|
||||||
definition->foam_material.shininess = 1.5;
|
definition->foam_material->shininess = 1.5;
|
||||||
|
|
||||||
WaterDefinitionClass.validate(definition);
|
definition->validate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "../tools.h"
|
#include "../tools.h"
|
||||||
#include "../renderer.h"
|
#include "../renderer.h"
|
||||||
|
#include "WaterDefinition.h"
|
||||||
|
#include "SurfaceMaterial.h"
|
||||||
#include "NoiseGenerator.h"
|
#include "NoiseGenerator.h"
|
||||||
#include "terrain/public.h"
|
#include "terrain/public.h"
|
||||||
|
|
||||||
|
@ -143,7 +145,7 @@ static inline Color _getFoamMask(Renderer* renderer, WaterDefinition* definition
|
||||||
foam_factor = (foam_factor - (1.0 - definition->foam_coverage)) * definition->foam_coverage;
|
foam_factor = (foam_factor - (1.0 - definition->foam_coverage)) * definition->foam_coverage;
|
||||||
|
|
||||||
/* TODO Re-use base lighting status */
|
/* TODO Re-use base lighting status */
|
||||||
result = renderer->applyLightingToSurface(renderer, location, normal, &definition->foam_material);
|
result = renderer->applyLightingToSurface(renderer, location, normal, definition->foam_material);
|
||||||
result.r *= 2.0;
|
result.r *= 2.0;
|
||||||
result.g *= 2.0;
|
result.g *= 2.0;
|
||||||
result.b *= 2.0;
|
result.b *= 2.0;
|
||||||
|
@ -260,7 +262,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Color depth_color = definition->depth_color;
|
Color depth_color = *definition->depth_color;
|
||||||
refracted = renderer->rayWalking(renderer, location, _refractRay(look_direction, normal), 1, 0, 1, 1);
|
refracted = renderer->rayWalking(renderer, location, _refractRay(look_direction, normal), 1, 0, 1, 1);
|
||||||
depth = v3Norm(v3Sub(location, refracted.hit_location));
|
depth = v3Norm(v3Sub(location, refracted.hit_location));
|
||||||
colorLimitPower(&depth_color, colorGetPower(&refracted.hit_color));
|
colorLimitPower(&depth_color, colorGetPower(&refracted.hit_color));
|
||||||
|
@ -279,7 +281,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lighting from environment */
|
/* Lighting from environment */
|
||||||
color = renderer->applyLightingToSurface(renderer, location, normal, &definition->material);
|
color = renderer->applyLightingToSurface(renderer, location, normal, definition->material);
|
||||||
|
|
||||||
color.r += result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
|
color.r += result.reflected.r * definition->reflection + result.refracted.r * definition->transparency;
|
||||||
color.g += result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
|
color.g += result.reflected.g * definition->reflection + result.refracted.g * definition->transparency;
|
||||||
|
@ -292,7 +294,7 @@ static WaterResult _realGetResult(Renderer* renderer, double x, double z)
|
||||||
/* Bring color to the camera */
|
/* Bring color to the camera */
|
||||||
color = renderer->applyMediumTraversal(location, color);
|
color = renderer->applyMediumTraversal(location, color);
|
||||||
|
|
||||||
result.base = definition->material._rgb;
|
result.base = definition->material->_rgb;
|
||||||
result.final = color;
|
result.final = color;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -304,7 +306,7 @@ static WaterRenderer* _createRenderer()
|
||||||
WaterRenderer* result;
|
WaterRenderer* result;
|
||||||
|
|
||||||
result = new WaterRenderer;
|
result = new WaterRenderer;
|
||||||
result->definition = (WaterDefinition*)WaterDefinitionClass.create();
|
result->definition = new WaterDefinition(NULL);
|
||||||
|
|
||||||
result->getHeightInfo = _fakeGetHeightInfo;
|
result->getHeightInfo = _fakeGetHeightInfo;
|
||||||
result->getHeight = _fakeGetHeight;
|
result->getHeight = _fakeGetHeight;
|
||||||
|
@ -315,13 +317,13 @@ static WaterRenderer* _createRenderer()
|
||||||
|
|
||||||
static void _deleteRenderer(WaterRenderer* renderer)
|
static void _deleteRenderer(WaterRenderer* renderer)
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.destroy(renderer->definition);
|
delete renderer->definition;
|
||||||
delete renderer;
|
delete renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _bindRenderer(Renderer* renderer, WaterDefinition* definition)
|
static void _bindRenderer(Renderer* renderer, WaterDefinition* definition)
|
||||||
{
|
{
|
||||||
WaterDefinitionClass.copy(definition, renderer->water->definition);
|
definition->copy(renderer->water->definition);
|
||||||
|
|
||||||
renderer->water->getHeightInfo = _realGetHeightInfo;
|
renderer->water->getHeightInfo = _realGetHeightInfo;
|
||||||
renderer->water->getHeight = _realGetHeight;
|
renderer->water->getHeight = _realGetHeight;
|
||||||
|
|
|
@ -17,9 +17,7 @@ int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callbac
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
Color pixel = callback_pixel(data, x, y);
|
result.setPixel(x, height - 1 - y, callback_pixel(data, x, y));
|
||||||
QColor pixelconv = QColor::fromRgbF(pixel.r, pixel.g, pixel.b, pixel.a);
|
|
||||||
result.setPixel(x, height - 1 - y, pixelconv.rgba());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,8 @@ public:
|
||||||
|
|
||||||
// Transitional C-API
|
// Transitional C-API
|
||||||
|
|
||||||
#ifndef TYPEDEF_COLOR
|
// Les pixels doivent être fournis en RGBA
|
||||||
typedef struct
|
typedef unsigned int (*PictureCallbackSavePixel)(void* data, int x, int y);
|
||||||
{
|
|
||||||
double r;
|
|
||||||
double g;
|
|
||||||
double b;
|
|
||||||
double a;
|
|
||||||
} Color;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef Color (*PictureCallbackSavePixel)(void* data, int x, int y);
|
|
||||||
SYSTEMSHARED_EXPORT int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height);
|
SYSTEMSHARED_EXPORT int systemSavePictureFile(const char* filepath, PictureCallbackSavePixel callback_pixel, void* data, int width, int height);
|
||||||
|
|
||||||
#endif // PICTUREFILE_H
|
#endif // PICTUREFILE_H
|
||||||
|
|
|
@ -28,7 +28,7 @@ TEST(Bruneton, AerialPerspective1)
|
||||||
|
|
||||||
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
||||||
renderSetParams(renderer->render_area, params);
|
renderSetParams(renderer->render_area, params);
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
|
||||||
renderClear(renderer->render_area);
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
|
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
|
||||||
|
@ -63,7 +63,7 @@ TEST(Bruneton, AerialPerspective2)
|
||||||
|
|
||||||
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
||||||
renderSetParams(renderer->render_area, params);
|
renderSetParams(renderer->render_area, params);
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLACK);
|
renderSetBackgroundColor(renderer->render_area, COLOR_BLACK);
|
||||||
renderClear(renderer->render_area);
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
|
renderer->pushQuad(renderer, v3(50.0, -10.0, -50.0), v3(1.0, -10.0, -50.0), v3(1.0, -10.0, 50.0), v3(50.0, -10.0, 50.0), _postProcessFragment, NULL);
|
||||||
|
|
|
@ -45,7 +45,7 @@ TEST(Render, quad)
|
||||||
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
RenderParams params = {renderer->render_width, renderer->render_height, 1, 1};
|
||||||
renderSetParams(renderer->render_area, params);
|
renderSetParams(renderer->render_area, params);
|
||||||
|
|
||||||
renderSetBackgroundColor(renderer->render_area, &COLOR_BLUE);
|
renderSetBackgroundColor(renderer->render_area, COLOR_BLUE);
|
||||||
renderClear(renderer->render_area);
|
renderClear(renderer->render_area);
|
||||||
|
|
||||||
renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
|
renderer->pushQuad(renderer, v3(-1.0, 0.0, 1.0), v3(-1.0, 0.0, -1.0), v3(1.0, 0.0, -1.0), v3(1.0, 0.0, 1.0), _postProcessFragment, NULL);
|
||||||
|
|
Loading…
Reference in a new issue