Skip to content

Commit

Permalink
Improved equation in the fog resolve
Browse files Browse the repository at this point in the history
- simplier equation is mathematically identical
  • Loading branch information
djewsbury committed Mar 31, 2016
1 parent dad1f00 commit 527df0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Working/Game/xleres/Lighting/RangeFogResolve.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ void LightResolve_RangeFog(RangeFogDesc desc, float distance, out float outscatt
// Approximate the amount of inscatter that gets outscattered later on... This helps
// to give the inscatter a slightly less linear shape (against distance), which can avoid
// excessive brightening in the distance (but tends to replace the brightening with darkening)
float inoutApprox = exp(-desc.MonochromeOpticalThickness * .5f * distance);
float inoutApprox = sqrt(outscatterScale);
// float inoutApprox = exp(-desc.MonochromeOpticalThickness * .5f * distance);
inscatter = desc.Inscatter * distance * inoutApprox;
}

Expand Down
10 changes: 6 additions & 4 deletions Working/Game/xleres/VolumetricEffect/resolvefog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ void CalculateTransmissionAndInscatter(
// light, so this is can important step. But the math is a bit more complex.
// inscatter = CalculateInscatter(maxDensityDistance, desc.OpticalThickness);
inscatter = maxDensityDistance * exp(-desc.OpticalThickness * .5f * maxDensityDistance);
inscatter *= exp(-desc.OpticalThickness * aveDensity * partialDistance);
float outscatter = exp(-desc.OpticalThickness * aveDensity * partialDistance);
inscatter *= outscatter;

// rough estimate for inscatter in the partial area...
// this is a cheap hack, but it works surprisingly well!
// inscatter += CalculatePartialInscatter(partialDistance, aveDensity, desc.OpticalThickness);
inscatter += aveDensity * partialDistance * exp(-desc.OpticalThickness * aveDensity * .5f * partialDistance);
inscatter += aveDensity * partialDistance * sqrt(outscatter); // exp(-desc.OpticalThickness * aveDensity * .5f * partialDistance);

} else {

Expand All @@ -72,8 +73,9 @@ void CalculateTransmissionAndInscatter(
// * CalculatePartialInscatter(partialDistance, aveDensity, desc.OpticalThickness);

inscatter = aveDensity * partialDistance * exp(-desc.OpticalThickness * aveDensity * .5f * partialDistance);
inscatter *= exp(-desc.OpticalThickness * maxDensityDistance);
inscatter += maxDensityDistance * exp(-desc.OpticalThickness * .5f * maxDensityDistance);
float outscatter = exp(-desc.OpticalThickness * maxDensityDistance);
inscatter *= outscatter;
inscatter += maxDensityDistance * sqrt(outscatter); // exp(-desc.OpticalThickness * .5f * maxDensityDistance);

}
}
Expand Down

0 comments on commit 527df0f

Please sign in to comment.