26 2.Modeling,Lighti ng,andRenderingTechniquesforVolumetricClouds
,,abc are the semiaxis lengths of the ellipsoid. Subtract this expression from
one to modulate the phase and vapor probabilities with distance from the ellip-
soid center. As an optimization, the cellular automaton may be limited to cells
contained by these ellipsoids, or each ellipsoid may be treated as independent
cellular automata to eliminate the storage and rendering overhead of cells that are
always empty. If you’re after cumulus clouds with flattened bottoms, using
hemiellipsoids as bounding volumes for the clouds instead of ellipsoids is also
more efficient.
You may grow your simulated clouds by placing a few random phase transi-
tion seeds at the center of each ellipsoid and iterating over the cellular automaton
a few times. The resulting 3D array of cloud states may then be stored for render-
ing, or you may continue to iterate at runtime, smoothing the cloud states in the
time domain to produce real-time animations of cloud growth. In reality, howev-
er, clouds change their shape very slowly—their growth and extinction is gener-
ally only noticeable in time-lapse photography.
SimulatingtheDistributionofClouds
We discussed using bounding ellipsoids to contain individual clouds within our
simulation, but how do we position and size these ellipsoids? Some approaches
leave the modeling of clouds entirely to artists or level designers [Wang 2004],
but procedural approaches exist to make the generation of realistic cloud volumes
easier. The Plank exponential model [Plank 1969] is one such technique, based
on the analysis of experimental data of cloud size distributions over Florida.
Plank found an exponential relationship between cloud sizes and their densi-
ty in a region of cumulus clouds; further, he found there is an upper bound of
cumulus cloud size at any given time of day, and there are fewer of these large
clouds than smaller clouds.
His algorithm may be implemented by iteratively calling the
GetNext-
Cloud()
method shown in Listing 2.2 until it returns false. GetNextCloud() is
assumed to be a method of a class that is initialized with the desired cloud cover-
age, area, and minimum and maximum cloud sizes. For the constants referenced
in the code, we use an
alpha value of 0.001, chi of 0.984, nu of 0.5, and beta of
0.10
. We use a minimum cloud size of 500 meters, a maximum of 5000 meters,
and an
epsilon of 100 meters.
bool GetNextCloud(double& width, double& depth, double& height)
{
while (currentN >= targetN)
2.2CloudLightingTechniques 27
{
currentD -= epsilon;
if (currentD <= GetMinimumSize()) return (false);
currentN = 0;
targetN = (int) (((2.0 * GetDesiredArea() * epsilon * alpha *
alpha * alpha * GetDesiredCoverage()) / (PI * chi)) *
exp(-alpha * (currentD)));
}
if (currentD <= GetMinimumSize()) return (false);
// select random diameter within currentD += bandwidth
double variationW = random() * (epsilon);
double variationH = random() * (epsilon);
width = currentD - epsilon * 0.5 + variationW;
depth = currentD - epsilon * 0.5 + variationH;
double D = (width + depth) * 0.5;
double hOverD = nu * pow(D / GetMaximumSize(), beta);
height = D * hOverD;
currentN++;
return (true);
}
Listing 2.2. The Plank exponential cloud size distribution model.
2.2CloudLightingTechniques
Clouds are not the simple translucent objects you might think they are—
somehow, these collections of water droplets and air turn opaque and white and
end up brighter than the sky behind them. As light enters a cloud, it is deflected
many times by water vapor particles (which are highly reflective) in directions
that are not entirely random. This is known as multiple scattering, and our task is
to find a way to approximate it without tracing every ray of light as it bounces
around inside the cloud.
As it turns out, for thin slabs of clouds (
100
m
), single scattering accounts
for most of the radiative transfer [Bouthors 2008]. That is, most of the light only
28 2.Modeling,Lighti ng,andRenderingTechniquesforVolumetricClouds
bounces off a single cloud droplet at this distance. This means we may approxi-
mate light transport through a cloud by dividing it up into chunks of 100 meters
or less, computing how much light is scattered and absorbed by single scattering
within each chunk, and passing the resulting light as the incident light into the
next chunk. This technique is known as multiple forward scattering [Harris
2002]. It benefits from the fact that computing the effects of single scattering is a
well-understood and simple problem, while the higher orders of scattering may
only be solved using computationally expensive Monte Carlo ray tracing tech-
niques. These higher orders of scattering are increasingly diffuse, meaning we
can reasonably approximate the missing scattered light with a simple ambient
term.
As you might guess, the chunks of cloud we just described map well to the
voxels we generated from the cellular automaton above. Multiple forward scat-
tering computes the color and transparency of a given voxel by shooting a ray
from the light source toward the voxel and iteratively compositing the scattering
and extinction from each voxel we pass through. Essentially, we accumulate the
scattering and absorption of light on a voxel-by-voxel basis, producing darker
and more opaque voxels the deeper we go into the cloud.
To compute the transparency of a given voxel in isolation, we need to com-
pute its optical depth
[Blinn 1982], given by
2
τ nπpT
.
Here, n is the number of water droplets per unit volume, p is the effective radius
of each droplet, and T is the thickness of the voxel. Physically realistic values of
p in cumulus clouds are around
0.75 μ
m
, and n is around 400 droplets per cubic
centimeter [Bouthors 2008]. The extinction of light
within this voxel is then
1
τ
α
e
.
This informs us as to the transparency of the voxel, but we still need to compute
its color due to forward scattering. The voxel’s color
C is given by
cosΘ
4
aτ P
π
L
C
.
Here, a is the albedo of the water droplets, which is very high—between 0.9 and
1.0.
L is the light color incident on the voxel (which itself may be physically
simulated [Kane 2010]), and
cosΘ
P
is the phase function of the cloud, which is
a function of the dot product between the view direction and the light direction.
2.2CloudLightingTechniques 29
The phase function is where things get interesting. Light has a tendency to
scatter in the forward direction within a cloud; this is what leads to the bright
“silver lining” you see on clouds that are lit from behind. The more accurate a
phase function you use, the more realistic your lighting effects are.
A simple phase function is the Rayleigh function [Rayleigh 1883]. Although
it is generally used to describe the scattering of atmospheric molecules and is
best known as the reason the sky is blue, it turns out to be a reasonable approxi-
mation of scattering from cloud droplets under certain cloud densities and wave-
lengths [Petty 2006] and has been used successfully in both prior research [Harris
2002] and commercial products.
1
The Rayleigh function is given by


2
3
cosΘ 1cosΘ
4
P

.
The Rayleigh function is simple enough to execute in a fragment program,
but one problem is that it scatters light equally in the backward direction and the
forward direction. For the larger particles that make up a typical cloud, the Heny-
ey-Greenstein function [Henyey and Greenstein 1941] provides a better approxi-
mation:


2
3/2
2
1
cosΘ
12cosΘ
g
P
gg

.
The parameter g describes the asymmetry of the function, and is typically high
(0.99 ). Positive values of g produce forward scattering, and negative values
produce backward scattering. Since a bit of both actually occurs, more sophisti-
cated implementations actually use a double-lobed Henyey-Greenstein function.
In this case, two functions are evaluated—one with a positive value of g and one
with a negative value, and they are blended together, heavily favoring the posi-
tive (forward) scattering component.
The ultimate phase function is given by Mie theory, which simulates actual
light waves using Maxwell’s equations in three-dimensional space [Boh-
ren and Huffman 1983]. It is dependent on the droplet size distribution within the
cloud, and as you can imagine, it is very expensive to calculate. However, a free
tool called MiePlot
2
is available to perform offline solutions to Mie scattering,
which may be stored in a texture to be looked up for a specific set of conditions.
Mie scattering not only gives you silver linings but also wavelength-dependent
1
For example, SilverLining. See http://www.sundog-soft.com/.
2
See http://www.philiplaven.com/mieplot.htm.
30 2.Modeling,Lighti ng,andRenderingTechniquesforVolumetricClouds
effects such as fogbows and glories. It has been applied in real-time successfully
by either chopping the function’s massive forward peak [Bouthers et al. 2006] or
restricting it to phase angles where wavelength-dependent effects occur, and us-
ing simpler phase functions for other angles [Petty 2006].
If you rely exclusively on multiple forward scattering of the incident sunlight
on a cloud, your cloud will appear unnaturally dark. There are other light sources
to consider—skylight, reflected light from the ground, and the light from higher-
order scattering should not be neglected. We approximate these contributions
with an ambient term; more sophisticated implementations may use hemisphere
lighting techniques [Rost and Licea-Kane 2009] to treat skylight from above and
light reflected from the ground below independently.
Tone mapping and gamma correcting the final result are also vitally im-
portant for good image quality. We use a gamma value of 2.2 together with the
simplest form of the Reinhard tone-mapping operator [Reinhard et al. 2002] with
good results:
1
d
L
L
L
.
For added realism, you’ll also want to simulate atmospheric perspective effects
on distant clouds. Exponentially blending the clouds into the sky with distance is
a simple approach that’s generally “good enough,” although more rigorous ap-
proaches are available [Preetham et al. 1999].
2.3CloudRenderingTechniques
At this point, we have a means of generating a 3D volume of voxels representing
a collection of clouds and an algorithm for lighting these voxels. Visualizing the
volumetric data described by these voxels may be achieved through a variety of
techniques.
VolumetricSplatting
The simplest technique is called splatting and is illustrated in Figure 2.2. Each
voxel is represented by a billboard that represents an individual cloud puff.
Mathematically, this texture should represent a Gaussian distribution, but adding
some wispy detail and randomly rotating it produces visually appealing results.
Figure 2.3 illustrates how a single texture representing a cloud puff is used to
generate a realistic scene of cumulus clouds.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.210.102