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
908 stars 120 forks source link

Removed double extrapolation of single mie scattering with COMBINED_SCATTERING_TEXTURES #47

Closed alextyurin closed 1 year ago

alextyurin commented 1 year ago

Hi! Looks like I found a bug with COMBINED_SCATTERING_TEXTURES. As you can see above, the single_mie_scattering is already unpacked returned from the function GetCombinedScattering:

IrradianceSpectrum GetCombinedScattering(
    IN(AtmosphereParameters) atmosphere,
    IN(ReducedScatteringTexture) scattering_texture,
    IN(ReducedScatteringTexture) single_mie_scattering_texture,
    Length r, Number mu, Number mu_s, Number nu,
    bool ray_r_mu_intersects_ground,
    OUT(IrradianceSpectrum) single_mie_scattering) {
...
#ifdef COMBINED_SCATTERING_TEXTURES
  vec4 combined_scattering =
      texture(scattering_texture, uvw0) * (1.0 - lerp) +
      texture(scattering_texture, uvw1) * lerp;
  IrradianceSpectrum scattering = IrradianceSpectrum(combined_scattering);
  single_mie_scattering =
      GetExtrapolatedSingleMieScattering(atmosphere, combined_scattering);
#else
...
  return scattering;
}

Therefore, re-unpacking to single_mie_scattering in a GetSkyRadianceToPoint looks incorrect.

alextyurin commented 1 year ago

I figured it out and realized that it was on purpose to calculate single_mie_scattering by the difference in the red channel instead of the difference of the extrapolated values