Wednesday, 21 September 2011

Out-Scattering integral solution.

Let me start off by saying I am a programmer, not a mathematician, so this is largely just me talking out of my ass but I did back it up with some screenshots. Onwards.

I've been going over the Atmospheric Scattering equations again, as written in GPU Gems 2.

If you look at the out-scattering equation, it is as follows:
Something about that integral just seemed like it should be solvable. So I've spent the past week thinking about it, and I finally figured it out. The -h/H0 term is the altitude of the point divided by the 'Scale Height' (the point in the atmosphere at which the density is considered 'constant' or 'average').

If we do our atmospheric scattering calculations assuming that the atmosphere is centered around the origin, then our value 'h' is just the magnitude of our sample point (S). So now we know how far the point is from the origin, and to turn that into an 'altitude' we just subtract the radius of the planet, (R). So now our expression is

exp(-(|S| - R)/H0)

We already know our points Pa and Pb, and thus we know their magnitudes and thus we can determine their altitudes, lets call them just A and B. We'll come back to this later.

So what that integral above is doing is accumulating the atmospheric density along the ray from Pa to Pb. Because this density function is only concerned with the altitude or magnitude of the points between, and the integral only really cares about the distance between Pa and Pb, which we will call N, we can mush this about to a nice 1 dimensional integral, where we just integrate along the distance of N, using it to parameterize our altitude.

let C = B - A , then our altitude at any point x between 0 and N is:

((A + (C*x/N)) - R)

drop that into our expression and we get:

exp(- ((A + (C*x/N)) - R) / H0)

then our integral becomes:

furthermore, we can scale the starting points Pa and Pb ahead of time, ie:

A = (A - R) / H0 and B = (B - R) / H0

so now we've simplified that integral to

Tada! Here's some screenshots of only out-scattering with this definite integral, and with the previous sampling method.

This is the outscattering computed with the closed form solution.

This is the same shot but using the previous sampling approximation method.

If any mathematicians out there want to verify or refute this, I would love to have a more concrete opinion of it.

No comments:

Post a Comment