Skip to content

Commit

Permalink
scattering: optimize lightDepth along thw view ray
Browse files Browse the repository at this point in the history
  • Loading branch information
McPain committed Sep 6, 2023
1 parent 42be989 commit bb3519a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions data/shaders/opengl/geosphere_sky.frag
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,20 @@ vec3 computeIncidentLight(const in vec3 sunDirection, in vec3 orig, const in vec
getCoefficients(kR, bR, cR, earthRadius, atmosphereHeight, Hr);
getCoefficients(kM, bM, cM, earthRadius, atmosphereHeight, Hm);

float h, t;
findClosestHeight(h, t, orig, dir, center);
h -= earthRadius;

opticalDepthR = predictDensityOut(atmosphereHeight, h, kR, bR);
opticalDepthM = predictDensityOut(atmosphereHeight, h, kM, bM);

opticalDepthR *= predictDensityIn(earthRadius, atmosphereHeight, h, cR, t);
opticalDepthM *= predictDensityIn(earthRadius, atmosphereHeight, h, cM, t);

for (int i = 0; i < numSamples; ++i) {
vec3 samplePosition = orig + vec3(tCurrent + segmentLength * 0.5f) * dir;
float hr, hm;
scatter(hr, hm, samplePosition, center);
opticalDepthR += exp(hr) * segmentLength;
opticalDepthM += exp(hm) * segmentLength;

// light optical depth
{
Expand Down

0 comments on commit bb3519a

Please sign in to comment.