paysages : Textures optimizations.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@320 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
7f798cbf3d
commit
661a8b1261
3 changed files with 84 additions and 29 deletions
|
@ -178,7 +178,7 @@ void autoGenRealisticLandscape(int seed)
|
|||
texture->thickness = 0.02;
|
||||
texture->slope_range = 0.03;
|
||||
texture->thickness_transparency = 0.005;
|
||||
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
|
||||
/*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);
|
||||
noiseGenerateBaseNoise(texture->bump_noise, 102400);
|
||||
|
@ -192,7 +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;
|
||||
texture->thickness_transparency = 0.015;*/
|
||||
scenerySetTextures(&textures);
|
||||
texturesDeleteDefinition(&textures);
|
||||
|
||||
|
|
|
@ -154,20 +154,20 @@ CloudsLayerDefinition cloudsLayerCreateDefinition()
|
|||
{
|
||||
CloudsLayerDefinition result;
|
||||
|
||||
result.ymin = 10.0;
|
||||
result.ycenter = 40.0;
|
||||
result.ymax = 100.0;
|
||||
result.ymin = 4.0;
|
||||
result.ycenter = 6.0;
|
||||
result.ymax = 10.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.shininess = 2.0;
|
||||
result.hardness = 0.1;
|
||||
result.transparencydepth = 20.0;
|
||||
result.lighttraversal = 50.0;
|
||||
result.minimumlight = 0.5;
|
||||
result.scaling = 50.0;
|
||||
result.coverage = 0.5;
|
||||
result.material.reflection = 0.3;
|
||||
result.material.shininess = 0.8;
|
||||
result.hardness = 0.15;
|
||||
result.transparencydepth = 1.5;
|
||||
result.lighttraversal = 3.0;
|
||||
result.minimumlight = 0.4;
|
||||
result.scaling = 3.5;
|
||||
result.coverage = 0.45;
|
||||
result.noise = noiseCreateGenerator();
|
||||
noiseGenerateBaseNoise(result.noise, 262144);
|
||||
noiseAddLevelSimple(result.noise, 1.0, 1.0);
|
||||
|
@ -408,7 +408,16 @@ static int _findSegments(CloudsLayerDefinition* definition, Renderer* renderer,
|
|||
return 0;
|
||||
}
|
||||
|
||||
render_precision = 3.3 - 0.3 * (double)renderer->render_quality;
|
||||
render_precision = 15.2 - 1.5 * (double)renderer->render_quality;
|
||||
render_precision = render_precision * definition->scaling / 50.0;
|
||||
if (render_precision > max_total_length / 10.0)
|
||||
{
|
||||
render_precision = max_total_length / 10.0;
|
||||
}
|
||||
else if (render_precision < max_total_length / 2000.0)
|
||||
{
|
||||
render_precision = max_total_length / 2000.0;
|
||||
}
|
||||
|
||||
segment_count = 0;
|
||||
current_total_length = 0.0;
|
||||
|
|
|
@ -17,11 +17,10 @@ static TextureLayerDefinition _NULL_LAYER;
|
|||
|
||||
typedef struct
|
||||
{
|
||||
double thickness;
|
||||
Vector3 location;
|
||||
Vector3 normal;
|
||||
double thickness;
|
||||
Color color;
|
||||
double thickness_transparency;
|
||||
TextureLayerDefinition* definition;
|
||||
} TextureResult;
|
||||
|
||||
void texturesInit()
|
||||
|
@ -275,9 +274,8 @@ 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;
|
||||
result.definition = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -323,8 +321,7 @@ static inline TextureResult _getLayerResult(TextureLayerDefinition* definition,
|
|||
result_center.normal = _getNormal2(result_center.location, result_east.location, result_south.location);
|
||||
}
|
||||
|
||||
result_center.color = renderer->applyLightingToSurface(renderer, result_center.location, result_center.normal, definition->material);
|
||||
result_center.thickness_transparency = definition->thickness_transparency;
|
||||
result_center.definition = definition;
|
||||
|
||||
return result_center;
|
||||
}
|
||||
|
@ -340,19 +337,23 @@ double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* re
|
|||
return zoneGetValue(definition->zone, base.location, base.normal);
|
||||
}
|
||||
|
||||
static inline Color _getLayerColor(Renderer* renderer, TextureResult result)
|
||||
{
|
||||
return renderer->applyLightingToSurface(renderer, result.location, result.normal, result.definition->material);
|
||||
}
|
||||
|
||||
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail)
|
||||
{
|
||||
return _getLayerResult(definition, renderer, location.x, location.z, detail).color;
|
||||
return _getLayerColor(renderer, _getLayerResult(definition, renderer, location.x, location.z, detail));
|
||||
}
|
||||
|
||||
Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, double x, double z, double detail)
|
||||
{
|
||||
TextureResult results[TEXTURES_MAX_LAYERS + 1];
|
||||
Color result;
|
||||
Color result, color;
|
||||
double thickness, last_height;
|
||||
int i;
|
||||
int i, start;
|
||||
|
||||
/* TODO Do not compute layers fully covered */
|
||||
/* TODO Optimize : each layer computes the same shadows */
|
||||
|
||||
detail *= 0.1;
|
||||
|
@ -366,20 +367,65 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
|
|||
|
||||
qsort(results, definition->nbtextures + 1, sizeof(TextureResult), _cmpResults);
|
||||
|
||||
result = results[0].color;
|
||||
/* Pre compute alpha channel */
|
||||
start = 0;
|
||||
last_height = results[0].thickness;
|
||||
for (i = 1; i <= definition->nbtextures; i++)
|
||||
{
|
||||
thickness = results[i].thickness - last_height;
|
||||
last_height = results[i].thickness;
|
||||
|
||||
if (thickness < results[i].thickness_transparency)
|
||||
if (results[i].definition)
|
||||
{
|
||||
results[i].color.a = thickness / results[i].thickness_transparency;
|
||||
if (thickness < results[i].definition->thickness_transparency)
|
||||
{
|
||||
results[i].thickness = thickness / results[i].definition->thickness_transparency;
|
||||
}
|
||||
else
|
||||
{
|
||||
results[i].thickness = (thickness > 0.0) ? 1.0 : 0.0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
color = COLOR_GREEN;
|
||||
results[i].thickness = 1.0;
|
||||
}
|
||||
|
||||
colorMask(&result, &results[i].color);
|
||||
if (results[i].thickness >= 0.999999)
|
||||
{
|
||||
start = i;
|
||||
}
|
||||
|
||||
colorMask(&result, &color);
|
||||
}
|
||||
|
||||
/* Apply colors and alphas */
|
||||
if (results[start].definition)
|
||||
{
|
||||
result = _getLayerColor(renderer, results[start]);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = COLOR_GREEN;
|
||||
}
|
||||
for (i = start; i <= definition->nbtextures; i++)
|
||||
{
|
||||
if (results[i].thickness)
|
||||
{
|
||||
if (results[i].definition)
|
||||
{
|
||||
color = _getLayerColor(renderer, results[i]);
|
||||
color.a = results[i].thickness;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = COLOR_GREEN;
|
||||
}
|
||||
|
||||
colorMask(&result, &color);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue