Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios...

65
make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty @ westwood .com Arcot J Preetham ATI Research preetham @ ati .com

Transcript of Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios...

Page 2: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Outline– Basics

• Atmospheric Light Scattering• Radiometric Quantities• From Radiance to Pixels

– Scattering Theory• Absorption, Out-Scattering, In-Scattering• Rayleigh and Mie Scattering

– Implementation• Aerial Perspective, Sunlight, Skylight• Vertex Shader

– Future Work

Page 3: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

• Is caused by a variety of particles– Molecules, dust, water vapor, etc.

• These can cause light to be:– Scattered into the line of sight (in-

scattering)

– Scattered out of the line of sight (out-scattering)

– Absorbed altogether (absorption)

Atmospheric Light Scattering

Page 4: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Illuminates the sky

Atmospheric Light Scattering

Page 5: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Attenuates and colors the Sun

Atmospheric Light Scattering

Page 6: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Attenuates and colors distant objects

Atmospheric Light Scattering

Page 7: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Atmospheric Light Scattering• Varies by

– Time of Day– Weather– Pollution

Page 8: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Atmospheric Light Scattering• Varies by

– Time of Day– Weather– Pollution

Page 9: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Atmospheric Light Scattering• Varies by

– Time of Day– Weather– Pollution

Page 10: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Atmospheric Light Scattering• Varies by

– Time of Day– Weather– Pollution

Page 11: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Varies between planets

Atmospheric Light Scattering

Page 12: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

• Extinction (Absorption, Out-scattering)– Phenomena which remove light– Multiplicative:

• In-scattering:– Phenomenon which adds light– Additive:

• Combined:

Atmospheric Light Scattering

0exextinction LFL

inL

in0exscattering LLFL

Page 13: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.
Page 14: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Radiometric Quantities• Radiant Flux• Radiance• Irradiance

Page 15: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Radiometric Quantities• Radiant Flux

– Quantity of light through a surface

– Radiant power (energy / time)– Watt

Page 16: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Radiometric Quantities

• Radiance L– Quantity of light in a single ray– Radiant flux / area / solid angle– Watt / (meter2 * steradian)

Page 17: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Radiometric Quantities

• Irradiance E– Quantity of light incident to a surface

point– Incident radiant flux / area (Watt /

meter2)– Radiance integrated over hemisphere

Page 18: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

From Radiance to Pixels• Compute radiance incident to

eye through each screen pixel

Page 19: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

From Radiance to Pixels• Pixel value based on radiance• But radiance is distributed

continuously along the spectrum– We need three numbers: R, G, B

Page 20: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

From Radiance to Pixels• SPD (Spectral Power Distribution) to

RGB– Fast approach:

•Do all math at R, G, B sample wavelengths

– Correct approach:•Use SPDs, convert final radiance to

RGB

400nm 500nm 600nm 700nm

S

M L

Page 21: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Absorption• Absorption cross section

– Absorbed radiant flux per unit incident irradiance

– Units of area (meter2)

ab

E

ab

Page 22: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Absorption• Absorption cross section

abEab

Eab

ab

Page 23: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Absorption• Absorption coefficient

– Particle density times absorption cross section

– Units of inverse length (meter-1)

abab

ab

Page 24: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Absorption• Total absorption cross

section:

• Probability of absorption:

A

ds

dsA A ababab

ababababab AAP ds

Page 25: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Absorption• Attenuation of radiance from

travel through a constant-density absorptive medium:

seLsL ab0

L0 L(s)s

Page 26: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Out-Scattering• Exactly as in the absorption

case– Scattering cross section– Scattering coefficient– Attenuation due to out-

scattering in a constant-density medium: seLsL sc

0

scscscsc

sc

Page 27: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Extinction• Both absorption and out-

scattering attenuate light• They can be combined as

extinction• Extinction coefficient• Total attenuation from

extinction seLsL ex0

sesF exex

scabex

Page 28: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

In-Scattering• Light is scattered into a view

ray from all directions– From the sun– From the sky– From the ground

• We will only handle in-scattering from the sun

Page 29: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

In-Scattering• Where does a scattered photon

go?– Scattering phase function

• If a photon is scattered, gives the probability it goes in direction

•Most atmospheric particles are spherical or very small:

,f

,

ff ,

Page 30: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

In-Scattering• How do we use for in-

scattering?– In-scatter probability:– In-scatter radiance :

Eye ray

Sun

f sunf

sunsunsun EfLf

sun

Page 31: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

In-Scattering• In-scattering over a path

– Radiance from a single event:

– Over a distance ds:• Angular scattering coefficient

– In-scattering over ds:– Units of : meter-1 * steradian-1

fscsc

sunEf dsEf scsun

dsE scsun

sc

Page 32: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

In-Scattering• Added radiance from solar in-

scattering through a constant-density scattering medium: seEsL ex1

1, scsun

exin

s ,in sL

Page 33: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Extinction and In-Scattering

,F, inex0 sLsLsL ses ex

exF seEsL ex11

, scsunex

in

s ,sL0L

Page 34: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Extinction and In-Scattering ,F, inex0 sLsLsL • Compare to hardware fog:

– Monochrome extinction– Added color completely non-

directional

sCsLsL ff-1 fog0

Page 35: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Rayleigh Scattering• Small particles

• is proportional to

05.0rsc 4

Page 36: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Rayleigh Scattering• Phase function:

2R cos1

16

3f

Page 37: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Rayleigh Scattering

Page 38: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Mie Scattering• Larger, spherical particles• Phase function

approximation: – Henyey-Greenstein

2/32

2

HGcos214

1

gg

gf

0 -0.5 -0.750.50.75

Page 39: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Mie Scattering• Wavelength dependence

– Complex and depends on exact size of particle

– In practice, air usually contains a mix of various sizes of Mie particles• In the aggregate these tend to

average out any wavelength dependence

Page 40: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Mie Scattering

Page 41: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Combined Scattering• In practice, air contains both

Rayleigh and Mie scatterers• Absorption is usually slight• We will use:

Miesc

Rayleighscex

HGMiescR

Rayleighscsc ff

Page 42: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

• Atmospheric parameters:

• Constant?– Affected by extinction

• Constant:

Parameters

MiescRayleigh

sc HGg

sunE

0sunE

Page 43: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

With scatteringWithout scattering

How ?

Implementation

Page 44: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Aerial Perspective– Extinction & Inscattering– Rays low in atmosphere– Constant density good

approximation

Implementation

s

Page 45: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Sunlight

– is white– Density is not constant!– Use a more accurate model for

Fex?

Implementation

ex0sun

groundsun FEE

0sunE

groundsunE

0sunE

Page 46: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Sunlight:– Virtual sky dome, use simple

model

Implementation

density

distance R

R s

Page 47: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

• Sky color:– Density is not constant! – More accurate model too

expensive• Many computations needed per

frame

• Sky geometry– Virtual sky dome

Implementation ,, insky FL

Page 48: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Implementation• Compute:

– Can be done with textures•1D texture for

– Texture coordinate is a function of s•2D texture for

– Texture coords are functions of s,•Combine in pixel shader

– We decided on a different approach

,F, inex0 sLsLsL

exF

inL

Page 49: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Implementation• Compute:

– Use vertex shader to compute– Apply as vertex interpolated

colors• In pixel shader, or even fixed pipeline

– Pros:•Doesn’t use valuable texture slots•Can change atmosphere properties

– Cons:•Somewhat dependent on tessellation

inex ,F L ,F, inex0 sLsLsL

Page 50: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Vertex Shader

HGg

extF oD0

Position

in oD1 L

Sun Direction

Eye Position

VertexShader

Transform Matrix

Constants:

sunE Outputs:

Page 51: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Vertex Shader

ses MRexF

seEsL MR1, sunMR

MRin

,F, inex0 sLsLsL

2RR cos1

16

3

2/32

2

MMcos21

1

4

1

gg

g

Page 52: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Vertex Shader• Current Implementation:

– 33 Instructions•Not including macro expansion•Could probably be optimized

– 8 registers

Page 53: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

X =L0

Fex

L0 * Fex

L = L0 * Fex + Lin

Pixel Shader

Page 54: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

+ =L0 * Fex

Lin

L = L0 * Fex + Lin

L = L0 * Fex + Lin

Pixel Shader

Page 55: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Results

Page 56: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Rayleigh Scattering - highMie Scattering - lowSun Altitude - high

Page 57: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Rayleigh Scattering - lowMie Scattering - highSun Altitude - high

Page 58: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Rayleigh Scattering - mediumMie Scattering - mediumSun Altitude - low

Page 59: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Planet Mars like scattering

Page 60: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

Demo

Page 61: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Conclusion

• Scattering is easy to implement.

• Easy to add to an existing rendering framework– compute Fex and Lin

– apply these to existing color to get final color

Page 62: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Future Work• In-scattering from sky• Clouds (scattering and

extinction)• Volumetric cloud shadows• Non-uniform density

distributions• Full-spectrum math?

Page 63: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

Acknowledgements• We would like to thank

– Kenny Mitchell for the terrain engine used in our demo

– Solomon Srinivasan for help with the demo movie

Page 64: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

References[Blinn1982] J. F. Blinn. Light Reflection Functions for Simulation of Clouds and

Dusty Surfaces. [Dutré2001] P. Dutré. Global Illumination Compendium. [Henyey1941] L. G. Henyey and J. L. Greenstein. Diffuse Reflection in the

Galaxy. [Hoffman2001] N. Hoffman and K. J. Mitchell. Photorealistic Terrain Lighting in

Real Time. [Klassen1987] R. V. Klassen. Modeling the Effect of the Atmosphere on Light.[Mie1908] G. Mie. Bietage zur Optik truber Medien Speziell Kolloidaler

Metallosungen.[Preetham1999] A. J. Preetham, P. Shirley, B. E. Smits. A Practical Analytic

Model for Daylight.[Rayleigh1871] J. W. Strutt (Lord Rayleigh). On the light from the sky, its

polarization and colour. [Yee2002] H. Yee, P. Dutré, S. Pattanaik. Fundamentals of Lighting and

Perception: The Rendering of Physically Accurate Images.

Page 65: Make better games Rendering Outdoor Light Scattering in Real Time Naty Hoffman Westwood Studios naty@westwood.com Arcot J Preetham ATI Research preetham@ati.com.

makebettergames

THANK YOU