Fixed atmosphere model producing artifacts below ground surface

This commit is contained in:
Michaël Lemaire 2015-12-17 19:51:40 +01:00
parent 0ab1719d25
commit f2d38f7165
3 changed files with 7 additions and 4 deletions

View file

@ -255,7 +255,7 @@ static void testAtmosphereBruneton() {
return result.final;
} else {
auto result = renderer->getAtmosphereRenderer()->applyAerialPerspective(
Vector3(-relx * 400.0, (rely + 1.0) * 20.0 - 10.0, 0.0), COLOR_BLACK);
Vector3(-relx * 400.0, (rely + 1.0) * 20.0, 0.0), COLOR_BLACK);
return result.final;
}
}

View file

@ -246,7 +246,8 @@ vec3 applyWeatherEffects(float distance, vec3 base, vec3 _attenuation, vec3 _ins
vec4 applyAerialPerspective(vec4 base)
{
vec3 x = vec3(0.0, Rg + WORKAROUND_OFFSET + cameraLocation.y * WORLD_SCALING, 0.0);
vec3 location = vec3(unprojected.x, max(unprojected.y, 0.0), unprojected.z);
vec3 x = vec3(0.0, Rg + WORKAROUND_OFFSET + max(cameraLocation.y, 0.0) * WORLD_SCALING, 0.0);
vec3 v = normalize(unprojected - cameraLocation);
vec3 s = normalize(sunDirection * SUN_DISTANCE_SCALED - x);
@ -285,7 +286,7 @@ vec4 getSkyColor(vec3 location, vec3 direction)
vec4 applyLighting(vec3 location, vec3 normal, vec4 color, float reflection, float shininess, float hardness)
{
float r0 = Rg + WORKAROUND_OFFSET + location.y * WORLD_SCALING;
float r0 = Rg + WORKAROUND_OFFSET + max(location.y, 0.0) * WORLD_SCALING;
vec3 sun_position = sunDirection * SUN_DISTANCE;
float muS = dot(vec3(0.0, 1.0, 0.0), normalize(sun_position - vec3(0.0, r0, 0.0)));

View file

@ -1095,6 +1095,8 @@ AtmosphereResult AtmosphereModelBruneton::getSkyColor(Vector3 eye, const Vector3
AtmosphereResult AtmosphereModelBruneton::applyAerialPerspective(Vector3 location, const Color &base) {
Vector3 eye = parent->getCameraLocation(location);
eye.y = max(eye.y, 0.0);
location.y = max(location.y, 0.0);
Vector3 sun_position = parent->getAtmosphereRenderer()->getSunDirection().scale(SUN_DISTANCE);
Vector3 direction = location.sub(eye).scale(WORLD_SCALING);
@ -1134,7 +1136,7 @@ bool AtmosphereModelBruneton::getLightsAt(vector<LightComponent> &result, const
LightComponent sun, irradiance;
double muS;
double altitude = location.y * WORLD_SCALING;
double altitude = max(location.y * WORLD_SCALING, 0.0);
double r0 = Rg + WORKAROUND_OFFSET + altitude;
Vector3 up = {0.0, 1.0, 0.0};