paysages : Textures refactoring and improving (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@546 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-04-04 20:44:49 +00:00 committed by ThunderK
parent 701c6b35c1
commit 515a079a7f
5 changed files with 34 additions and 32 deletions

9
TODO
View file

@ -6,11 +6,10 @@ Technology Preview 2 :
- Finalize lighting/clouds refactoring - Finalize lighting/clouds refactoring
=> Restore cloud lighting => Restore cloud lighting
=> Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)). => Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)).
- Improve textures (current model is greatly incorrect). - Finish texture refactoring.
=> Use triplanar projection. => Push displaced polygons, but keep undisplaced coordinates for second pass.
=> Separate models (basic texture and covering texture). => Add detail texture.
=> Covering texture height should inpact terrain height. => Displacement on 3d explorer and previews.
=> Add texture shadowing.
- Fix rendering when inside a cloud layer, with other upper or lower layers. - Fix rendering when inside a cloud layer, with other upper or lower layers.
- Translations. - Translations.

View file

@ -141,7 +141,7 @@ static inline Vector3 _getNormal2(Vector3 center, Vector3 east, Vector3 south)
static TerrainResult _realGetResult(Renderer* renderer, double x, double z, int with_painting, int with_textures) static TerrainResult _realGetResult(Renderer* renderer, double x, double z, int with_painting, int with_textures)
{ {
TerrainResult result; TerrainResult result;
double detail = 0.01; double detail = 0.001; /* TODO */
/* Normal */ /* Normal */
Vector3 center, north, east, south, west; Vector3 center, north, east, south, west;
@ -158,7 +158,7 @@ static TerrainResult _realGetResult(Renderer* renderer, double x, double z, int
south.z = z + detail; south.z = z + detail;
south.y = renderer->terrain->getHeight(renderer, south.x, south.z, with_painting); south.y = renderer->terrain->getHeight(renderer, south.x, south.z, with_painting);
if (renderer->render_quality > 5) if (renderer->render_quality > 6)
{ {
west.x = x - detail; west.x = x - detail;
west.z = z; west.z = z;
@ -181,10 +181,11 @@ static TerrainResult _realGetResult(Renderer* renderer, double x, double z, int
/* Texture displacement */ /* Texture displacement */
if (with_textures) if (with_textures)
{ {
center = result.location = renderer->textures->displaceTerrain(renderer, result); center = renderer->textures->displaceTerrain(renderer, result);
result.location = center;
/* TODO Recompute normal */ /* Recompute normal */
if (renderer->render_quality > 7) if (renderer->render_quality > 6)
{ {
/* Use 5 points on displaced terrain */ /* Use 5 points on displaced terrain */
east = renderer->textures->displaceTerrain(renderer, _realGetResult(renderer, east.x, east.z, with_painting, 0)); east = renderer->textures->displaceTerrain(renderer, _realGetResult(renderer, east.x, east.z, with_painting, 0));
@ -204,7 +205,7 @@ static TerrainResult _realGetResult(Renderer* renderer, double x, double z, int
} }
else else
{ {
/* Use texture noise directly, as if terrain was a plane */ /* TODO Use texture noise directly, as if terrain was a plane */
} }
} }
@ -301,11 +302,7 @@ static int _alterLight(Renderer* renderer, LightDefinition* light, Vector3 locat
double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length; double inc_value, inc_base, inc_factor, height, diff, light_factor, smoothing, length;
direction_to_light = v3Scale(light->direction, -1.0); direction_to_light = v3Scale(light->direction, -1.0);
if ((fabs(direction_to_light.x) < 0.0001 && fabs(direction_to_light.z) < 0.0001) || definition->height < 0.001) if (direction_to_light.y < -0.05)
{
return 0;
}
else if (direction_to_light.y < 0.05)
{ {
light->color = COLOR_BLACK; light->color = COLOR_BLACK;
return 1; return 1;
@ -330,7 +327,7 @@ static int _alterLight(Renderer* renderer, LightDefinition* light, Vector3 locat
inc_vector = v3Scale(direction_to_light, inc_value); inc_vector = v3Scale(direction_to_light, inc_value);
length += v3Norm(inc_vector); length += v3Norm(inc_vector);
location = v3Add(location, inc_vector); location = v3Add(location, inc_vector);
height = _realGetHeight(renderer, location.x, location.z, 1); height = renderer->terrain->getResult(renderer, location.x, location.z, 1, 1).location.y;
diff = location.y - height; diff = location.y - height;
if (diff < 0.0) if (diff < 0.0)
{ {

View file

@ -29,14 +29,19 @@ static Color _postProcessFragment(Renderer* renderer, Vector3 point, void* data)
return renderer->terrain->getFinalColor(renderer, point, precision); return renderer->terrain->getFinalColor(renderer, point, precision);
} }
static void _renderQuad(TerrainDefinition* definition, Renderer* renderer, double x, double z, double size, double water_height) static void _renderQuad(Renderer* renderer, double x, double z, double size, double water_height)
{ {
Vector3 v1, v2, v3, v4; Vector3 v1, v2, v3, v4;
v1 = _getPoint(definition, renderer, x, z); /*v1 = _getPoint(definition, renderer, x, z);
v2 = _getPoint(definition, renderer, x, z + size); v2 = _getPoint(definition, renderer, x, z + size);
v3 = _getPoint(definition, renderer, x + size, z + size); v3 = _getPoint(definition, renderer, x + size, z + size);
v4 = _getPoint(definition, renderer, x + size, z); v4 = _getPoint(definition, renderer, x + size, z);*/
v1 = renderer->terrain->getResult(renderer, x, z, 1, 1).location;
v2 = renderer->terrain->getResult(renderer, x, z + size, 1, 1).location;
v3 = renderer->terrain->getResult(renderer, x + size, z + size, 1, 1).location;
v4 = renderer->terrain->getResult(renderer, x + size, z, 1, 1).location;
if (v1.y > water_height || v2.y > water_height || v3.y > water_height || v4.y > water_height) if (v1.y > water_height || v2.y > water_height || v3.y > water_height || v4.y > water_height)
{ {
@ -53,14 +58,13 @@ void terrainRenderSurface(Renderer* renderer)
double min_chunk_size, visible_chunk_size; double min_chunk_size, visible_chunk_size;
double radius_int, radius_ext, chunk_size; double radius_int, radius_ext, chunk_size;
double water_height; double water_height;
TerrainDefinition* definition = renderer->terrain->definition;
min_chunk_size = 0.1 / (double)renderer->render_quality; min_chunk_size = 0.2 / (double)renderer->render_quality;
visible_chunk_size = 0.05 / (double)renderer->render_quality; visible_chunk_size = 0.1 / (double)renderer->render_quality;
if (renderer->render_quality > 7) if (renderer->render_quality > 7)
{ {
min_chunk_size *= 0.5; min_chunk_size *= 0.25;
visible_chunk_size *= 0.5; visible_chunk_size *= 0.25;
} }
chunk_factor = 1; chunk_factor = 1;
@ -80,10 +84,10 @@ void terrainRenderSurface(Renderer* renderer)
for (i = 0; i < chunk_count - 1; i++) for (i = 0; i < chunk_count - 1; i++)
{ {
_renderQuad(definition, renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, water_height); _renderQuad(renderer, cx - radius_ext + chunk_size * i, cz - radius_ext, chunk_size, water_height);
_renderQuad(definition, renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, water_height); _renderQuad(renderer, cx + radius_int, cz - radius_ext + chunk_size * i, chunk_size, water_height);
_renderQuad(definition, renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, water_height); _renderQuad(renderer, cx + radius_int - chunk_size * i, cz + radius_int, chunk_size, water_height);
_renderQuad(definition, renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, water_height); _renderQuad(renderer, cx - radius_ext, cz + radius_int - chunk_size * i, chunk_size, water_height);
} }
if (chunk_count % 64 == 0 && chunk_size / radius_int < visible_chunk_size) if (chunk_count % 64 == 0 && chunk_size / radius_int < visible_chunk_size)

View file

@ -57,7 +57,8 @@ static void _layerValidateDefinition(TexturesLayerDefinition* definition)
} }
noiseClearLevels(definition->_displacement_noise); noiseClearLevels(definition->_displacement_noise);
noiseAddLevelsSimple(definition->_displacement_noise, 3, 1.0, -1.0, 1.0, 0.0); noiseAddLevelsSimple(definition->_displacement_noise, 4, 1.0, -1.0, 1.0, 0.0);
noiseNormalizeAmplitude(definition->_displacement_noise, -1.0, 1.0, 0);
noiseValidate(definition->_displacement_noise); noiseValidate(definition->_displacement_noise);
} }
@ -68,7 +69,7 @@ static TexturesLayerDefinition* _layerCreateDefinition()
result = malloc(sizeof(TexturesLayerDefinition)); result = malloc(sizeof(TexturesLayerDefinition));
result->terrain_zone = zoneCreate(); result->terrain_zone = zoneCreate();
result->displacement_scaling = 0.1; result->displacement_scaling = 2.0;
result->displacement_height = 0.1; result->displacement_height = 0.1;
result->displacement_offset = 0.0; result->displacement_offset = 0.0;
result->material.base = COLOR_WHITE; result->material.base = COLOR_WHITE;

View file

@ -42,7 +42,8 @@ static Vector3 _realDisplaceTerrain(Renderer* renderer, TerrainResult terrain)
if (layer->displacement_height > 0.0) if (layer->displacement_height > 0.0)
{ {
double presence = texturesGetLayerBasePresence(layer, terrain); double presence = texturesGetLayerBasePresence(layer, terrain);
offset += texturesGetTriplanarNoise(layer->_displacement_noise, terrain.location, terrain.normal) * presence * layer->displacement_height; Vector3 location = {terrain.location.x / layer->displacement_scaling, terrain.location.y / layer->displacement_scaling, terrain.location.z / layer->displacement_scaling};
offset += texturesGetTriplanarNoise(layer->_displacement_noise, location, terrain.normal) * presence * layer->displacement_height;
} }
} }