Skip to content

Commit

Permalink
Annotate Rayleigh-related functions in SystemBody
Browse files Browse the repository at this point in the history
  • Loading branch information
Mc-Pain committed Jan 18, 2024
1 parent 8e76555 commit 80a4740
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/galaxy/SystemBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ bool SystemBody::IsScoopable() const
return false;
}

// this is a reduced version of original Rayleigh scattering function used to compute density once per planet
// (at least it meant not to be once per frame) given:
// planet radius, height of atmosphere (not its radius), length of perpendicular between ray and planet center, lapse rate at which density fades out by rate of e
// this function is used in GetCoefficients
// all input units are in km
double SystemBody::ComputeDensity(const double radius, const double atmosphereHeight, const double h, const double baricStep) const
{
Expand All @@ -283,13 +287,20 @@ double SystemBody::ComputeDensity(const double radius, const double atmosphereHe
return density;
}

// these coefficients are to be passed into shaders, meant to accelerate scattering computation per-pixel
// instead of sampling each one (which I suspect is VERY SLOW)
// all input units are in km
vector3f SystemBody::GetCoefficients(const double radius, const double atmHeight, const double baricStep) const
{
float k, b, c;

// compute full out-scattering densities at 0 and 1 km heights
// k = density at 0 km
// b = log(density0km / density1km) - log is used to multiply it by actual height
k = ComputeDensity(radius, atmHeight, 0.f, baricStep);
b = log(k / ComputeDensity(radius, atmHeight, 1.f, baricStep));

// compute c - erf coefficient, which adjusts slope of erf near t=0 to match actual in-scattering
float erf1_minus_erf0 = 0.421463;
float sHeight = sqrt(radius*radius + 1.f) - radius;
float c1 = exp(-sHeight / baricStep);
Expand Down

0 comments on commit 80a4740

Please sign in to comment.