Tuesday, October 2, 2012

Ray Marching

Because the properties of the atmosphere vary with altitude, I can't just use the scattering and absorption properties at a single point to compute scattering and absorption along a ray. Instead, I implemented a ray-marching system that takes fixed-size steps along each ray. Each step forms a line segment. For each segment, I use the altitude, density, and Rayleigh scattering coefficient from the midpoint of the segment, and assume that these properties are constant along the span of the segment. This allows me to compute a random scattering distance (or absorption distance, but I've only implemented Rayleigh scattering so far) by importance sampling the exponential falloff of unscattered light. If the sampled scattering distance is less than the length of the segment (i.e., if the scattering point falls within the segment), I scatter it, otherwise I proceed to the next segment. By decreasing the step size, the simulation can be made more accurate, but you get diminishing returns at a certain point, slowing down the program without a noticeable increase in accuracy. I am considering implementing adaptive step sizes based on the density of the air.

No comments:

Post a Comment