ebruneton / precomputed_atmospheric_scattering

This project provides a new implementation of our EGSR 2008 paper "Precomputed Atmospheric Scattering".
BSD 3-Clause "New" or "Revised" License
922 stars 121 forks source link

Fix for white stripe over horizon #32

Closed MaximeDup closed 5 years ago

MaximeDup commented 5 years ago

comparison

MaximeDup commented 5 years ago

From Unreal Engine: comparison2

ebruneton commented 5 years ago

Thanks for this! It seems you ported and adapted the hack from the initial implementation? In your change 'a' is no longer used and it seems you just clamp 'mu' to some value just above the horizon?

I tried a simplified version with

--- a/atmosphere/functions.glsl
+++ b/atmosphere/functions.glsl
@@ -1806,6 +1806,14 @@ RadianceSpectrum GetSkyRadianceToPoint(
   Length d = length(point - camera);
   bool ray_r_mu_intersects_ground = RayIntersectsGround(atmosphere, r, mu);

+  // Hack to avoid rendering artifacts near the horizon, due to finite
+  // atmosphere texture resolution and finite floating point precision.
+  if (!ray_r_mu_intersects_ground) {
+    Number mu_horiz = -SafeSqrt(
+        1.0 - (atmosphere.bottom_radius / r) * (atmosphere.bottom_radius / r));
+    mu = max(mu, mu_horiz + 0.004);
+  }
+
   transmittance = GetTransmittance(atmosphere, transmittance_texture,
       r, mu, d, ray_r_mu_intersects_ground);

and it seems to give more or less the same results. Can you confirm?

MaximeDup commented 5 years ago

Result were very similar, and your solution much more elegant! I ended up not using this fix after improving my texture generation during precompute phase. Current iteration: https://www.youtube.com/watch?v=wPGMbprrtDA

MaximeDup commented 5 years ago

Screen from current UE4 version. I've read several other people implemented your latest atmosphere version in UE4, one of which gonna be sold on the marketplace. Might get better results than mine, but i'm really satisfied with mine so far! atmo

ebruneton commented 5 years ago

Impressive work! Since you don't need the patch in the end, I will not commit it.

Ralith commented 5 years ago

I ended up not using this fix after improving my texture generation during precompute phase.

Can you elaborate on what changes were necessary? Are they something that could be upstreamed here?

Ralith commented 4 years ago

I'd still love to have some clarity here. What's the proper solution to the severe artifacts that can occur?