diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index e86ef48..7df1940 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -21,7 +21,7 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery): shared_state = new OpenGLSharedState(); shared_state->set("viewDistance", 300.0); - shared_state->set("exposure", 1.6); + shared_state->set("exposure", 1.2); skybox = new OpenGLSkybox(this); water = new OpenGLWater(this); diff --git a/src/render/opengl/shaders/skybox.frag b/src/render/opengl/shaders/skybox.frag index 8acc7da..604677b 100644 --- a/src/render/opengl/shaders/skybox.frag +++ b/src/render/opengl/shaders/skybox.frag @@ -15,5 +15,7 @@ void main(void) vec3 attenuation; vec3 inscattering = _getInscatterColor(x, t, v, s, r, mu, attenuation); - gl_FragColor = applyToneMapping(sunTransmittance + vec4(inscattering, 0.0)); + gl_FragColor = vec4(0.01, 0.012, 0.03, 1.0); // night sky + gl_FragColor += sunTransmittance + vec4(inscattering, 0.0); + gl_FragColor = applyToneMapping(gl_FragColor); } diff --git a/src/render/opengl/shaders/tonemapping.frag b/src/render/opengl/shaders/tonemapping.frag index 2ea09af..5614cab 100644 --- a/src/render/opengl/shaders/tonemapping.frag +++ b/src/render/opengl/shaders/tonemapping.frag @@ -12,21 +12,23 @@ float _uncharted2Tonemap(float x) return ((x * (A * x + C * B) + D * E) / (x * (A * x + B) + D * F)) - E / F; } -vec4 applyToneMapping(vec4 color) -{ - return vec4(((color * exposure) / (1.0 + color * exposure)).rgb, 1.0); -} - /*vec4 applyToneMapping(vec4 color) { + float e = mix(exposure, exposure * 3.0, clamp(-sunDirection.y * 10.0, 0.0, 1.0)); + return vec4(((color * e) / (1.0 + color * e)).rgb, 1.0); +}*/ + +vec4 applyToneMapping(vec4 color) +{ + float e = mix(exposure, exposure * 3.0, clamp(-sunDirection.y * 10.0, 0.0, 1.0)); float W = 11.2; float white_scale = 1.0 / _uncharted2Tonemap(W); vec4 result; - result.r = pow(_uncharted2Tonemap(color.r * exposure) * white_scale, 1.0 / 2.2); - result.g = pow(_uncharted2Tonemap(color.g * exposure) * white_scale, 1.0 / 2.2); - result.b = pow(_uncharted2Tonemap(color.b * exposure) * white_scale, 1.0 / 2.2); + result.r = pow(_uncharted2Tonemap(color.r * e) * white_scale, 1.0 / 2.2); + result.g = pow(_uncharted2Tonemap(color.g * e) * white_scale, 1.0 / 2.2); + result.b = pow(_uncharted2Tonemap(color.b * e) * white_scale, 1.0 / 2.2); result.a = 1.0; return result; -}*/ +} diff --git a/src/render/software/LightStatus.cpp b/src/render/software/LightStatus.cpp index a424267..ae26119 100644 --- a/src/render/software/LightStatus.cpp +++ b/src/render/software/LightStatus.cpp @@ -6,6 +6,7 @@ LightStatus::LightStatus(LightingManager *manager, const Vector3 &location, const Vector3 &eye) { + this->max_power = 0.0; this->manager = manager; this->location = location; this->eye = eye; @@ -13,8 +14,19 @@ LightStatus::LightStatus(LightingManager *manager, const Vector3 &location, cons void LightStatus::pushComponent(LightComponent component) { + double power = component.color.getPower(); + if (component.altered && (power < max_power * 0.05 || power < 0.001)) + { + // Exclude filtered lights that are owerpowered by a previous one + return; + } + if (manager->alterLight(component, location)) { + if (power > max_power) + { + max_power = power; + } components.push_back(component); } } diff --git a/src/render/software/LightStatus.h b/src/render/software/LightStatus.h index 048bd31..947ee8a 100644 --- a/src/render/software/LightStatus.h +++ b/src/render/software/LightStatus.h @@ -25,6 +25,7 @@ public: Color apply(const Vector3 &normal, const SurfaceMaterial &material); private: + double max_power; LightingManager* manager; Vector3 location; Vector3 eye; diff --git a/src/render/software/NightSky.cpp b/src/render/software/NightSky.cpp index 4a8e2b2..b8c1cdb 100644 --- a/src/render/software/NightSky.cpp +++ b/src/render/software/NightSky.cpp @@ -72,7 +72,7 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction) double dist = hit2.sub(hit1).getNorm() / moon_radius; // distance between intersection points (relative to radius) Vector3 nearest = (hit1.sub(location).getNorm() > hit2.sub(location).getNorm()) ? hit2 : hit1; - SurfaceMaterial moon_material(Color(3.0, 3.0, 3.0, 1.0)); + SurfaceMaterial moon_material(Color(3.0, 3.0, 3.0)); moon_material.validate(); Color moon_color = renderer->applyLightingToSurface(nearest, nearest.sub(moon_position).normalize(), moon_material); @@ -91,7 +91,7 @@ const Color NightSky::getColor(double altitude, const Vector3 &direction) void NightSky::fillLightingStatus(LightStatus *status, const Vector3 &, int) { - LightComponent moon; + LightComponent moon, sky; AtmosphereDefinition* atmosphere = renderer->getScenery()->getAtmosphere(); VectorSpherical moon_location_s = {MOON_DISTANCE_SCALED, atmosphere->moon_theta, -atmosphere->moon_phi}; @@ -102,4 +102,11 @@ void NightSky::fillLightingStatus(LightStatus *status, const Vector3 &, int) moon.altered = 1; status->pushComponent(moon); + + sky.color = Color(0.01, 0.012, 0.03); + sky.direction = VECTOR_DOWN; + sky.reflection = 0.0; + sky.altered = 0; + + status->pushComponent(sky); }