diff --git a/TODO b/TODO index 09b0c2e..502c2f3 100644 --- a/TODO +++ b/TODO @@ -5,8 +5,6 @@ Technology Preview 2 : => Add map preview with editor area. => Allow camera move and zoom. - Get rid of noise dialogs, for simpler settings. -- Finalize Bruneton's model - => Fix artifacts on aerial perspective (mostly when sun is near horizon) - Finalize lighting refactoring => Restore cloud lighting - Hide Preetham's model. @@ -16,6 +14,7 @@ Technology Preview 2 : => Covering texture height should inpact terrain height. => Add texture shadowing. - Clouds should keep distance to ground. +- Apply depth filtering to water preview. - Fix rendering when inside a cloud layer, with other upper or lower layers. - Improve cloud rendering precision (and beware of precision discontinuity when rendering clouds in front of ground (shorter distance)). - Translations. diff --git a/lib_paysages/atmosphere/bruneton.c b/lib_paysages/atmosphere/bruneton.c index 26648e7..2a64e9a 100644 --- a/lib_paysages/atmosphere/bruneton.c +++ b/lib_paysages/atmosphere/bruneton.c @@ -26,7 +26,7 @@ static const double exposure = 0.4; static const double ISun = 100.0; static const double AVERAGE_GROUND_REFLECTANCE = 0.1; -#if 0 +#if 1 #define RES_MU 128 #define RES_MU_S 32 #define RES_R 32 @@ -863,14 +863,14 @@ static Color _getInscatterColor(Vector3* _x, double* _t, Vector3 v, Vector3 s, d double muS0 = v3Dot(x0, s) / r0; /* avoids imprecision problems in transmittance computations based on textures */ *attenuation = _analyticTransmittance(r, mu, t); - if (r0 > Rg + 0.01) + if (r0 > Rg + 0.001) { /* computes S[L]-T(x,x0)S[L]|x0 */ Color attmod = {attenuation->x, attenuation->y, attenuation->z, attenuation->x}; Color samp = _texture4D(_inscatterTexture, r0, mu0, muS0, nu); inscatter = _applyInscatter(inscatter, attmod, samp); /* avoids imprecision problems near horizon by interpolating between two points above and below horizon */ - const double EPS = 0.004; + const double EPS = 0.02; double muHoriz = -sqrt(1.0 - (Rg / r) * (Rg / r)); if (fabs(mu - muHoriz) < EPS) { @@ -1151,12 +1151,15 @@ void brunetonInit() texture4DDelete(_deltaJTexture); } -Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position) +Color brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position) { - UNUSED(definition); - - /* TODO Water height ? */ - Vector3 x = {0.0, Rg + (max(eye.y, 0.0) + GROUND_OFFSET) * WORLD_SCALING, 0.0}; + double yoffset = GROUND_OFFSET - renderer->water->getHeightInfo(renderer).base_height; + eye.y += yoffset; + if (eye.y < 0.0) + { + eye.y = 0.0; + } + Vector3 x = {0.0, Rg + eye.y * WORLD_SCALING, 0.0}; Vector3 v = v3Normalize(direction); Vector3 s = v3Normalize(v3Sub(sun_position, x)); diff --git a/lib_paysages/atmosphere/main.c b/lib_paysages/atmosphere/main.c index bbb3dd6..f36d6c7 100644 --- a/lib_paysages/atmosphere/main.c +++ b/lib_paysages/atmosphere/main.c @@ -134,7 +134,7 @@ static Color _getSkyColor(Renderer* renderer, Vector3 direction) switch (definition->model) { case ATMOSPHERE_MODEL_BRUNETON: - sky_color = brunetonGetSkyColor(definition, camera_location, direction, sun_position); + sky_color = brunetonGetSkyColor(renderer, camera_location, direction, sun_position); break; case ATMOSPHERE_MODEL_PREETHAM: sky_color = preethamGetSkyColor(definition, camera_location, direction, sun_position); diff --git a/lib_paysages/atmosphere/private.h b/lib_paysages/atmosphere/private.h index aa0c03c..0550b2e 100644 --- a/lib_paysages/atmosphere/private.h +++ b/lib_paysages/atmosphere/private.h @@ -16,7 +16,7 @@ Color basicApplyAerialPerspective(Renderer* renderer, Vector3 location, Color ba void basicGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque); void brunetonInit(); -Color brunetonGetSkyColor(AtmosphereDefinition* definition, Vector3 eye, Vector3 direction, Vector3 sun_position); +Color brunetonGetSkyColor(Renderer* renderer, Vector3 eye, Vector3 direction, Vector3 sun_position); Color brunetonApplyAerialPerspective(Renderer* renderer, Vector3 location, Color base); void brunetonGetLightingStatus(Renderer* renderer, LightStatus* status, Vector3 normal, int opaque);