paysages : New atmosphere previews.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@473 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-12-07 14:15:28 +00:00 committed by ThunderK
parent 237040864d
commit 2756c41188
4 changed files with 158 additions and 33 deletions

View file

@ -4,6 +4,7 @@
Global : Global :
* Version handling in saved files. * Version handling in saved files.
* Replaced old noise algorithm with Simplex Noise (up to 4 times faster). * Replaced old noise algorithm with Simplex Noise (up to 4 times faster).
* New noise settings for better shape control.
Terrain : Terrain :
* Added canvases to paint the shape directly. * Added canvases to paint the shape directly.
@ -16,9 +17,11 @@ Textures :
Water : Water :
* Added foam. * Added foam.
Sky : Atmosphere :
* Merged with sky module.
* New sky model (based on Preetham's work). * New sky model (based on Preetham's work).
* Added sun halo control. * Added sun halo control.
* Better previews.
Clouds : Clouds :
* Added clouds hardness to light. * Added clouds hardness to light.

View file

@ -26,21 +26,7 @@ public:
protected: protected:
QColor getColor(double x, double y) QColor getColor(double x, double y)
{ {
y -= 100.0 * scaling; return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, M_PI_2));
if (y > 0.0)
{
return QColor(0, 0, 0);
}
else
{
Vector3 look;
look.x = 1.0;
look.y = -y;
look.z = x;
return colorToQColor(_renderer.atmosphere->getSkyColor(&_renderer, look));
}
} }
void updateData() void updateData()
{ {
@ -63,21 +49,7 @@ public:
protected: protected:
QColor getColor(double x, double y) QColor getColor(double x, double y)
{ {
y -= 100.0 * scaling; return colorToQColor(atmosphereGetPreview(&_renderer, x, -y, -M_PI_2));
if (y > 0.0)
{
return QColor(0, 0, 0);
}
else
{
Vector3 look;
look.x = -1.0;
look.y = -y;
look.z = -x;
return colorToQColor(_renderer.atmosphere->getSkyColor(&_renderer, look));
}
} }
void updateData() void updateData()
{ {
@ -91,8 +63,6 @@ private:
FormAtmosphere::FormAtmosphere(QWidget *parent): FormAtmosphere::FormAtmosphere(QWidget *parent):
BaseForm(parent) BaseForm(parent)
{ {
BaseInput* input;
_definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create(); _definition = (AtmosphereDefinition*)AtmosphereDefinitionClass.create();
previewWest = new PreviewSkyWest(this); previewWest = new PreviewSkyWest(this);

View file

@ -0,0 +1,151 @@
#include "public.h"
#include "../renderer.h"
#include "../lighting.h"
/*
* Atmosphere previews.
*/
typedef struct
{
Vector3 location;
double size;
} Mount;
#define MOUNTS_COUNT 11
static Mount MOUNTS[MOUNTS_COUNT] = {
{{2.0, 0.0, -4.0}, 4.0},
{{-1.0, 0.0, -6.0}, 4.0},
{{3.0, 0.0, -10.0}, 6.0},
{{-8.0, 0.0, -15.0}, 6.0},
{{10.0, 0.0, -20.0}, 6.0},
{{-6.0, 0.0, -30.0}, 8.0},
{{15.0, 0.0, -40.0}, 8.0},
{{-20.0, 0.0, -50.0}, 8.0},
{{10.0, 0.0, -60.0}, 10.0},
{{-5.0, 0.0, -80.0}, 10.0},
{{30.0, 0.0, -100.0}, 10.0},
};
static SurfaceMaterial MOUNT_MATERIAL = {{0.0, 0.0, 0.0, 1.0}, 0.0, 0.0};
static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit)
{
Vector3 e1, e2, h, s, q;
double a, f, u, v, t;
e1 = v3Sub(v1, v0);
e2 = v3Sub(v2, v0);
h = v3Cross(d, e2);
a = v3Dot(e1, h);
if (a > -0.00001 && a < 0.00001)
{
return 0;
}
f = 1.0 / a;
s = v3Sub(p, v0);
u = f * v3Dot(s, h);
if (u < 0.0 || u > 1.0)
{
return 0;
}
q = v3Cross(s, e1);
v = f * v3Dot(d, q);
if (v < 0.0 || u + v > 1.0)
{
return 0;
}
t = f * v3Dot(e2, q);
if (t > 0.00001)
{
*hit = v3Add(p, v3Scale(d, t));
return 1;
}
else
{
return 0;
}
}
static inline int _checkHitMountain(Vector3 eye, Vector3 direction, Mount mount, Vector3* hit)
{
Vector3 v0 = mount.location;
Vector3 v1 = mount.location;
Vector3 v2 = mount.location;
v0.x -= mount.size;
v1.x += mount.size;
v2.y += mount.size;
return _rayIntersectsTriangle(eye, direction, v0, v1, v2, hit);
}
static inline int _checkHitGround(Vector3 eye, Vector3 direction, Vector3* hit)
{
if (direction.y > -0.0001)
{
return 0;
}
else
{
hit->x = eye.x - direction.x * eye.y / direction.y;
hit->y = 0.0;
hit->z = eye.z - direction.z * eye.y / direction.y;
return 1;
}
}
static inline int _checkHit(Vector3 eye, Vector3 direction, Vector3* hit, Vector3* normal)
{
int i;
for (i = 0; i < MOUNTS_COUNT; i++)
{
if (_checkHitMountain(eye, direction, MOUNTS[i], hit))
{
*normal = VECTOR_SOUTH;
return 1;
}
}
*normal = VECTOR_UP;
return _checkHitGround(eye, direction, hit);
}
Color atmosphereGetPreview(Renderer* renderer, double x, double y, double heading)
{
Vector3 eye = {0.0, 8.0, 0.0};
Vector3 direction = {x, y, -1.0};
Vector3 hit, normal;
Matrix4 rotation;
rotation = m4NewRotateY(heading);
if (_checkHit(eye, direction, &hit, &normal))
{
Color color;
LightStatus light;
normal = m4Transform(rotation, normal);
hit = m4Transform(rotation, hit);
/* TODO Refactor lighting module for this to work */
renderer->getLightStatus(renderer, &light, hit);
color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL);
color = COLOR_BLACK;
return renderer->atmosphere->applyAerialPerspective(renderer, hit, color);
}
else
{
direction = m4Transform(rotation, direction);
return renderer->atmosphere->getSkyColor(renderer, direction);
}
}

View file

@ -75,6 +75,7 @@ extern StandardDefinition AtmosphereDefinitionClass;
extern StandardRenderer AtmosphereRendererClass; extern StandardRenderer AtmosphereRendererClass;
void atmosphereRenderSkydome(Renderer* renderer); void atmosphereRenderSkydome(Renderer* renderer);
Color atmosphereGetPreview(Renderer* renderer, double x, double y, double heading);
#ifdef __cplusplus #ifdef __cplusplus
} }