paysages : Fixes and larger render area.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@497 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-01-16 15:26:33 +00:00 committed by ThunderK
parent 804ee6943f
commit 614243b58d
9 changed files with 27 additions and 101 deletions

View file

@ -82,9 +82,7 @@ FormAtmosphere::FormAtmosphere(QWidget *parent):
addInputInt(tr("Day time (hour)"), &_definition->hour, 0, 23, 1, 10);
addInputInt(tr("Day time (minute)"), &_definition->minute, 0, 59, 1, 10);
addInputColor(tr("Sun color"), &_definition->sun_color);
addInputDouble(tr("Sun radius"), &_definition->sun_radius, 0.0, 0.4, 0.004, 0.04);
addInputDouble(tr("Sun halo radius"), &_definition->sun_halo_size, 0.0, 0.4, 0.004, 0.04);
addInputCurve(tr("Sun halo profile"), _definition->sun_halo_profile, 0.0, 1.0, 0.0, 1.0, tr("Distance to center of the sun"), tr("Light influence (halo opacity)"));
addInputDouble(tr("Sun radius"), &_definition->sun_radius, 0.0, 0.1, 0.001, 0.01);
addInputDouble(tr("Influence of skydome on lighting"), &_definition->dome_lighting, 0.0, 2.0, 0.01, 0.1);
addInputDouble(tr("Humidity"), &_definition->humidity, 0.0, 1.0, 0.01, 0.1);

View file

@ -957,22 +957,15 @@ static Color _groundColor(Color base, Vector3 x, double t, Vector3 v, Vector3 s,
}
/* direct sun light for ray x+tv, when sun in direction s (=L0) */
static Color _sunColor(Vector3 x, double t, Vector3 v, Vector3 s, double r, double mu)
static Color _sunColor(Vector3 v, Vector3 s, double r, double mu)
{
if (t > 0.0)
{
return COLOR_BLACK;
}
else
{
Color transmittance = r <= Rt ? _transmittanceWithShadow(r, mu) : COLOR_WHITE; /* T(x,xo) */
double isun = step(cos(M_PI / 180.0), v3Dot(v, s)) * ISun; /* Lsun */
transmittance.r *= isun;
transmittance.g *= isun;
transmittance.b *= isun;
transmittance.a = 1.0;
return transmittance; /* Eq (9) */
}
Color transmittance = r <= Rt ? _transmittanceWithShadow(r, mu) : COLOR_WHITE; /* T(x,xo) */
double isun = step(cos(M_PI / 180.0), v3Dot(v, s)) * ISun; /* Lsun */
transmittance.r *= isun;
transmittance.g *= isun;
transmittance.b *= isun;
transmittance.a = 1.0;
return transmittance; /* Eq (9) */
}
/*********************** Cache/debug methods ***********************/
@ -1193,53 +1186,24 @@ void brunetonInit()
texture3DDelete(_deltaJTexture);
}
static inline void _fixVector(Vector3* v)
{
double temp = v->y;
/*v->x = -v->x;*/
v->y = v->z;
v->z = temp;
}
Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position)
{
Vector3 x = {0.0, Rg + (eye.y + 10.0) * 0.01, 0.0};
_fixVector(&x);
Vector3 v = v3Normalize(direction);
_fixVector(&v);
_fixVector(&sun_position);
Vector3 s = v3Normalize(v3Sub(sun_position, x));
double r = v3Norm(x);
double mu = v3Dot(x, v) / r;
double t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rg * Rg);
Vector3 g = {x.x, x.y, x.z - Rg + 10.0};
double a = v.x * v.x + v.y * v.y - v.z * v.z;
double b = 2.0 * (g.x * v.x + g.y * v.y - g.z * v.z);
double c = g.x * g.x + g.y * g.y - g.z * g.z;
double d = -(b + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
int cone = d > 0.0 && fabs(x.z + d * v.z - Rg) <= 10.0;
if (t > 0.0)
{
if (cone && d < t)
{
t = d;
}
}
else if (cone)
{
t = d;
}
Vector3 attenuation;
Color inscatterColor = _getInscatterColor(&x, &t, v, s, &r, &mu, &attenuation); /* S[L]-T(x,xs)S[l]|xs */
Color sunColor = _sunColor(x, 0.0, v, s, r, mu); /* L0 */
Color sunColor = _sunColor(v, s, r, mu); /* L0 */
inscatterColor.r += sunColor.r;
inscatterColor.g += sunColor.g;
inscatterColor.b += sunColor.b;
return inscatterColor; /* Eq (16) */
}
@ -1250,42 +1214,25 @@ Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color
Vector3 sun_position = v3Scale(renderer->atmosphere->getSunDirection(renderer), 149597870.0);
Vector3 x = {0.0, Rg + (eye.y + 10.0) * 0.01, 0.0};
_fixVector(&x);
Vector3 v = v3Normalize(direction);
_fixVector(&v);
_fixVector(&sun_position);
Vector3 s = v3Normalize(v3Sub(sun_position, x));
if (v.y == 0.0)
{
v.y = -0.000001;
}
double r = v3Norm(x);
double mu = v3Dot(x, v) / r;
/*double t = -r * mu - sqrt(r * r * (mu * mu - 1.0) + Rg * Rg);*/
double t = v3Norm(direction);
Vector3 g = {x.x, x.y, x.z - Rg - 10.0};
double a = v.x * v.x + v.y * v.y - v.z * v.z;
double b = 2.0 * (g.x * v.x + g.y * v.y - g.z * v.z);
double c = g.x * g.x + g.y * g.y - g.z * g.z;
double d = -(b + sqrt(b * b - 4.0 * a * c)) / (2.0 * a);
int cone = d > 0.0 && fabs(x.z + d * v.z - Rg) <= 10.0;
if (t > 0.0)
{
if (cone && d < t)
{
t = d;
}
}
else if (cone)
{
t = d;
}
Vector3 attenuation;
Color inscatterColor = _getInscatterColor(&x, &t, v, s, &r, &mu, &attenuation); /* S[L]-T(x,xs)S[l]|xs */
Color groundColor = _groundColor(base, x, t, v, s, r, mu, attenuation); //R[L0]+R[L*]*/
Color groundColor = _groundColor(base, x, t, v, s, r, mu, attenuation); /*R[L0]+R[L*]*/
groundColor.r += inscatterColor.r;
groundColor.g += inscatterColor.g;
groundColor.b += inscatterColor.b;
return groundColor; /* Eq (16) */
}

View file

@ -55,7 +55,6 @@ static AtmosphereDefinition* _createDefinition()
}
result = malloc(sizeof(AtmosphereDefinition));
result->sun_halo_profile = curveCreate();
atmosphereAutoPreset(result, ATMOSPHERE_PRESET_CLEAR_DAY);
@ -64,7 +63,6 @@ static AtmosphereDefinition* _createDefinition()
static void _deleteDefinition(AtmosphereDefinition* definition)
{
curveDelete(definition->sun_halo_profile);
free(definition);
}
@ -75,12 +73,9 @@ static void _copyDefinition(AtmosphereDefinition* source, AtmosphereDefinition*
destination->minute = source->minute;
destination->sun_color = source->sun_color;
destination->sun_radius = source->sun_radius;
destination->sun_halo_size = source->sun_halo_size;
destination->dome_lighting = source->dome_lighting;
destination->humidity = source->humidity;
curveCopy(source->sun_halo_profile, destination->sun_halo_profile);
_validateDefinition(destination);
}
@ -91,8 +86,6 @@ static void _saveDefinition(PackStream* stream, AtmosphereDefinition* definition
packWriteInt(stream, &definition->minute);
colorSave(stream, &definition->sun_color);
packWriteDouble(stream, &definition->sun_radius);
packWriteDouble(stream, &definition->sun_halo_size);
curveSave(stream, definition->sun_halo_profile);
packWriteDouble(stream, &definition->dome_lighting);
packWriteDouble(stream, &definition->humidity);
}
@ -104,8 +97,6 @@ static void _loadDefinition(PackStream* stream, AtmosphereDefinition* definition
packReadInt(stream, &definition->minute);
colorLoad(stream, &definition->sun_color);
packReadDouble(stream, &definition->sun_radius);
packReadDouble(stream, &definition->sun_halo_size);
curveLoad(stream, definition->sun_halo_profile);
packReadDouble(stream, &definition->dome_lighting);
packReadDouble(stream, &definition->humidity);
@ -171,17 +162,19 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction)
}
/* Get sun halo */
if (dist < definition->sun_radius + definition->sun_halo_size)
if (dist < definition->sun_radius)
{
sun_color = definition->sun_color;
if (dist <= definition->sun_radius)
sun_color.r *= 100.0;
sun_color.g *= 100.0;
sun_color.b *= 100.0;
if (dist <= definition->sun_radius * 0.9)
{
return sun_color;
}
else
{
dist = (dist - definition->sun_radius) / definition->sun_halo_size;
sun_color.a = curveGetValue(definition->sun_halo_profile, dist);
sun_color.a = (dist - definition->sun_radius * 0.9) / (definition->sun_radius * 0.1);
colorMask(&sky_color, &sun_color);
return sky_color;
}

View file

@ -11,11 +11,6 @@ void atmosphereAutoPreset(AtmosphereDefinition* definition, AtmospherePreset pre
definition->sun_color.b = 0.9;
definition->sun_color.a = 1.0;
definition->sun_radius = 0.02;
definition->sun_halo_size = 0.3;
curveClear(definition->sun_halo_profile);
curveQuickAddPoint(definition->sun_halo_profile, 0.0, 1.0);
curveQuickAddPoint(definition->sun_halo_profile, 0.1, 0.2);
curveQuickAddPoint(definition->sun_halo_profile, 1.0, 0.0);
definition->humidity = 0.1;
switch (preset)

View file

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

View file

@ -3,7 +3,7 @@
#ifndef _PAYSAGES_ATMOSPHERE_PRIVATE_H_
#define _PAYSAGES_ATMOSPHERE_PRIVATE_H_
#define SPHERE_SIZE 1000.0
#define SPHERE_SIZE 10000.0
Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base);

View file

@ -34,8 +34,6 @@ typedef struct
double humidity;
Color sun_color;
double sun_radius;
double sun_halo_size;
Curve* sun_halo_profile;
double dome_lighting;
double _daytime;

View file

@ -65,7 +65,7 @@ void terrainRenderSurface(Renderer* renderer)
water_height = renderer->getWaterHeightInfo(renderer).max_height;
while (radius_ext < 1000.0)
while (radius_int < 5000.0)
{
if (!renderer->addRenderProgress(renderer, 0.0))
{

View file

@ -413,7 +413,7 @@ void waterRender(WaterDefinition* definition, Renderer* renderer)
radius_ext = base_chunk_size;
chunk_size = base_chunk_size;
while (radius_ext < 1000.0)
while (radius_int < 5000.0)
{
if (!renderer->addRenderProgress(renderer, 0.0))
{