Atmospheric illumination and shadows
Atmospheric illumination and shadows
II I
Nelson L. Max
Lawrence Livermore National Laboratory
117
S I G G R A P H '86
3. Polygon number.
118
Dallas, August 18-22 Volume 20, Number 4, 1986
II
J
S
"7
°\
E
T
B A
Figure 2a. A scan plane through the viewpoint E and the light
source S, intersecting the view plane in line T, and three polygons in Figure 2b. Same data as in Figure 2a, rotated so that the light
segments AB, CD, and FG. The light source is in front of the view- source is behind the viewpoint.
point.
shadow edges, a n d the plane equations for the shadow polygons are the position at which it begins.
stored in shadow edge blocks, which are physically part o f the seg- In order for this to work, the scan plane m u s t be swept out in
m e n t blocks, but are also linked into separate lists. (See Table 1, order by rays from the eye m a k i n g increasing angles ~ with the light
items 8 and 9.) source direction, so that before a polygon is rendered, all polygons
In order to c o m p u t e the a t m o s p h e r i c shadows, these shadow which could cast s h a d o w s on it have been considered a n d merged
edges m u s t be sorted in the order o f increasing distance from the eye. into the shadow sort.
Since the shadow edges are all parallel, or all radiate from the light In the case s h o w n in Figure 2a, the light source is in front o f the
source, they never cross except (possibly) at the light source. There- viewer, a n d increasing ~ corresponds to increasing r, so the Watkins
fore they can be sorted in an order which r e m a i n s valid from one algorithm proceeds in the order o f increasing r. However, in the case
viewing ray to the next along a scan plane. o f Figure 2b, where the light source is behind the viewer, the situa-
W h e n the light source is at infinity, the p a r a m e t e r for the tion is reversed, and the algorithm m u s t proceed in the order o f
shadow sort is the perpendicular distance between the shadow edge decreasing r.
a n d the eye. If the light source is finite, the extended shadow edge Suppose segment AB is the current span to be rendered. In both
passes through it, and the sort p a r a m e t e r is the angle between the Figures 2a a n d 2b, a n y polygon which can cast a s h a d o w on AB m u s t
shadow edge direction a n d the line L from the light source to the eye. interest the triangle SAB. By the time this current span is reached,
The shadow edges are linked into the shadow sort list by a separate any polygons contained in the semi-infinite angle SEA h a v e already
shadow sort pointer, which identifies the shadow edge block with the been merged into the shadow sort. But we m u s t treat carefully poly-
next highest sort p a r a m e t e r m a r k i n g a transition between light (0 gons intersecting the angle AEB, and in particular, the s e g m e n t AB
shadows) or darkness (1 or m o r e shadows). (See Table 1, item 8c.) itself.
We can think o f the scan plane as m a d e up o f a collection o f rays We say a polygon is front lit if the side facing the viewer also
from the eye, ordered by the r sort in increasing angles away from the faces the light source, as is true for polygon AB in the figures. In this
sun direction. Along these rays are regions in shadow, b o u n d e d at the case, the s e g m e n t AB is merged into the shadow sort only after the r
shadow sort parameters o f the shadow edges. These regions deter- processing h a s completely passed it; otherwise it would shadow itself.
m i n e the shadowed surfaces when rendering a span, and also the T h e neglected s h a d o w s caused by this delay will not affect the final
shadowed regions in the atmosphere. picture, because segments like C D and EF, which should have been
At the appropriate time, as discussed below, each polygon in shadowed by AB, are hidden by AB.
turn m u s t have its s h a d o w edges merged into the shadow sort. T h i s 11 is also necessary to refrain from merging segments C D a n d EF
could result in no change, if the new shadow region is already in until AB has been rendered, otherwise they will cast backwards shad-
shadow, or in one or two new shadow edges, depending on the over- ows onto AB. Since C D is front lit, it is delayed by the rule already
lap with existing shadows. Old shadow edges overlapped by the new m e n t i o n e d for AB. Back lit segments like F G are merged when one
region are unlinked from the sort list, which can thus grow shorter. If o f the following conditions b e c o m e s true: (a) the s e g m e n t FG over-
care is taken to join s h a d o w regions which exactly abut, then after a laps the span to be rendered a n d lies at least partly on the sunlit side
network o f polygons defining a c o n t i n u o u s surface has been pro- o f the polygon visible in the span, (b) the s e g m e n t FG is itself a b o u t
cessed, the result in the shadow sort is the s a m e as if only shadow to be rendered, or (c) the r processing has completely passed FG.
polygons for the profile edges had been entered. (See Crow [3].) W h e n a polygon is entered into the active s e g m e n t list, its plane
Consider the scan plane through the eye E and the light source S, equation is c o m p u t e d and entered into its segment block, as coef-
as shown in Figures 2a and 2b. In Frank Crow's algorithm, the ficients of an affine function which is positive on the side o f the
shadow edges would be considered togelher with the polygon seg- polygon containing the light source. (See item 13 in Table I.) Also a
m e n t s during the two-dimensional sort constituting the hidden sur- bit (item 10) is set to 1 if the viewpoint is on the positive side o f t h i s
face algorithm on this plane. Here, we treat the shadow edges sepa- plane, so that the polygon is front lit. Segments with this bit set are
rately, in the simpler o n e - d i m e n s i o n a l merge/sort just described, merged into the shadow sort at the l i m e they are r e m o v e d from the
which accounts only for the sort p a r a m e t e r o f a s h a d o w edge, and not active segment list.
119
S I G G R A P H '86
I/ i
4. Translucency
In a forest, the leaves are translucent and light falling on the
sunlit side causes the other side to glow. (A s h a d o w is still cast, how-
ever, because the light is scattered in all directions, rather t h a n being
partially t r a n s m i t t e d along a u n i q u e refracted direction.) To get this
effect, I could n o t merely delay entering back lit translucent segments
into the s h a d o w sort, to prevent t h e m from s h a d o w i n g themselves, H G
because they m u s t still s h a d o w o t h e r polygons.
Instead, I m a i n t a i n a " ' 0 / 1 / m a n y " s h a d o w counter, which is 0 for
regions with no shadows, I for a single shadow, a n d 2 (representing
m a n y ) for regions blocked from the s u n by m o r e t h a n one polygon.
In each s h a d o w edge block is an entry for the count o f the region
b e y o n d that s h a d o w edge (item 8e in Table 1). T h e s h a d o w sort
pointer discussed above treats 2 the s a m e as 1 in deciding how to
merge a new s e g m e n t into the sort, so I call this the " 0 / m a n y " list. If
a scene h a s a n y translucent polygons, a separate 0 / l / m a n y list
pointer (item 8d) is m a i n t a i n e d for the potentially longer sort o f 0/1/
m a n y s h a d o w regions, a n d all s e g m e n t s are merged into both linked
lists. To do both merges at once, the m e r g e s u b r o u t i n e traces through Figure 3. A vertical plane through a ray R between the eye at O and
the 0 / m a n y pointers until the 0 / m a n y region containing the first a first polygon intersection point C. For clarity, the figure shows the
s h a d o w edge o f the new s e g m e n t has been found. It then follows the case w h e n the unit direction vector V to the sun lies in the s a m e
0 / m a n y a n d 0 / l / m a n y pointers separately from this point, and ad- vertical plane, so the parallel lines m a k i n g an angle of ~p with the
j u s t s the lists accordingly. If t h e 0 / m a n y list h a s N entries, the first vertical all represent sun rays or shadow edges. The ray R m a k e s an
search step takes t i m e o f order N. angle of 0 with the vertical and U is a unit vector along the ray. D E
Translucent polygons add 1 to the count o f the regions they and FG represent polygon segments casting shadows, and AB is an
shadow. W h e n the back lit side o f a translucent s e g m e n t is rendered, illuminated interval on the ray between the shadows. P = s U is a
1 is subtracted from the c o u n t to d e t e r m i n e which regions are glow- typical point in this interval. Q = s U + tV is a typical point on the
ing. O p a q u e polygons a n d front lit translucent polygons a d d 2 to the ray from P towards the sun.
count a n d are thus m o r e likely to shorten the 0 / 1 / m a n y list.
W h e n a visible s e g m e n t o f a polygon is rendered, its e n d p o i n t s
bedo of the particles, a n d on the scattering angle (see Blinn [ 11 ]). T h e
define a region o f the s h a d o w sort list, whose c o u n t s are used to
point P is at a distance s from the eye, so this scattered light is further
d e t e r m i n e the s h a d o w s on the segment. D u r i n g the sequential search
attenuated by a factor exp ( - bs). Therefore, the light reaching the
for this region in the 0 / m a n y list, t h e plane e q u a t i o n s for all s h a d o w
eye, scattered from the infinitesimal ray s e g m e n t o f length ds at P, is
polygons up to a n d including this region are copied into linearly
pI o exp [ - b (H - s cos 0) see q~] exp ( - bs) ds.
ordered data arrays. T h e s e arrays are t h e n used by the Cray-I in a
The total light reaching the eye, scatlered from the interval be-
vectorized ray/plane intersection c o m p u t a t i o n to d e t e r m i n e the illu-
t w e e n A = s i U a n d B = si + l U i s
m i n a t e d intervals along each ray from the eye. Since this ordered
data is needed, a m o r e sophisticated search taking t i m e o f order log
N cannot be used.
L~+'plo e x p [ - b H sec ~p - bs (1 - cos Osec ¢)] ds
i
5. Atmospheric illumination
;i~ I
distance to the light source is finite or infinite. e x p [ - b s ( 1 - cos Osec ~)] ~if,
First, a s s u m e the light source, like the sun, is at infinity. In Fig- = pI°exp(-bH sec ¢P) - b ( 1 - cos Osecfp)
ure 3, U is a unit vector from the eye along a viewing ray R, with the
eye at the origin O, a n d H is a height a b o v e which no data in the
which is o f the form C {exp [ - D (s i+ 1)] - exp [ - D (si)]/.
model extends. Also, V is a unit vector in the direction o f the sun, ~p
T h e constants C a n d D d e p e n d on the ray, but n o t on the dis-
is the angle between the s u n direction a n d the vertical a n d 0 is the
tances % so the s u m o f the scattered light reaching the eye from all
angle between the ray R a n d the vertical. We wish to c o m p u t e the
the illuminated intervals on a ray can be c o m p u t e d in a vectorizable
scattered light reaching the eye from a n o n - s h a d o w e d interval A B on
loop, using a vectorized exponential function.
the ray R. We first consider the absorption o f the sunlight due to the
T h i s calculation can be generalized for the case of layered fog,
haze above a point P on the interval AB.
whose density b(z) is a function o f only the altitude z a b o v e sea level.
A s s u m e that the haze h a s c o n s t a n t density a n d absorbs a frac-
Perlin [14] suggests that the integral g(z) = J~ b(u) d u be p r e c o m -
tion b dr o f the light along an infinitesimal length dr o f the ray R. If
puled and tabulated. Then, to find the total density between the eye
l(r) is the intensity at distance r t h r o u g h the haze, then [d I(r)]/I(r) =
a n d the point P = sU in Figure 3, we need only look up g (s cos 0)
- b dr, a n d by integration l(r) = I(0) exp ( - br). Let I o represent the
a n d multiply by see 0.
sunlight intensity at altitude H. In Figure 3, the z coordinate at P is
A s s u m e that the scattering coefficient p satisfies p = fib(z), with
s cos 0, so the distance r from P to T is r = P G sec q~ = (H - s cos 0)
the c o n s t a n t / 3 d e p e n d i n g only on the angle between the viewing ray
sec ~0, a n d the intensity reaching P is I o exp [ - b (H - s cos 69 sec ~p].
a n d the s u n direction. T h e n , because o f the lucky identity
In this paper, we a s s u m e a single scattering m o d e l for light diffu-
sion through haze, as described in Blinn [11] and M a x [12]. (For a
d/dz {exp [ - g(z)] } = - dg/dz [exp [ - g(z)l = - b(z) exp [ - g(z)] },
m o r e sophisticated m o d e l o f light scattering, see Kajiya [13].) Ac-
cording to the single scattering model, the dust particles or water it turns o u t that the analysis above for c o n s t a n t density can be re-
droplets in the air will scatter an a m o u n t p d s o f the light at P towards pealed for layered fog, giving a total scattering intensity o f the form
the eye. T h e scattering coefficient p d e p e n d s on the density a n d al- C see 0 {exp [ - D g (si. 1 cos 0)] - exp [ - D g (s i cos 0)]} with C a n d
120
Dallas, A u g u s t 18-22 V o l u m e 20, N u m b e r 4, 1986
III
|1 I
• si+,
i +
K ds
rift,,1 dt
K
i 1 +
d
121
~ S I G G R A P H '86
This eliminates polygons which are invisible and prevents verti- The algorithm was adapted in incremental fashion from a direct
ces behind the eye from being incorrectly projected. For a view with descendant of the original Fortran program written by Gary Watkins
shadows, such clipping might eliminate polygons which could cast to test his proposed hardware hidden surface algorithm. It was re-
shadows on visible ones. Unless the light source is within the view written by Mike Achuleta at LLNL and later modified by Bruce
volume, a larger shadow-casting volume must be found, which in- Brown, Paul Renard, and Gene Cronshagen. I found incremental
cludes all polygons which could cast shadows into the view volume. changes to an existing program easier than planning a new algorithm
The planes bounding the shadow casting volume come from two from scratch, because I could use the pictures to debug each new
lists: a) the faces of the view volume whose outward normal points feature. I wish to thank Jules Bioomenthal for the tree trunk data and
away from the light source, and b) planes formed by joining the light bark texture, Mafia Lopez for typing this paper, and Charles Grant
source direction to profile edges of the view volume. The profile for carefully reading and commenting on it.
edges can be identified as those which appear exactly once among the
edges of the faces in list a). A third list c) contains the faces of the References
view volume not in list a), as well as a near clipping plane used to [1] Williams, Lance, "'Casting Curved Shadows on Curved Sur-
avoid division by zero. faces," SIGGRAPH "78 proceedings, pp. 270-274.
All polygons are clipped to the planes in lists a) and b) to remove [2] Athenon, Peter, Weiler, Kevin, and Greenberg, Donald, "Poly-
polygons or parts of polygons which are irrelevant to the image. gon Shadow Generation," SIGGRAPH '78 proceedings, pp.
Then the planes in list c) are used to break the resulting polygons into 275-281.
two groups: the visible polygons and the shadow-only polygons. [3] Crow, Franklin, "Shadow Algorithms for Computer Graph-
The shadow-only polygons are entered into the 0 bucket sort. ics," SIGGRAPH '77 proceedings, pp. 242-248.
They need not be entered into the Watkins r - z sort, but they must [4] Nishita, Tomoyuki, Okamura, Isao, and Nakamae, Eihachiro,
be merged together as non-translucent segments in the shadow sort "Shading Models for Point and Linear Sources," ACM Trans-
lists, before the r - z sort is started. actions on Graphics, Vol 4 no. 2 (1985), pp. 124-146.
[5] Bouknight, J., and Kelly, K., "'An algorithm for producing half-
9. Summary tone computer graphics presentations with shadows and mov-
Put all edges into 0 buckets. able light sources," SJCC, AFIPS, Vol 36 (1970), pp. 1-10.
For all buckets, in order of decreasing 0: [6] Whitted, Turner " A n Improved Illumination Model for
Enter all edges from bucket 0 into r sort segment blocks. Shaded Display," Communications of the ACM, Vol 23
Merge all shadow-only segments into shadow sort. (1980), pp. 343-349.
For each visible span generated by the Watkins r - z sort: [7] Cook, Robert, Porter, Thomas, and Carpenter, Loren, "'Dis-
Merge back lit polygon segments which satisfy conditions tributed Ray Tracing," SIGGRAPH '84 proceedings, pp. 137-
(a), (b), or (c) of section 3 into shadow sort. 145.
Find intervals of light and shade on the visible span. [8] Watkins, Gary, "A real-time visible surface algorithm," Ph.D.
For each interval, approximate color functions by recur- Thesis, University o f Utah (1970) UTECH-CSc-70-101.
sively defined piecewise cubic polynomials, and scan con- [9] Sproull, Robert, and Newman, William, "'Principles oflnterac-
vert each piece into rectilinear pixel array. rive Computer Graphics" (first edition is better on this sub-
Merge front lit polygon segments which end during the span ject), McGraw Hill, New York (1973).
into shadow sort. [10] Rogers, David, "Procedural Elements for Computer Graph-
Remove edges which terminate at this 0 from active r sort. ics," McGraw Hill, New York (1985).
Update edges for next radial scan line. [11] Blinn, James, "Light Reflection Functions for Simulation of
Output final picture. Clouds and Dusty Surface," SIGGRAPH '82 proceedings, pp.
21-29.
10. Results [12] Max, Nelson, "Light Diffusion through Clouds and Haze,"
Computer Vision Graphics, and Image Processing, Vol 33
Figure 6 shows a jack-o-lantern, lit by a candle inside it. The (1986), pp, 280-292.
finite light source is within the view volume. It took approximately [13] Kajiya, James, and Von Herzen, Brian, "'Ray Tracing Volume
20 seconds to compute on the Cray-1, at 512 by 512 resolution. Fig- Densities," SIGGRAPH '84 proceedings, pp. 165-174.
ure 7 shows vertical columns o f light coming through a hole in the [14] Perlin, Ken, "State of the Art in Image Synthesis '85 Course
clouds. The sun is at infinity directly overhead, and the methods of Notes," ACM SIGGRAPH '85, course 11.
Max [12] were used to compute the atmospheric shadows from the [15] Monenson, Michael, "Geometric Modelling," John Wiley and
partially transparent clouds. Sons, New York (1985).
Figure 8 shows three polygons casting shadows on each other, on [16] Rogers, David, and Adams, J. A., "'Mathematical Elements for
the ground below, and in the atmosphere. The contrast in the atmo- Computer Graphics," McGraw Hill, New York (1976).
spheric illumination is most apparent where there is a shadow poly- [17] Catmull, Ed, and Smith, Alvey Ray, "3-D Transformations of
gon almost parallel to the line of sight. The light is at infinity above Images in Scanline Order," SIGGRAPH '80 proceedings, pp.
and behind the viewer, so the atmospheric shadows appear smaller 279-285.
near the ground, due to the perspective forshortening. Figure 9 shows [18] Max, Nelson "Anti-Aliasing Scan Line Data" to be submitted
several trees, designed by Jules Bloomenthal (see [19]), with shadow- to IEEE Computer Graphics and Applications.
mapped bark (see [20]). [19] B l o o m e n t h a l , Jules, " M o d e l l i n g the Mighty M a p l e , "
These results show that it is possible to integrate atmospheric SIGGRAPH '85 proceedings, pp. 305-311.
illumination efficiently into a scan line hidden-surface algorithm, if [20] Max, Nelson, "Shadows for Bump Mapped Surfaces," in Ad-
radial scan lines are used. vanced Computer Graphics: Proceedings of Computer Graph-
ics Tokyo "86, T. L. Kunii, ed., Springer Verlag, Tokyo (1986),
Acknowledgments pp. 145-156. To be revised and submitted to The Visual
This work was performed under the auspices o f the U.S. Depart- Computer.
ment of Energy by Lawrence Livermore National Laboratory
(LLNL) under contract number W-7405-ENG-48.
122
Dallas, August 18-22 Volume 20, Number 4, 1986
Figure 6. A jack-o-lantern, lit by a candle. Figure 8. Three polygons casting atmospheric shadows.
123
// S I G G R A P H '86
124