paysages: Small fixes to clouds interface.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@263 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-02-08 21:20:22 +00:00 committed by ThunderK
parent e7f76022ec
commit 6f0859bbe0
2 changed files with 46 additions and 41 deletions

View file

@ -79,34 +79,6 @@ void autoGenRealisticLandscape(int seed)
/* Cloud layer */ /* Cloud layer */
clouds = cloudsCreateDefinition(); clouds = cloudsCreateDefinition();
cloud = cloudsGetLayer(&clouds, cloudsAddLayer(&clouds)); cloud = cloudsGetLayer(&clouds, cloudsAddLayer(&clouds));
cloud->ymin = 10.0;
cloud->ycenter = 40.0;
cloud->ymax = 100.0;
cloud->material.base.r = 0.7;
cloud->material.base.g = 0.7;
cloud->material.base.b = 0.7;
cloud->material.reflection = 0.1;
cloud->material.shininess = 2.0;
cloud->transparencydepth = 20.0;
cloud->lighttraversal = 50.0;
cloud->minimumlight = 0.8;
cloud->scaling = 50.0;
cloud->coverage = 0.5;
noiseGenerateBaseNoise(cloud->noise, 262144);
noiseAddLevelSimple(cloud->noise, 1.0, 1.0);
noiseAddLevelSimple(cloud->noise, 1.0 / 2.0, 0.6);
noiseAddLevelSimple(cloud->noise, 1.0 / 4.0, 0.3);
noiseAddLevelSimple(cloud->noise, 1.0 / 10.0, 0.15);
noiseAddLevelSimple(cloud->noise, 1.0 / 20.0, 0.09);
noiseAddLevelSimple(cloud->noise, 1.0 / 40.0, 0.06);
noiseAddLevelSimple(cloud->noise, 1.0 / 60.0, 0.03);
noiseAddLevelSimple(cloud->noise, 1.0 / 80.0, 0.015);
noiseAddLevelSimple(cloud->noise, 1.0 / 100.0, 0.06);
noiseAddLevelSimple(cloud->noise, 1.0 / 150.0, 0.015);
noiseAddLevelSimple(cloud->noise, 1.0 / 200.0, 0.009);
noiseAddLevelSimple(cloud->noise, 1.0 / 400.0, 0.024);
noiseAddLevelSimple(cloud->noise, 1.0 / 800.0, 0.003);
noiseAddLevelSimple(cloud->noise, 1.0 / 1000.0, 0.0015);
scenerySetClouds(&clouds); scenerySetClouds(&clouds);
cloudsDeleteDefinition(&clouds); cloudsDeleteDefinition(&clouds);

View file

@ -1,6 +1,7 @@
#include "clouds.h" #include "clouds.h"
#include <string.h> #include <string.h>
#include <stdlib.h>
#include <math.h> #include <math.h>
#include "color.h" #include "color.h"
#include "euclid.h" #include "euclid.h"
@ -22,6 +23,8 @@ void cloudsInit()
{ {
NULL_LAYER.noise = noiseCreateGenerator(); NULL_LAYER.noise = noiseCreateGenerator();
NULL_LAYER.coverage = 0.0; NULL_LAYER.coverage = 0.0;
NULL_LAYER.customcoverage = NULL;
cloudsLayerValidateDefinition(&NULL_LAYER);
} }
void cloudsSave(FILE* f, CloudsDefinition* definition) void cloudsSave(FILE* f, CloudsDefinition* definition)
@ -144,18 +147,35 @@ CloudsLayerDefinition cloudsLayerCreateDefinition()
{ {
CloudsLayerDefinition result; CloudsLayerDefinition result;
result.material.base = COLOR_WHITE; result.ymin = 10.0;
result.ycenter = 40.0;
result.ymax = 100.0;
result.material.base.r = 0.7;
result.material.base.g = 0.7;
result.material.base.b = 0.7;
result.material.reflection = 0.1; result.material.reflection = 0.1;
result.material.shininess = 2.0; result.material.shininess = 2.0;
result.transparencydepth = 50.0; result.transparencydepth = 20.0;
result.lighttraversal = 50.0; result.lighttraversal = 50.0;
result.minimumlight = 0.8; result.minimumlight = 0.8;
result.scaling = 50.0;
result.coverage = 0.5; result.coverage = 0.5;
result.noise = noiseCreateGenerator(); result.noise = noiseCreateGenerator();
result.scaling = 50.0; noiseGenerateBaseNoise(result.noise, 262144);
result.ymin = 50.0; noiseAddLevelSimple(result.noise, 1.0, 1.0);
result.ycenter = 100.0; noiseAddLevelSimple(result.noise, 1.0 / 2.0, 0.6);
result.ymax = 200.0; noiseAddLevelSimple(result.noise, 1.0 / 4.0, 0.3);
noiseAddLevelSimple(result.noise, 1.0 / 10.0, 0.15);
noiseAddLevelSimple(result.noise, 1.0 / 20.0, 0.09);
noiseAddLevelSimple(result.noise, 1.0 / 40.0, 0.06);
noiseAddLevelSimple(result.noise, 1.0 / 60.0, 0.03);
noiseAddLevelSimple(result.noise, 1.0 / 80.0, 0.015);
noiseAddLevelSimple(result.noise, 1.0 / 100.0, 0.06);
noiseAddLevelSimple(result.noise, 1.0 / 150.0, 0.015);
noiseAddLevelSimple(result.noise, 1.0 / 200.0, 0.009);
noiseAddLevelSimple(result.noise, 1.0 / 400.0, 0.024);
noiseAddLevelSimple(result.noise, 1.0 / 800.0, 0.003);
noiseAddLevelSimple(result.noise, 1.0 / 1000.0, 0.0015);
result.customcoverage = _standardCoverageFunc; result.customcoverage = _standardCoverageFunc;
@ -171,6 +191,11 @@ void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinit
{ {
NoiseGenerator* noise; NoiseGenerator* noise;
if (destination == &NULL_LAYER)
{
return;
}
noise = destination->noise; noise = destination->noise;
*destination = *source; *destination = *source;
destination->noise = noise; destination->noise = noise;
@ -179,14 +204,14 @@ void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinit
void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition) void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
{ {
/*if (definition->coverage < 0.5) if (definition->scaling < 0.0001)
{ {
noiseNormalizeHeight(definition->noise, -1.0, definition->coverage * 2.0, 0); definition->scaling = 0.00001;
} }
else if (definition->customcoverage == NULL)
{ {
noiseNormalizeHeight(definition->noise, -(1.0 - definition->coverage) * 2.0, 1.0, 0); definition->customcoverage = _standardCoverageFunc;
}*/ }
} }
int cloudsGetLayerCount(CloudsDefinition* definition) int cloudsGetLayerCount(CloudsDefinition* definition)
@ -493,10 +518,16 @@ Color cloudsGetLayerColor(CloudsLayerDefinition* definition, Renderer* renderer,
return result; return result;
} }
static int _cmpLayer(const void* layer1, const void* layer2)
{
return (((CloudsLayerDefinition*)layer1)->ymin > ((CloudsLayerDefinition*)layer2)->ymin) ? -1 : 1;
}
Color cloudsGetColor(CloudsDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end) Color cloudsGetColor(CloudsDefinition* definition, Renderer* renderer, Vector3 start, Vector3 end)
{ {
int i; int i;
Color layer_color, result; Color layer_color, result;
CloudsLayerDefinition layers[CLOUDS_MAX_LAYERS];
if (definition->nblayers < 1) if (definition->nblayers < 1)
{ {
@ -504,10 +535,11 @@ Color cloudsGetColor(CloudsDefinition* definition, Renderer* renderer, Vector3 s
} }
result = COLOR_TRANSPARENT; result = COLOR_TRANSPARENT;
/* TODO Order layers */ memcpy(layers, definition->layers, sizeof(CloudsLayerDefinition) * definition->nblayers);
qsort(layers, definition->nblayers, sizeof(CloudsLayerDefinition), _cmpLayer);
for (i = 0; i < definition->nblayers; i++) for (i = 0; i < definition->nblayers; i++)
{ {
layer_color = cloudsGetLayerColor(definition->layers + i, renderer, start, end); layer_color = cloudsGetLayerColor(layers + i, renderer, start, end);
if (layer_color.a > 0.0) if (layer_color.a > 0.0)
{ {
colorMask(&result, &layer_color); colorMask(&result, &layer_color);
@ -551,6 +583,7 @@ Color cloudsLayerFilterLight(CloudsLayerDefinition* definition, Renderer* render
Color cloudsFilterLight(CloudsDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light) Color cloudsFilterLight(CloudsDefinition* definition, Renderer* renderer, Color light, Vector3 location, Vector3 light_location, Vector3 direction_to_light)
{ {
int i; int i;
/* TODO Order layers ? */
for (i = 0; i < definition->nblayers; i++) for (i = 0; i < definition->nblayers; i++)
{ {
light = cloudsLayerFilterLight(definition->layers + i, renderer, light, location, light_location, direction_to_light); light = cloudsLayerFilterLight(definition->layers + i, renderer, light, location, light_location, direction_to_light);