From 134158c33aba8b02d516cf29590d50b6ddb3f5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Sun, 29 Dec 2013 18:44:12 +0100 Subject: [PATCH] Stars optimization and small tweaks --- src/definition/AtmosphereDefinition.cpp | 4 +-- .../preview/WaterAspectPreviewRenderer.cpp | 2 ++ src/render/software/NightSky.cpp | 30 +++++++++++-------- src/render/software/SoftwareRenderer.cpp | 6 ++-- src/render/software/TerrainRasterizer.cpp | 4 +-- .../clouds/CloudModelStratoCumulus.cpp | 6 ++-- 6 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index d1fd3c5..0cbb27f 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -154,7 +154,7 @@ void AtmosphereDefinition::applyPreset(AtmospherePreset preset) ; } - generateStars(5000); + generateStars(2000); validate(); } @@ -167,7 +167,7 @@ void AtmosphereDefinition::generateStars(int count) { Star star; - star.location = Vector3((RandomGenerator::random() - 0.5) * 100000.0, (RandomGenerator::random() - 0.5) * 100000.0, (RandomGenerator::random() - 0.5) * 100000.0); + star.location = Vector3((RandomGenerator::random() - 0.5) * 100000.0, (RandomGenerator::random() * 0.5) * 100000.0, (RandomGenerator::random() - 0.5) * 100000.0); if (star.location.getNorm() < 30000.0) { i--; diff --git a/src/render/preview/WaterAspectPreviewRenderer.cpp b/src/render/preview/WaterAspectPreviewRenderer.cpp index 0c16f58..abedac3 100644 --- a/src/render/preview/WaterAspectPreviewRenderer.cpp +++ b/src/render/preview/WaterAspectPreviewRenderer.cpp @@ -13,6 +13,8 @@ WaterAspectPreviewRenderer::WaterAspectPreviewRenderer(WaterDefinition* definiti lighting = true; background = 2; + render_quality = 3; + customData[0] = &lighting; customData[1] = &background; } diff --git a/src/render/software/NightSky.cpp b/src/render/software/NightSky.cpp index b8c1cdb..c8b107b 100644 --- a/src/render/software/NightSky.cpp +++ b/src/render/software/NightSky.cpp @@ -6,6 +6,7 @@ #include "SoftwareRenderer.h" #include "Scenery.h" #include "AtmosphereDefinition.h" +#include "AtmosphereRenderer.h" #include "SurfaceMaterial.h" #include "LightComponent.h" #include "LightStatus.h" @@ -37,23 +38,28 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction) Vector3 location(0.0, altitude, 0.0); // Get stars - for (const auto &star: atmosphere->stars) + Vector3 sun_direction = renderer->getAtmosphereRenderer()->getSunDirection(); + if (sun_direction.y < 0.1) { - if (star.location.dotProduct(direction) >= 0) + double factor = (sun_direction.y < 0.0) ? 1.0 : 1.0 - (sun_direction.y * 10.0); + for (const auto &star: atmosphere->stars) { - double radius = star.radius; - Vector3 hit1, hit2; - int hits = Geometry::rayIntersectSphere(location, direction, star.location, radius, &hit1, &hit2); - if (hits > 1) + if (star.location.dotProduct(direction) >= 0) { - double dist = hit2.sub(hit1).getNorm() / radius; // distance between intersection points (relative to radius) - - Color color = star.col; - if (dist <= 0.5) + double radius = star.radius; + Vector3 hit1, hit2; + int hits = Geometry::rayIntersectSphere(location, direction, star.location, radius, &hit1, &hit2); + if (hits > 1) { - color.a *= 1.0 - dist / 0.5; + double dist = hit2.sub(hit1).getNorm() / radius; // distance between intersection points (relative to radius) + + Color color = star.col; + if (dist <= 0.5) + { + color.a *= (1.0 - dist / 0.5) * factor; + } + result.mask(color); } - result.mask(color); } } } diff --git a/src/render/software/SoftwareRenderer.cpp b/src/render/software/SoftwareRenderer.cpp index b5fe461..1f88f17 100644 --- a/src/render/software/SoftwareRenderer.cpp +++ b/src/render/software/SoftwareRenderer.cpp @@ -141,9 +141,9 @@ void SoftwareRenderer::disableAtmosphere() light.reflection = 0.0; lights.push_back(light); - light.color.r = 0.2; - light.color.g = 0.2; - light.color.b = 0.21; + light.color.r = 0.25; + light.color.g = 0.25; + light.color.b = 0.265; light.direction.x = 1.0; light.direction.y = -0.5; light.direction.z = -1.0; diff --git a/src/render/software/TerrainRasterizer.cpp b/src/render/software/TerrainRasterizer.cpp index 72b1e20..d05892d 100644 --- a/src/render/software/TerrainRasterizer.cpp +++ b/src/render/software/TerrainRasterizer.cpp @@ -117,7 +117,7 @@ static void _getChunk(SoftwareRenderer* renderer, TerrainRasterizer::TerrainChun int coverage = renderer->render_camera->isUnprojectedBoxInView(box); if (coverage > 0) { - chunk->detail_hint = (int)ceil(sqrt((double)coverage) / (double)(25 - 2 * renderer->render_quality)); + chunk->detail_hint = (int)ceil(sqrt((double)coverage) / (double)(25 - renderer->render_quality)); if (chunk->detail_hint > 5 * renderer->render_quality) { chunk->detail_hint = 5 * renderer->render_quality; @@ -139,7 +139,7 @@ void TerrainRasterizer::getTessellationInfo(int displaced) double radius_int, radius_ext; double base_chunk_size, chunk_size; - base_chunk_size = 5.0 / (double)renderer->render_quality; + base_chunk_size = 8.0 / (double)(renderer->render_quality * renderer->render_quality); chunk_factor = 1; chunk_count = 2; diff --git a/src/render/software/clouds/CloudModelStratoCumulus.cpp b/src/render/software/clouds/CloudModelStratoCumulus.cpp index f186903..68a6c34 100644 --- a/src/render/software/clouds/CloudModelStratoCumulus.cpp +++ b/src/render/software/clouds/CloudModelStratoCumulus.cpp @@ -37,7 +37,7 @@ void CloudModelStratoCumulus::update() void CloudModelStratoCumulus::getAltitudeRange(double *min_altitude, double *max_altitude) const { - *min_altitude = 4.0 + 14.0 * layer->altitude; + *min_altitude = 10.0 + 10.0 * layer->altitude; *max_altitude = *min_altitude + 11.0 * layer->scaling; } @@ -55,9 +55,9 @@ double CloudModelStratoCumulus::getDensity(const Vector3 &location) const } else { - double x = location.x / noise_scaling; + double x = 0.3 * location.x / noise_scaling; double y = (location.y - min_altitude) / noise_scaling; - double z = location.z / noise_scaling; + double z = 0.3 * location.z / noise_scaling; //double coverage = layer->coverage * layer->_coverage_by_altitude->getValue((position.y - layer->altitude) / layer->scaling); double coverage = layer->coverage;