From 468b3628e55319f34d75c9d6fb188ee7b16ac54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 6 May 2012 08:49:12 +0000 Subject: [PATCH] paysages : Addes texture transparency at borders. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@318 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 4 +++- lib_paysages/auto.c | 3 +++ lib_paysages/textures.c | 29 +++++++++++++++++++++++++++-- lib_paysages/textures.h | 9 +-------- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index 7d4e65a..1d60719 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ Technology Preview 2 : -- Interface for textures thickness and slope_range. +- Replace zone ranges with curves. +- Interface for textures thickness, slope_range and thickness_transparency. - Render tab previews should not rerender when changing render options. - Compute shadows only once for all textures at a same location. => Add an intermediary light status (two pass lighting). @@ -36,6 +37,7 @@ Technology Preview 3 : - Multi threaded first pass. - Fix potential holes in land rendering. - Progressive final render. +- If we can't remove clouds artifacts, blur them. Release Candidate : - Polish all features and UI. diff --git a/lib_paysages/auto.c b/lib_paysages/auto.c index c6b522f..be4c441 100644 --- a/lib_paysages/auto.c +++ b/lib_paysages/auto.c @@ -161,6 +161,7 @@ void autoGenRealisticLandscape(int seed) texture->material.shininess = 3.0; texture->thickness = 0.001; texture->slope_range = 0.001; + texture->thickness_transparency = 0.0; texture = texturesGetLayer(&textures, texturesAddLayer(&textures)); zoneAddHeightRangeQuick(texture->zone, 1.0, -1.0, 0.0, 3.0, 15.0); zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.1, 0.7); @@ -176,6 +177,7 @@ void autoGenRealisticLandscape(int seed) texture->material.shininess = 2.0; texture->thickness = 0.02; texture->slope_range = 0.03; + texture->thickness_transparency = 0.005; texture = texturesGetLayer(&textures, texturesAddLayer(&textures)); zoneAddHeightRangeQuick(texture->zone, 1.0, 4.0, 5.0, 100.0, 100.0); zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.2, 1.0); @@ -190,6 +192,7 @@ void autoGenRealisticLandscape(int seed) texture->material.shininess = 0.6; texture->thickness = 0.05; texture->slope_range = 0.3; + texture->thickness_transparency = 0.015; scenerySetTextures(&textures); texturesDeleteDefinition(&textures); diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 3adea80..aabfdf4 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -15,6 +15,15 @@ static TextureLayerDefinition _NULL_LAYER; +typedef struct +{ + Vector3 location; + Vector3 normal; + double thickness; + Color color; + double thickness_transparency; +} TextureResult; + void texturesInit() { _NULL_LAYER = texturesLayerCreateDefinition(); @@ -39,6 +48,7 @@ void texturesSave(PackStream* stream, TexturesDefinition* definition) materialSave(stream, &definition->textures[i].material); packWriteDouble(stream, &definition->textures[i].thickness); packWriteDouble(stream, &definition->textures[i].slope_range); + packWriteDouble(stream, &definition->textures[i].thickness_transparency); } } @@ -64,6 +74,7 @@ void texturesLoad(PackStream* stream, TexturesDefinition* definition) materialLoad(stream, &layer->material); packReadDouble(stream, &definition->textures[i].thickness); packReadDouble(stream, &definition->textures[i].slope_range); + packReadDouble(stream, &definition->textures[i].thickness_transparency); } texturesValidateDefinition(definition); @@ -126,6 +137,7 @@ TextureLayerDefinition texturesLayerCreateDefinition() result.material.shininess = 0.0; result.thickness = 0.0; result.slope_range = 0.001; + result.thickness_transparency = 0.0; return result; } @@ -143,6 +155,7 @@ void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDef destination->bump_scaling = source->bump_scaling; destination->thickness = source->thickness; destination->slope_range = source->slope_range; + destination->thickness_transparency = source->thickness_transparency; noiseCopy(source->bump_noise, destination->bump_noise); zoneCopy(source->zone, destination->zone); } @@ -293,6 +306,7 @@ static inline TextureResult _getTerrainResult(Renderer* renderer, double x, doub result.location = center; result.color = COLOR_GREEN; result.thickness = -100.0; + result.thickness_transparency = 0.0; return result; } @@ -339,6 +353,7 @@ static inline TextureResult _getLayerResult(TextureLayerDefinition* definition, } result_center.color = renderer->applyLightingToSurface(renderer, result_center.location, result_center.normal, definition->material); + result_center.thickness_transparency = definition->thickness_transparency; return result_center; } @@ -358,6 +373,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl { TextureResult results[TEXTURES_MAX_LAYERS + 1]; Color result; + double thickness, last_height; int i; /* TODO Do not compute layers fully covered */ @@ -375,9 +391,18 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl qsort(results, definition->nbtextures + 1, sizeof(TextureResult), _cmpResults); result = results[0].color; - for (i = 0; i < definition->nbtextures; i++) + last_height = results[0].thickness; + for (i = 1; i <= definition->nbtextures; i++) { - colorMask(&result, &results[i + 1].color); + thickness = results[i].thickness - last_height; + last_height = results[i].thickness; + + if (thickness < results[i].thickness_transparency) + { + results[i].color.a = thickness / results[i].thickness_transparency; + } + + colorMask(&result, &results[i].color); } return result; diff --git a/lib_paysages/textures.h b/lib_paysages/textures.h index 685ac14..15d5478 100644 --- a/lib_paysages/textures.h +++ b/lib_paysages/textures.h @@ -22,6 +22,7 @@ typedef struct SurfaceMaterial material; double thickness; double slope_range; + double thickness_transparency; } TextureLayerDefinition; typedef struct @@ -30,14 +31,6 @@ typedef struct TextureLayerDefinition textures[TEXTURES_MAX_LAYERS]; } TexturesDefinition; -typedef struct -{ - Vector3 location; - Vector3 normal; - double thickness; - Color color; -} TextureResult; - void texturesInit(); void texturesQuit(); void texturesSave(PackStream* stream, TexturesDefinition* definition);