14.12.2012 Views

Rendering Outdoor Light Scattering in Real Time

Rendering Outdoor Light Scattering in Real Time

Rendering Outdoor Light Scattering in Real Time

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Render<strong>in</strong>g</strong> <strong>Outdoor</strong> <strong>Light</strong><br />

<strong>Scatter<strong>in</strong>g</strong> <strong>in</strong> <strong>Real</strong> <strong>Time</strong><br />

Naty Hoffman<br />

Westwood Studios<br />

naty@westwood.com<br />

make<br />

better<br />

games<br />

Arcot J Preetham<br />

ATI Research<br />

preetham@ati.com


Outl<strong>in</strong>e<br />

– Basics<br />

• Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Radiometric Quantities<br />

• From Radiance to Pixels<br />

– <strong>Scatter<strong>in</strong>g</strong> Theory<br />

• Absorption, Out-<strong>Scatter<strong>in</strong>g</strong>, In-<strong>Scatter<strong>in</strong>g</strong><br />

• Rayleigh and Mie <strong>Scatter<strong>in</strong>g</strong><br />

– Implementation<br />

• Aerial Perspective, Sunlight, Skylight<br />

• Vertex Shader<br />

– Future Work<br />

make<br />

better<br />

games


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Is caused by a variety of particles<br />

– Molecules, dust, water vapor, etc.<br />

• These can cause light to be:<br />

– Scattered <strong>in</strong>to the l<strong>in</strong>e of sight (<strong>in</strong>-scatter<strong>in</strong>g)<br />

– Scattered out of the l<strong>in</strong>e of sight (out-scatter<strong>in</strong>g)<br />

– Absorbed altogether (absorption)<br />

make<br />

better<br />

games


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Illum<strong>in</strong>ates the sky


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Attenuates and colors the Sun


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Attenuates and colors distant objects


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Varies by<br />

– <strong>Time</strong> of Day<br />

– Weather<br />

– Pollution


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Varies by<br />

– <strong>Time</strong> of Day<br />

– Weather<br />

– Pollution


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Varies by<br />

– <strong>Time</strong> of Day<br />

– Weather<br />

– Pollution


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Varies by<br />

– <strong>Time</strong> of Day<br />

– Weather<br />

– Pollution


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Varies between planets


Atmospheric <strong>Light</strong> <strong>Scatter<strong>in</strong>g</strong><br />

• Ext<strong>in</strong>ction (Absorption, Out-scatter<strong>in</strong>g)<br />

– Phenomena which remove light<br />

– Multiplicative:<br />

• In-scatter<strong>in</strong>g:<br />

– Phenomenon which adds light<br />

– Additive:<br />

• Comb<strong>in</strong>ed:<br />

L<strong>in</strong><br />

L =<br />

ext<strong>in</strong>ction<br />

make<br />

better<br />

games<br />

F<br />

ex<br />

L =<br />

F L +<br />

scatter<strong>in</strong>g<br />

ex<br />

0<br />

L<br />

L<br />

0<br />

<strong>in</strong>


Radiometric Quantities<br />

• Radiant Flux<br />

• Radiance<br />

• Irradiance<br />

make<br />

better<br />

games


Radiometric Quantities<br />

• Radiant Flux Φ<br />

– Quantity of light through a surface<br />

– Radiant power (energy / time)<br />

– Watt<br />

make<br />

better<br />

games


Radiometric Quantities<br />

• Radiance L<br />

– Quantity of light <strong>in</strong> a s<strong>in</strong>gle ray<br />

– Radiant flux / area / solid angle<br />

– Watt / (meter 2 * steradian)<br />

make<br />

better<br />

games


Radiometric Quantities<br />

• Irradiance E<br />

– Quantity of light <strong>in</strong>cident to a surface po<strong>in</strong>t<br />

– Incident radiant flux / area (Watt / meter 2 )<br />

– Radiance <strong>in</strong>tegrated over hemisphere<br />

make<br />

better<br />

games


From Radiance to Pixels<br />

• Compute radiance <strong>in</strong>cident to eye<br />

through each screen pixel<br />

make<br />

better<br />

games


From Radiance to Pixels<br />

• Pixel value based on radiance<br />

• But radiance is distributed<br />

cont<strong>in</strong>uously along the spectrum<br />

– We need three numbers: R, G, B<br />

make<br />

better<br />

games


From Radiance to Pixels<br />

• SPD (Spectral Power Distribution) to RGB<br />

S<br />

– Fast approach:<br />

• Do all math at R, G, B sample wavelengths<br />

– Correct approach:<br />

• Use SPDs, convert f<strong>in</strong>al radiance to RGB<br />

M L<br />

400nm 500nm 600nm 700nm<br />

make<br />

better<br />

games


Absorption<br />

• Absorption cross section ó ab<br />

– Absorbed radiant flux per unit <strong>in</strong>cident<br />

irradiance Φ / E<br />

– Units of area (meter 2 )<br />

make<br />

better<br />

games<br />

ó ab


Absorption<br />

• Absorption cross section ó ab<br />

Φ = E * ó ab<br />

make<br />

better<br />

games<br />

ó ab = Φ / E<br />

ó ab


Absorption<br />

• Absorption coefficient â ab<br />

– Particle density ñ ab times<br />

absorption cross section ó ab<br />

– Units of <strong>in</strong>verse length (meter -1 )<br />

make<br />

better<br />

games


Absorption<br />

• Total absorption cross section:<br />

A ab = ó ab ñ ab A dx<br />

• Probability of absorption:<br />

P ab = A ab / A = ó ab ñ ab dx = â ab dx<br />

A<br />

dx<br />

make<br />

better<br />

games


Absorption<br />

• Attenuation of radiance from travel<br />

through a constant-density<br />

absorptive medium:<br />

L 0<br />

L<br />

( s)<br />

s<br />

=<br />

L<br />

make<br />

better<br />

games<br />

0<br />

e<br />

− β<br />

ab<br />

s<br />

L(s)


Out-<strong>Scatter<strong>in</strong>g</strong><br />

• Exactly as <strong>in</strong> the absorption case<br />

– <strong>Scatter<strong>in</strong>g</strong> cross section ó sc<br />

– <strong>Scatter<strong>in</strong>g</strong> coefficient â ñ ó sc = sc sc<br />

– Attenuation due to out-scatter<strong>in</strong>g <strong>in</strong><br />

a constant-density medium:<br />

L(<br />

s)<br />

= L e<br />

− β<br />

0<br />

ósc make<br />

better<br />

games<br />

sc<br />

s


L<br />

( s)<br />

Ext<strong>in</strong>ction<br />

• Both absorption and out-scatter<strong>in</strong>g<br />

attenuate light<br />

• They can be comb<strong>in</strong>ed as ext<strong>in</strong>ction<br />

• Ext<strong>in</strong>ction coefficient β ex = β ab + β sc<br />

• Total attenuation from ext<strong>in</strong>ction<br />

s<br />

= L e ex F ( s)<br />

=<br />

e<br />

−β<br />

ex s<br />

0<br />

−β<br />

make<br />

better<br />

games<br />

ex


In-<strong>Scatter<strong>in</strong>g</strong><br />

• <strong>Light</strong> is scattered <strong>in</strong>to a view ray<br />

from all directions<br />

– From the sun<br />

– From the sky<br />

– From the ground<br />

• We will only handle <strong>in</strong>-scatter<strong>in</strong>g<br />

from the sun<br />

make<br />

better<br />

games


In-<strong>Scatter<strong>in</strong>g</strong><br />

• Where does a scattered photon go?<br />

– <strong>Scatter<strong>in</strong>g</strong> phase function f(è, ö)<br />

• If a photon is scattered, gives the<br />

probability it goes <strong>in</strong> direction è, ö<br />

• Most atmospheric particles are spherical<br />

or very small: f(è, ö) = f(è)<br />

make<br />

better<br />

games<br />

è


In-<strong>Scatter<strong>in</strong>g</strong><br />

• How do we use f(è) for <strong>in</strong>-scatter<strong>in</strong>g?<br />

– In-scatter probability: f(è)ω sun<br />

– In-scatter radiance : f(è)ω sun L sun =f(è)E sun<br />

Sun<br />

Eye ray<br />

w sun<br />

make<br />

better<br />

games<br />

è


In-<strong>Scatter<strong>in</strong>g</strong><br />

• In-scatter<strong>in</strong>g over a path<br />

– Radiance from a s<strong>in</strong>gle event: f(è)E sun<br />

– Over a distance dx: f(è)E sun â sc dx<br />

• Angular scatter<strong>in</strong>g coefficient<br />

( θ ) =<br />

β ( θ )<br />

β f<br />

sc<br />

– In-scatter<strong>in</strong>g over dx: E sun â sc (è) dx<br />

– Units of â sc (è) : meter -1 * steradian -1<br />

sc<br />

make<br />

better<br />

games


L<br />

In-<strong>Scatter<strong>in</strong>g</strong><br />

• Added radiance from solar <strong>in</strong>scatter<strong>in</strong>g<br />

through a constantdensity<br />

scatter<strong>in</strong>g medium:<br />

<strong>in</strong><br />

1<br />

( ) ( )( s )<br />

s θ = E β θ 1−<br />

e<br />

−β<br />

ex<br />

, sun sc<br />

βex<br />

s<br />

è<br />

make<br />

better<br />

games<br />

( , θ ) <strong>in</strong> s L


Ext<strong>in</strong>ction and In-<strong>Scatter<strong>in</strong>g</strong><br />

( s θ ) L F ( s)<br />

L ( s,<br />

θ )<br />

L = +<br />

Fex<br />

( s)<br />

, 0 ex <strong>in</strong><br />

= e<br />

−β<br />

exs<br />

( ) ( )( )<br />

L s,<br />

θ = E β θ 1−<br />

e<br />

−β<br />

exs<br />

<strong>in</strong><br />

sun sc<br />

βex<br />

L0<br />

s<br />

è<br />

make<br />

better<br />

games<br />

1<br />

L(<br />

s,<br />

θ )


Ext<strong>in</strong>ction and In-<strong>Scatter<strong>in</strong>g</strong><br />

( s θ ) L F ( s)<br />

L ( s,<br />

θ )<br />

L = +<br />

, 0 ex <strong>in</strong><br />

• Compare to hardware fog:<br />

( s)<br />

=<br />

L ( )<br />

( s ) + C ( s)<br />

L - f f<br />

0<br />

1 fog<br />

– Monochrome ext<strong>in</strong>ction<br />

– Added color completely nondirectional<br />

make<br />

better<br />

games


Rayleigh <strong>Scatter<strong>in</strong>g</strong><br />

• Small particles (r < 0.05 ë)<br />

• â sc is proportional to 1/λ 4<br />

make<br />

better<br />

games


Rayleigh <strong>Scatter<strong>in</strong>g</strong><br />

• Phase function:<br />

f<br />

R<br />

( )<br />

3 ( )<br />

θ = 1+<br />

cos<br />

2<br />

θ<br />

16π<br />

è<br />

make<br />

better<br />

games


Rayleigh <strong>Scatter<strong>in</strong>g</strong>


0.75<br />

Mie <strong>Scatter<strong>in</strong>g</strong><br />

• Larger, spherical particles<br />

• Phase function approximation:<br />

– Henyey-Greenste<strong>in</strong><br />

0.5<br />

0 -0.5<br />

f<br />

HG<br />

( θ )<br />

=<br />

-0.75<br />

make<br />

better<br />

games<br />

4π<br />

( )<br />

( ( ) ) 2 / 3<br />

2<br />

1−<br />

g<br />

2<br />

1+<br />

g − 2g<br />

cos θ


Mie <strong>Scatter<strong>in</strong>g</strong><br />

• Wavelength dependence<br />

– Complex and depends on exact size<br />

of particle<br />

– In practice, air usually conta<strong>in</strong>s a<br />

mix of various sizes of Mie particles<br />

• In the aggregate these tend to average<br />

out any wavelength dependence<br />

make<br />

better<br />

games


Mie <strong>Scatter<strong>in</strong>g</strong>


Comb<strong>in</strong>ed <strong>Scatter<strong>in</strong>g</strong><br />

• In practice, air conta<strong>in</strong>s both<br />

Rayleigh and Mie scatterers<br />

• Absorption is usually slight<br />

• We will use:<br />

ex<br />

Rayleigh<br />

sc<br />

β = β +<br />

make<br />

better<br />

games<br />

β<br />

Mie<br />

sc<br />

( θ ) =<br />

β<br />

Rayleigh<br />

f ( θ ) + β<br />

Mie<br />

f ( θ )<br />

βsc sc R<br />

sc HG


Parameters<br />

• Atmospheric parameters:<br />

β<br />

Rayleigh<br />

β<br />

Mie g<br />

sc<br />

sc HG<br />

Esun<br />

– Affected by ext<strong>in</strong>ction<br />

• Constant?<br />

• Constant:<br />

E<br />

0<br />

sun<br />

make<br />

better<br />

games


Without scatter<strong>in</strong>g<br />

Implementation<br />

How ?<br />

With scatter<strong>in</strong>g


Implementation<br />

• Aerial Perspective<br />

– Ext<strong>in</strong>ction & Inscatter<strong>in</strong>g<br />

– Rays low <strong>in</strong> atmosphere<br />

– Constant density good approximation<br />

θ<br />

s


Implementation<br />

• Sunlight<br />

ground<br />

sun<br />

E =<br />

E<br />

0<br />

– sun is white<br />

– Density is not constant!<br />

0<br />

sun<br />

– Use a more accurate model for Fex ?<br />

E<br />

0<br />

sun<br />

E<br />

F<br />

E<br />

ground<br />

sun<br />

ex


Implementation<br />

• Sunlight:<br />

– Virtual sky dome, use simple model<br />

density<br />

s(θ)<br />

θ<br />

R(θ)<br />

distance<br />

θ R(θ)


Implementation<br />

L sky , =<br />

F<strong>in</strong><br />

– Density is not constant!<br />

• Sky color:<br />

– More accurate model too expensive<br />

• Many computations needed per frame<br />

• Sky geometry<br />

– Virtual sky dome<br />

( θ ϕ ) ( θ , ϕ )


Implementation<br />

• Compute:<br />

– Can be done with textures<br />

• 1D texture for<br />

ex<br />

– Texture coord<strong>in</strong>ate is a function of s<br />

• 2D texture for<br />

– Texture coords are functions of s, θ<br />

• Comb<strong>in</strong>e <strong>in</strong> pixel shader<br />

( s θ ) L F ( s)<br />

L ( s,<br />

θ )<br />

L = +<br />

, 0 ex <strong>in</strong><br />

F<br />

L<br />

<strong>in</strong><br />

– We decided on a different approach<br />

make<br />

better<br />

games


Implementation<br />

• Compute:<br />

– Use vertex shader to compute<br />

– Apply as vertex <strong>in</strong>terpolated colors<br />

• In pixel shader, or even fixed pipel<strong>in</strong>e<br />

– Pros:<br />

• Doesn’t use valuable texture slots<br />

• Can change atmosphere properties<br />

– Cons:<br />

( s θ ) L F ( s)<br />

L ( s,<br />

θ )<br />

L =<br />

+<br />

, 0 ex <strong>in</strong><br />

• Somewhat dependent on tessellation<br />

make<br />

better<br />

games<br />

F L<br />

ex ,<br />

<strong>in</strong>


Vertex Shader<br />

Constants:<br />

Transform Matrix<br />

Sun Direction<br />

Eye Position<br />

â<br />

â<br />

R<br />

M<br />

gHG<br />

Position<br />

Esun Outputs:<br />

Vertex<br />

Shader<br />

make<br />

better<br />

games<br />

oD0 =<br />

Fext<br />

oD1= L<strong>in</strong>


Vertex Shader<br />

L<br />

<strong>in</strong><br />

( s θ ) L F ( s)<br />

L ( s,<br />

θ )<br />

L = +<br />

( )<br />

, 0 ex <strong>in</strong><br />

Fex<br />

( ) (<br />

s = e<br />

− β R + βM<br />

)s<br />

( θ ) + β ( θ ) −(<br />

β + β )<br />

βR<br />

M<br />

s,<br />

θ =<br />

Esun<br />

βR<br />

+ βM<br />

3<br />

( ) ( 2<br />

β θ β θ )<br />

R = R 1+<br />

cos<br />

16π<br />

( ) 2<br />

1<br />

1−<br />

g<br />

β ( ) M θ =<br />

β M<br />

4π<br />

2<br />

1+<br />

g − 2g<br />

cos<br />

make<br />

better<br />

games<br />

( s<br />

e )<br />

R M 1−<br />

( ( ) ) 2 / 3<br />

θ


Vertex Shader<br />

• Current Implementation:<br />

– 33 Instructions<br />

• Not <strong>in</strong>clud<strong>in</strong>g macro expansion<br />

• Could probably be optimized<br />

– 8 registers<br />

make<br />

better<br />

games


Pixel Shader<br />

Lo<br />

F_ex<br />

X<br />

=<br />

L = Lo * F_ex + L_<strong>in</strong><br />

Lo * F_ex


Pixel Shader<br />

Lo * F_ex<br />

L_<strong>in</strong><br />

+ =<br />

L = Lo * F_ex + L_<strong>in</strong><br />

Lo * F_ex + L_<strong>in</strong>


Results


Rayleigh <strong>Scatter<strong>in</strong>g</strong> - high<br />

Mie <strong>Scatter<strong>in</strong>g</strong> - low<br />

Sun Altitude - high


Rayleigh <strong>Scatter<strong>in</strong>g</strong> - low<br />

Mie <strong>Scatter<strong>in</strong>g</strong> - high<br />

Sun Altitude - high


Rayleigh <strong>Scatter<strong>in</strong>g</strong> - medium<br />

Mie <strong>Scatter<strong>in</strong>g</strong> - medium<br />

Sun Altitude - low


Planet Mars like scatter<strong>in</strong>g


Demo


Conclusion<br />

• <strong>Scatter<strong>in</strong>g</strong> is easy to implement.<br />

• Easy to add to an exist<strong>in</strong>g<br />

render<strong>in</strong>g framework<br />

– compute F_ex & L_<strong>in</strong><br />

– apply these to exist<strong>in</strong>g color to get<br />

f<strong>in</strong>al color<br />

make<br />

better<br />

games


Future Work<br />

• In-scatter<strong>in</strong>g from sky<br />

• Clouds (scatter<strong>in</strong>g and ext<strong>in</strong>ction)<br />

• Volumetric cloud shadows<br />

• Non-uniform density distributions<br />

• Full-spectrum math?<br />

make<br />

better<br />

games


Acknowledgements<br />

• We would like to thank<br />

– Kenny Mitchell for the terra<strong>in</strong><br />

eng<strong>in</strong>e used <strong>in</strong> our demo<br />

– Solomon Sr<strong>in</strong>ivasan for help with<br />

the demo movie<br />

make<br />

better<br />

games


References<br />

[Bl<strong>in</strong>n1982] J. F. Bl<strong>in</strong>n. <strong>Light</strong> Reflection Functions for Simulation of Clouds and<br />

Dusty Surfaces.<br />

[Dutré2001] P. Dutré. Global Illum<strong>in</strong>ation Compendium.<br />

[Henyey1941] L. G. Henyey and J. L. Greenste<strong>in</strong>. Diffuse Reflection <strong>in</strong> the<br />

Galaxy.<br />

[Hoffman2001] N. Hoffman and K. J. Mitchell. Photorealistic Terra<strong>in</strong> <strong>Light</strong><strong>in</strong>g <strong>in</strong><br />

<strong>Real</strong> <strong>Time</strong>.<br />

[Klassen1987] R. V. Klassen. Model<strong>in</strong>g the Effect of the Atmosphere on <strong>Light</strong>.<br />

[Mie1908] G. Mie. Bietage zur Optik truber Medien Speziell Kolloidaler<br />

Metallosungen.<br />

[Preetham1999] A. J. Preetham, P. Shirley, B. E. Smits. A Practical Analytic<br />

Model for Daylight.<br />

[Rayleigh1871] J. W. Strutt (Lord Rayleigh). On the light from the sky, its<br />

polarization and colour.<br />

[Yee2002] H. Yee, P. Dutré, S. Pattanaik. Fundamentals of <strong>Light</strong><strong>in</strong>g and<br />

Perception: The <strong>Render<strong>in</strong>g</strong> of Physically Accurate Images.<br />

make<br />

better<br />

games


THANK YOU<br />

make<br />

better<br />

games

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!