Topics

Tuesday, November 8, 2011

Atmosphere development

After some research into physically based atmospheric models (Nishita... etc) I realized that while I understand the basic principles behind calculating optical depth, Rayleigh and Mie scattering, I don't have the necessarily Math or shader building skills to recreate them properly and optimally in Houdini. Yet :P

So meanwhile, I'm using an artist's approach. Essentially I'm "pre-computing" the scattering of different wavelengths as well as optical depth due to incident viewing angle and storing them as colors on a color ramp. It's really not as complicated as it may sound, and apparently it's a similar technique used by game programmers to render planetary atmospheres in real time (though I came up with the idea independently before reading about a similar method here).

There are two main components to the scattering:
  1. Rayleigh scattering which scatters blue wavelengths more than red, mostly responsible for blue skies and red sunsets.
  2. Mie scattering which scatters pretty much independently of wavelength, but with a strong bias towards forward scattering making the sky appear brighter around the Sun. This is really only significant if I were rendering a view of the sky from within planet's atmosphere, which I haven't planned on doing just yet :P

The scattering is dependent on the optical depth through which sunlight travels within the atmosphere, and caused by small air molecules in the case of Rayleigh and larger particles and aerosols in the case of Mie. Generally, the more distance that light travels through the air/aerosols, the more the light attenuation and scattering effect. As more blue light gets scattering in all directions, the originally white light from the Sun appears more yellow, then red (during sunrise and sunsets). The actual calculations are further complicated by phase functions which are both light and view dependent, but I've attempted to incorporate those effects into the color ramps also.

Here's how I implemented the atmospheric scattering effects:

Looking at the entire planet from far, the optical depth is minimum at the center of the planet and gets thicker as we move toward the outer edge. This is characterized by less scattering in the middle and more scattering at the circumference, which can be easily approximated using an edge falloff function modulating the opacity of the atmosphere layer.

Terminator redness has been exaggerated for visibility

So far, this only captures the scattering component from points on the Earth's surface through the atmosphere toward the viewer's eye (Earth to Viewer). On top of this, we need to add a light dependent component, which is the scattering along the optical path from the Sun through the atmosphere to the point on the Earth's surface (Sun to Earth). Once again, I used an artist's "hack", employing the standard Lambertian dot product (L.N) and using the resultant to lookup another color ramp. This was used to achieve the "red terminator" characteristic of planets with red sunsets.

The last step would be to achieve the rim falloff from bright sky blue to the blackness of space, and I have chosen to recreate this using a separate layer from the atmosphere (which employs a multi-layered volumetric approach mentioned in this post). This is also achieved using an edge falloff function driving a color ramp:

Color ramps - a CG artist's best friend when it comes to creating shaders without programming
 
In a later post I will explain how I implemented atmospheric density falloff based on altitude - i.e, the air gets thinner the higher up you go.

No comments:

Post a Comment