paysages : Small improvements.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@474 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-12-08 14:12:02 +00:00 committed by ThunderK
parent 2756c41188
commit de719c62dd
5 changed files with 67 additions and 40 deletions

View file

@ -19,7 +19,7 @@ public:
PreviewSkyEast(QWidget* parent): PreviewSkyEast(QWidget* parent):
BasePreview(parent) BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = atmosphereCreatePreviewRenderer();
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }
@ -42,7 +42,7 @@ public:
PreviewSkyWest(QWidget* parent): PreviewSkyWest(QWidget* parent):
BasePreview(parent) BasePreview(parent)
{ {
_renderer = rendererCreate(); _renderer = atmosphereCreatePreviewRenderer();
configScaling(0.5, 5.0, 0.5, 2.5); configScaling(0.5, 5.0, 0.5, 2.5);
} }

View file

@ -2,6 +2,7 @@
#include "../renderer.h" #include "../renderer.h"
#include "../lighting.h" #include "../lighting.h"
#include "../terrain.h"
/* /*
* Atmosphere previews. * Atmosphere previews.
@ -15,8 +16,8 @@ typedef struct
#define MOUNTS_COUNT 11 #define MOUNTS_COUNT 11
static Mount MOUNTS[MOUNTS_COUNT] = { static Mount MOUNTS[MOUNTS_COUNT] = {
{{2.0, 0.0, -4.0}, 4.0}, {{2.0, 0.0, -6.0}, 4.0},
{{-1.0, 0.0, -6.0}, 4.0}, {{-1.5, 0.0, -8.0}, 4.0},
{{3.0, 0.0, -10.0}, 6.0}, {{3.0, 0.0, -10.0}, 6.0},
{{-8.0, 0.0, -15.0}, 6.0}, {{-8.0, 0.0, -15.0}, 6.0},
{{10.0, 0.0, -20.0}, 6.0}, {{10.0, 0.0, -20.0}, 6.0},
@ -28,7 +29,7 @@ static Mount MOUNTS[MOUNTS_COUNT] = {
{{30.0, 0.0, -100.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 SurfaceMaterial MOUNT_MATERIAL = {{0.4, 0.4, 0.4, 1.0}, 0.0, 0.0};
static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit) static inline int _rayIntersectsTriangle(Vector3 p, Vector3 d, Vector3 v0, Vector3 v1, Vector3 v2, Vector3* hit)
{ {
@ -135,10 +136,8 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
normal = m4Transform(rotation, normal); normal = m4Transform(rotation, normal);
hit = m4Transform(rotation, hit); hit = m4Transform(rotation, hit);
/* TODO Refactor lighting module for this to work */
renderer->getLightStatus(renderer, &light, hit); renderer->getLightStatus(renderer, &light, hit);
color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL); color = renderer->applyLightStatus(renderer, &light, hit, normal, MOUNT_MATERIAL);
color = COLOR_BLACK;
return renderer->atmosphere->applyAerialPerspective(renderer, hit, color); return renderer->atmosphere->applyAerialPerspective(renderer, hit, color);
} }
@ -149,3 +148,31 @@ Color atmosphereGetPreview(Renderer* renderer, double x, double y, double headin
return renderer->atmosphere->getSkyColor(renderer, direction); return renderer->atmosphere->getSkyColor(renderer, direction);
} }
} }
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
{
LightingDefinition def;
def = lightingCreateDefinition();
lightingGetStatus(&def, renderer, location, status);
lightingDeleteDefinition(&def);
}
static Color _applyLightStatus(Renderer* renderer, LightStatus* status, Vector3 location, Vector3 normal, SurfaceMaterial material)
{
return lightingApplyStatusToSurface(renderer, status, location, normal, material);
}
Renderer atmosphereCreatePreviewRenderer()
{
Renderer result = rendererCreate();
result.camera_location.x = 0.0;
result.camera_location.y = 8.0;
result.camera_location.z = 0.0;
result.getLightStatus = _getLightStatus;
result.applyLightStatus = _applyLightStatus;
return result;
}

View file

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

View file

@ -68,14 +68,14 @@ static double _standardCoverageFunc(CloudsLayerDefinition* layer, Vector3 positi
CloudsLayerDefinition* cloudsLayerCreateDefinition() CloudsLayerDefinition* cloudsLayerCreateDefinition()
{ {
CloudsLayerDefinition* result; CloudsLayerDefinition* result;
result = malloc(sizeof(CloudsLayerDefinition)); result = malloc(sizeof(CloudsLayerDefinition));
result->_coverage_by_altitude = curveCreate(); result->_coverage_by_altitude = curveCreate();
result->_shape_noise = noiseCreateGenerator(); result->_shape_noise = noiseCreateGenerator();
result->_edge_noise = noiseCreateGenerator(); result->_edge_noise = noiseCreateGenerator();
result->_custom_coverage = _standardCoverageFunc; result->_custom_coverage = _standardCoverageFunc;
cloudsLayerAutoPreset(result, CLOUDS_PRESET_CIRRUS); cloudsLayerAutoPreset(result, CLOUDS_PRESET_CIRRUS);
return result; return result;
@ -95,7 +95,7 @@ void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsPreset prese
definition->material.base.g = 0.7; definition->material.base.g = 0.7;
definition->material.base.b = 0.7; definition->material.base.b = 0.7;
definition->material.base.a = 1.0; definition->material.base.a = 1.0;
switch (preset) switch (preset)
{ {
case CLOUDS_PRESET_CIRRUS: case CLOUDS_PRESET_CIRRUS:
@ -161,17 +161,17 @@ void cloudsLayerAutoPreset(CloudsLayerDefinition* definition, CloudsPreset prese
default: default:
break; break;
} }
cloudsLayerValidateDefinition(definition); cloudsLayerValidateDefinition(definition);
} }
void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinition* destination) void cloudsLayerCopyDefinition(CloudsLayerDefinition* source, CloudsLayerDefinition* destination)
{ {
CloudsLayerDefinition temp; CloudsLayerDefinition temp;
temp = *destination; temp = *destination;
*destination = *source; *destination = *source;
destination->_shape_noise = temp._shape_noise; destination->_shape_noise = temp._shape_noise;
noiseCopy(source->_shape_noise, destination->_shape_noise); noiseCopy(source->_shape_noise, destination->_shape_noise);
@ -200,7 +200,7 @@ void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
curveClear(definition->_coverage_by_altitude); curveClear(definition->_coverage_by_altitude);
noiseClearLevels(definition->_shape_noise); noiseClearLevels(definition->_shape_noise);
noiseClearLevels(definition->_edge_noise); noiseClearLevels(definition->_edge_noise);
switch (definition->type) switch (definition->type)
{ {
case CLOUDS_TYPE_CIRRUS: case CLOUDS_TYPE_CIRRUS:
@ -249,7 +249,7 @@ void cloudsLayerValidateDefinition(CloudsLayerDefinition* definition)
void _cloudsLayerSave(PackStream* stream, CloudsLayerDefinition* layer) void _cloudsLayerSave(PackStream* stream, CloudsLayerDefinition* layer)
{ {
int clouds_type = (int)layer->type; int clouds_type = (int)layer->type;
packWriteInt(stream, &clouds_type); packWriteInt(stream, &clouds_type);
packWriteDouble(stream, &layer->lower_altitude); packWriteDouble(stream, &layer->lower_altitude);
packWriteDouble(stream, &layer->thickness); packWriteDouble(stream, &layer->thickness);
@ -270,7 +270,7 @@ void _cloudsLayerSave(PackStream* stream, CloudsLayerDefinition* layer)
void _cloudsLayerLoad(PackStream* stream, CloudsLayerDefinition* layer) void _cloudsLayerLoad(PackStream* stream, CloudsLayerDefinition* layer)
{ {
int clouds_type; int clouds_type;
packReadInt(stream, &clouds_type); packReadInt(stream, &clouds_type);
layer->type = (CloudsType)clouds_type; layer->type = (CloudsType)clouds_type;
packReadDouble(stream, &layer->lower_altitude); packReadDouble(stream, &layer->lower_altitude);
@ -284,21 +284,21 @@ void _cloudsLayerLoad(PackStream* stream, CloudsLayerDefinition* layer)
packReadDouble(stream, &layer->edge_scaling); packReadDouble(stream, &layer->edge_scaling);
packReadDouble(stream, &layer->edge_length); packReadDouble(stream, &layer->edge_length);
packReadDouble(stream, &layer->base_coverage); packReadDouble(stream, &layer->base_coverage);
cloudsLayerValidateDefinition(layer); cloudsLayerValidateDefinition(layer);
} }
LayerType cloudsGetLayerType() LayerType cloudsGetLayerType()
{ {
LayerType result; LayerType result;
result.callback_create = (LayerCallbackCreate)cloudsLayerCreateDefinition; result.callback_create = (LayerCallbackCreate)cloudsLayerCreateDefinition;
result.callback_delete = (LayerCallbackDelete)cloudsLayerDeleteDefinition; result.callback_delete = (LayerCallbackDelete)cloudsLayerDeleteDefinition;
result.callback_copy = (LayerCallbackCopy)cloudsLayerCopyDefinition; result.callback_copy = (LayerCallbackCopy)cloudsLayerCopyDefinition;
result.callback_validate = (LayerCallbackValidate)cloudsLayerValidateDefinition; result.callback_validate = (LayerCallbackValidate)cloudsLayerValidateDefinition;
result.callback_save = (LayerCallbackSave)_cloudsLayerSave; result.callback_save = (LayerCallbackSave)_cloudsLayerSave;
result.callback_load = (LayerCallbackLoad)_cloudsLayerLoad; result.callback_load = (LayerCallbackLoad)_cloudsLayerLoad;
return result; return result;
} }
@ -309,7 +309,7 @@ static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3
val = noiseGet3DTotal(layer->_shape_noise, position.x / layer->shape_scaling, position.y / layer->shape_scaling, position.z / layer->shape_scaling) / noiseGetMaxValue(layer->_shape_noise); val = noiseGet3DTotal(layer->_shape_noise, position.x / layer->shape_scaling, position.y / layer->shape_scaling, position.z / layer->shape_scaling) / noiseGetMaxValue(layer->_shape_noise);
coverage = layer->_custom_coverage(layer, position); coverage = layer->_custom_coverage(layer, position);
density = 0.5 * val - 0.5 + coverage; density = 0.5 * val - 0.5 + coverage;
if (density <= 0.0) if (density <= 0.0)
{ {
/* outside the main shape */ /* outside the main shape */
@ -322,7 +322,7 @@ static inline double _getDistanceToBorder(CloudsLayerDefinition* layer, Vector3
if (density < layer->edge_length) if (density < layer->edge_length)
{ {
density /= layer->edge_length; density /= layer->edge_length;
val = 0.5 * noiseGet3DTotal(layer->_edge_noise, position.x / layer->edge_scaling, position.y / layer->edge_scaling, position.z / layer->edge_scaling) / noiseGetMaxValue(layer->_edge_noise); val = 0.5 * noiseGet3DTotal(layer->_edge_noise, position.x / layer->edge_scaling, position.y / layer->edge_scaling, position.z / layer->edge_scaling) / noiseGetMaxValue(layer->_edge_noise);
val = val - 0.5 + density; val = val - 0.5 + density;
@ -340,7 +340,7 @@ static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position,
Vector3 result = {0.0, 0.0, 0.0}; Vector3 result = {0.0, 0.0, 0.0};
Vector3 dposition; Vector3 dposition;
double val, dval; double val, dval;
val = _getDistanceToBorder(layer, position); val = _getDistanceToBorder(layer, position);
dposition.x = position.x + detail; dposition.x = position.x + detail;
@ -385,7 +385,7 @@ static inline Vector3 _getNormal(CloudsLayerDefinition* layer, Vector3 position,
static int _optimizeSearchLimits(CloudsLayerDefinition* layer, Vector3* start, Vector3* end) static int _optimizeSearchLimits(CloudsLayerDefinition* layer, Vector3* start, Vector3* end)
{ {
Vector3 diff; Vector3 diff;
if (start->y > layer->lower_altitude + layer->thickness) if (start->y > layer->lower_altitude + layer->thickness)
{ {
if (end->y >= layer->lower_altitude + layer->thickness) if (end->y >= layer->lower_altitude + layer->thickness)
@ -465,15 +465,14 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
return 0; return 0;
} }
render_precision = 15.2 - 1.5 * (double)renderer->render_quality; render_precision = 1.005 - 0.01 * (double)(renderer->render_quality * renderer->render_quality);
render_precision = render_precision * definition->shape_scaling / 150.0;
if (render_precision > max_total_length / 10.0) if (render_precision > max_total_length / 10.0)
{ {
render_precision = max_total_length / 10.0; render_precision = max_total_length / 10.0;
} }
else if (render_precision < max_total_length / 2000.0) else if (render_precision < max_total_length / 10000.0)
{ {
render_precision = max_total_length / 2000.0; render_precision = max_total_length / 10000.0;
} }
segment_count = 0; segment_count = 0;
@ -568,11 +567,11 @@ static Color _applyLayerLighting(CloudsLayerDefinition* definition, Renderer* re
normal = v3Add(normal, _getNormal(definition, position, 0.5)); normal = v3Add(normal, _getNormal(definition, position, 0.5));
} }
normal = v3Scale(v3Normalize(normal), definition->hardness); normal = v3Scale(v3Normalize(normal), definition->hardness);
renderer->getLightStatus(renderer, &light, position); renderer->getLightStatus(renderer, &light, position);
col1 = renderer->applyLightStatus(renderer, &light, position, normal, definition->material); col1 = renderer->applyLightStatus(renderer, &light, position, normal, definition->material);
col2 = renderer->applyLightStatus(renderer, &light, position, v3Scale(normal, -1.0), definition->material); col2 = renderer->applyLightStatus(renderer, &light, position, v3Scale(normal, -1.0), definition->material);
col1.r = (col1.r + col2.r) / 2.0; col1.r = (col1.r + col2.r) / 2.0;
col1.g = (col1.g + col2.g) / 2.0; col1.g = (col1.g + col2.g) / 2.0;
col1.b = (col1.b + col2.b) / 2.0; col1.b = (col1.b + col2.b) / 2.0;
@ -662,7 +661,7 @@ Color cloudsLayerFilterLight(CloudsLayerDefinition* definition, Renderer* render
factor = 1.0; factor = 1.0;
} }
} }
factor = 1.0 - (1.0 - definition->minimumlight) * factor; factor = 1.0 - (1.0 - definition->minimumlight) * factor;
light.r = light.r * factor; light.r = light.r * factor;
@ -675,7 +674,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, n; int i, n;
/* TODO Iter layers in sorted order */ /* TODO Iter layers in sorted order */
n = layersCount(definition->layers); n = layersCount(definition->layers);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)

View file

@ -23,13 +23,13 @@ struct Layers {
Layers* layersCreate(LayerType type, int max_layer_count) Layers* layersCreate(LayerType type, int max_layer_count)
{ {
Layers* result = malloc(sizeof(Layers)); Layers* result = malloc(sizeof(Layers));
result->type = type; result->type = type;
result->count = 0; result->count = 0;
result->max_count = max_layer_count; result->max_count = max_layer_count;
result->null_layer = type.callback_create(); result->null_layer = type.callback_create();
result->layers_info = malloc(sizeof(LayerInfo) * max_layer_count); result->layers_info = malloc(sizeof(LayerInfo) * max_layer_count);
return result; return result;
} }
@ -47,8 +47,8 @@ void layersDelete(Layers* layers)
{ {
layers->type.callback_delete(layers->layers_info[i].definition); layers->type.callback_delete(layers->layers_info[i].definition);
} }
free(layers->null_layer); layers->type.callback_delete(layers->null_layer);
free(layers->layers_info); free(layers->layers_info);
free(layers); free(layers);
} }
@ -56,7 +56,7 @@ void layersDelete(Layers* layers)
void layersCopy(Layers* source, Layers* destination) void layersCopy(Layers* source, Layers* destination)
{ {
int i; int i;
assert(source->type.callback_copy == destination->type.callback_copy); assert(source->type.callback_copy == destination->type.callback_copy);
assert(source->type.callback_create == destination->type.callback_create); assert(source->type.callback_create == destination->type.callback_create);
assert(source->type.callback_delete == destination->type.callback_delete); assert(source->type.callback_delete == destination->type.callback_delete);
@ -80,7 +80,7 @@ void layersCopy(Layers* source, Layers* destination)
void layersValidate(Layers* layers) void layersValidate(Layers* layers)
{ {
int i; int i;
for (i = 0; i < layers->count; i++) for (i = 0; i < layers->count; i++)
{ {
layers->type.callback_validate(layers->layers_info[i].definition); layers->type.callback_validate(layers->layers_info[i].definition);
@ -91,7 +91,7 @@ void layersValidate(Layers* layers)
void layersSave(PackStream* stream, Layers* layers) void layersSave(PackStream* stream, Layers* layers)
{ {
int i; int i;
packWriteInt(stream, &layers->count); packWriteInt(stream, &layers->count);
for (i = 0; i < layers->count; i++) for (i = 0; i < layers->count; i++)
{ {
@ -103,7 +103,7 @@ void layersSave(PackStream* stream, Layers* layers)
void layersLoad(PackStream* stream, Layers* layers) void layersLoad(PackStream* stream, Layers* layers)
{ {
int i; int i;
packReadInt(stream, &layers->count); packReadInt(stream, &layers->count);
for (i = 0; i < layers->count; i++) for (i = 0; i < layers->count; i++)
{ {
@ -159,7 +159,7 @@ int layersAddLayer(Layers* layers, void* definition)
{ {
layers->type.callback_copy(definition, layers->layers_info[layers->count].definition); layers->type.callback_copy(definition, layers->layers_info[layers->count].definition);
} }
layers->count++; layers->count++;
layersSetName(layers, layers->count - 1, "unnamed"); layersSetName(layers, layers->count - 1, "unnamed");
return layers->count - 1; return layers->count - 1;