Fast, Flexible, Physically-Based Volumetric Light Scattering

71
Nathan Hoobler, NVIDIA Developer Technology March 16 th , 2016 Fast, Flexible, Physically-Based Volumetric Light Scattering

Transcript of Fast, Flexible, Physically-Based Volumetric Light Scattering

Page 1: Fast, Flexible, Physically-Based Volumetric Light Scattering

Nathan Hoobler, NVIDIA Developer Technology

March 16th, 2016

Fast, Flexible, Physically-Based Volumetric Light Scattering

Page 2: Fast, Flexible, Physically-Based Volumetric Light Scattering

2gameworks.nvidia.com

Page 3: Fast, Flexible, Physically-Based Volumetric Light Scattering

3gameworks.nvidia.com

Page 4: Fast, Flexible, Physically-Based Volumetric Light Scattering

4gameworks.nvidia.com

Page 5: Fast, Flexible, Physically-Based Volumetric Light Scattering

5gameworks.nvidia.comgameworks.nvidia.com

Polygonal Volumetric Lighting

Fast: Scalable performance on all hardware

Flexible: Minimally invasive to integrate into existing engines

Physically-based: Easy mapping to real-world phenomenon

Source will be available on GitHub to registered developers

Fast, Flexible, and Physically-based

Page 6: Fast, Flexible, Physically-Based Volumetric Light Scattering

6gameworks.nvidia.com

AGENDA

Background & Motivation

Algorithm Overview

Integration into Fallout 4

Page 7: Fast, Flexible, Physically-Based Volumetric Light Scattering

7gameworks.nvidia.com

Background & Motivation

Page 8: Fast, Flexible, Physically-Based Volumetric Light Scattering

8gameworks.nvidia.comgameworks.nvidia.com

Light Propagation in a Vacuum

x

l

Page 9: Fast, Flexible, Physically-Based Volumetric Light Scattering

9gameworks.nvidia.comgameworks.nvidia.com

Light Propagation in a VacuumDirectly Visible Light-Source

Direct Radiance:𝐿𝐷 = 𝐿(𝜔𝑥)

x

l

Page 10: Fast, Flexible, Physically-Based Volumetric Light Scattering

10gameworks.nvidia.comgameworks.nvidia.com

Light Propagation in a VacuumDirect Illumination

Direct Radiance:𝐿𝐷 = 𝐿(𝜔𝑠)𝜌𝑠(𝑙, 𝑠, 𝜔𝑥)

sx

l

Page 11: Fast, Flexible, Physically-Based Volumetric Light Scattering

11gameworks.nvidia.comgameworks.nvidia.com

Light Propagation in a VacuumShadows

Direct Radiance:𝐿𝐷 = 𝐿 𝜔𝑠 𝜌𝑠 𝑙, 𝑠, 𝜔𝑥 𝑉 𝑠, 𝑙

x

l

s

Page 12: Fast, Flexible, Physically-Based Volumetric Light Scattering

12gameworks.nvidia.comgameworks.nvidia.com

Transmitted Light

Participating MediaTransmittance & Extinction

Incident Light

Page 13: Fast, Flexible, Physically-Based Volumetric Light Scattering

13gameworks.nvidia.comgameworks.nvidia.com

Participating MediaTransmittance & Extinction

Incident Light Transmitted LightAbsorption

Out-Scattering

Page 14: Fast, Flexible, Physically-Based Volumetric Light Scattering

14gameworks.nvidia.comgameworks.nvidia.com

Participating MediaTransmittance & Extinction

sx

l Direct Radiance:𝐿𝐷 = 𝐿 𝜔𝑠 𝜌𝑠 𝑙, 𝑠, 𝜔𝑥 𝑉 𝑠, 𝑙

Transmitted Radiance:𝐿𝑇 = 𝐿𝐷𝑇 𝑙, 𝑠 𝑇 𝑠, 𝑥

Page 15: Fast, Flexible, Physically-Based Volumetric Light Scattering

15gameworks.nvidia.comgameworks.nvidia.com

Participating Media

Transmittance:

𝑇 = 1 −𝜙𝑠

𝜙𝑖∗

𝜙𝑎

𝜙𝑖= 1 −

𝜙𝑒𝑥

𝜙𝑖

𝑇 𝑎, 𝑏 = 𝑒−𝜏| 𝑏−𝑎 |

Optical Thickness:

𝜏𝑥 = −ln(1 −𝜙𝑥

𝜙𝑖)

𝜏𝑒𝑥 = 𝜏𝑠 + 𝜏𝑎

Beer-Lambert Law

Transmittance vs Distance

0.5

1.0

2.0

Page 16: Fast, Flexible, Physically-Based Volumetric Light Scattering

16gameworks.nvidia.comgameworks.nvidia.com

Participating MediaTransmittance & Extinction

sx

l Direct Radiance:𝐿𝐷 = 𝐿 𝜔𝑠 𝜌𝑠 𝑙, 𝑠, 𝜔𝑥 𝑉 𝑠, 𝑙

Transmitted Radiance:

𝐿𝑇 = 𝐿𝐷𝑒−𝜏𝑒𝑥(𝑙𝑠+𝑠𝑥)

Page 17: Fast, Flexible, Physically-Based Volumetric Light Scattering

17gameworks.nvidia.comgameworks.nvidia.com

Participating MediaIn-Scattering

Incident Light Transmitted LightAbsorption

Out-Scattering

Page 18: Fast, Flexible, Physically-Based Volumetric Light Scattering

18gameworks.nvidia.comgameworks.nvidia.com

Participating MediaIn-Scattering

Incident Light Transmitted LightAbsorption

In-Scattering

In-Scattering

Out-Scattering

Page 19: Fast, Flexible, Physically-Based Volumetric Light Scattering

19gameworks.nvidia.comgameworks.nvidia.com

Participating MediaIn-Scattering

sx

l Direct Radiance:𝐿𝐷 = 𝐿 𝜔𝑠 𝜌𝑠 𝑙, 𝑠, 𝜔𝑥 𝑉 𝑠, 𝑙

Transmitted Radiance:

𝐿𝑇 = 𝐿𝐷𝑒−𝜏𝑒𝑥(𝑙𝑠+𝑠𝑥)

In-Scattered Radiance:

𝐿𝑆 = 0

𝑠𝑥

𝐿 𝑡, 𝑙 𝑉(𝑡, 𝑙)𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)𝑑𝑡

t1 t2 t3

Page 20: Fast, Flexible, Physically-Based Volumetric Light Scattering

20gameworks.nvidia.comgameworks.nvidia.com

Phase Functions

Volume analog of BRDF

Directional distribution of energy relative to incident direction

Determined by the ratio of medium particles and their size relative to the light

Overview

Phase function for atmosphere on a clear day

Page 21: Fast, Flexible, Physically-Based Volumetric Light Scattering

21gameworks.nvidia.com

Phase Functions

Can be Wavelength-dependent

Can become arbitrarily complex depending on atmospheric conditions

We can approximate common conditions with simple models

Complex Phenomenon

Page 22: Fast, Flexible, Physically-Based Volumetric Light Scattering

22gameworks.nvidia.com

Algorithm Overview

Page 23: Fast, Flexible, Physically-Based Volumetric Light Scattering

23gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationOverview

sx

l In-Scattered Radiance:

𝐿𝑆 = 0

𝑠𝑥

𝐿 𝑡, 𝑙 𝑉(𝑡, 𝑙)𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)𝑑𝑡

Page 24: Fast, Flexible, Physically-Based Volumetric Light Scattering

24gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationNon-Constant Visibility

sx

l In-Scattered Radiance:

𝐿𝑆 = 0

𝑠𝑥

𝐿 𝑡, 𝑙 𝑉(𝑡, 𝑙)𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)𝑑𝑡

Page 25: Fast, Flexible, Physically-Based Volumetric Light Scattering

25gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationSum of Intervals

sx

l In-Scattered Radiance:

𝐿𝑆′′(𝑡) = 𝐿 𝑡, 𝑙 𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)

𝐿𝑆 = 𝑥

𝑡1

𝐿𝑆′′ 𝑡 𝑑𝑡 +

𝑡2

𝑠

𝐿𝑆′′ 𝑡 𝑑𝑡

t1 t2

Page 26: Fast, Flexible, Physically-Based Volumetric Light Scattering

26gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationSum & Difference of Intervals

l In-Scattered Radiance:

𝐿𝑆′′(𝑡) = 𝐿 𝑡, 𝑙 𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)

𝐿𝑆′(𝑑) = 0

𝑑

𝐿𝑆′′ 𝑡 𝑑𝑡

𝐿𝑆 = 𝐿𝑆′ 𝑡1 − 𝐿𝑆′ 𝑡2 + 𝐿𝑆′ 𝑠

Page 27: Fast, Flexible, Physically-Based Volumetric Light Scattering

27gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationSum & Difference of Intervals

l In-Scattered Radiance:

𝐿𝑆′′(𝑡) = 𝐿 𝑡, 𝑙 𝜌𝑚 𝑡𝑙, 𝜔𝑥 𝑒−𝜏𝑒𝑥(𝑙𝑡+𝑡𝑥)

𝐿𝑆′(𝑑) = 0

𝑑

𝐿𝑆′′ 𝑡 𝑑𝑡

𝐿𝑆 = 𝐿𝑆′ 𝑡1 − 𝐿𝑆′ 𝑡2 + 𝐿𝑆′ 𝑠

𝐿𝑆 =

𝑛∈𝐺𝑓

𝐿𝑆′ 𝑡𝑛 −

𝑚∈𝐺𝑏

𝐿𝑆′ 𝑡𝑚

Page 28: Fast, Flexible, Physically-Based Volumetric Light Scattering

28gameworks.nvidia.comgameworks.nvidia.com

Interval IntegrationIntervals from Mesh

l In-Scattered Radiance:

𝐿𝑆 =

𝑛∈𝐺𝑓

𝐿𝑆′ 𝑡𝑛 −

𝑚∈𝐺𝑏

𝐿𝑆′ 𝑡𝑚

Use front and back faces of light volume as integration intervals

Page 29: Fast, Flexible, Physically-Based Volumetric Light Scattering

29gameworks.nvidia.com No Scattering

Page 30: Fast, Flexible, Physically-Based Volumetric Light Scattering

30gameworks.nvidia.com Light Volume

Page 31: Fast, Flexible, Physically-Based Volumetric Light Scattering

31gameworks.nvidia.com Scattering Only

Page 32: Fast, Flexible, Physically-Based Volumetric Light Scattering

32gameworks.nvidia.com Composited Image

Page 33: Fast, Flexible, Physically-Based Volumetric Light Scattering

33gameworks.nvidia.com

Page 34: Fast, Flexible, Physically-Based Volumetric Light Scattering

34gameworks.nvidia.comgameworks.nvidia.com

WorkflowHigh-Level API

Begin Accumulation

Scene Depth

Medium Definition

Render Volume

Light Shadow

Map

Filter and Composite

Scene Depth

Scene Render

Page 35: Fast, Flexible, Physically-Based Volumetric Light Scattering

35gameworks.nvidia.comgameworks.nvidia.com

Workflow

G-Buffer Render

Render Shadow Map

Apply LightAlpha-Blend

RenderPost-Process

Generic Pipeline Example

Begin Accumulation

Render VolumeFilter and Composite

Page 36: Fast, Flexible, Physically-Based Volumetric Light Scattering

36gameworks.nvidia.comgameworks.nvidia.com

Medium Specification

Multiple Phase Terms

Density - Optical depth of that term in <RGB>

Phase Function - Directional scattering distribution (applied per-channel)

Phase Parameters - Eccentricity (for Henyey-Greenstein)

Absorption - Optical depth of light absorption <RGB>

Terms are summed together per-channel to produce composite medium

Page 37: Fast, Flexible, Physically-Based Volumetric Light Scattering

37gameworks.nvidia.comgameworks.nvidia.com

Medium Specification

Particles much smaller than wavelength of light (O2, N2, etc.)

Generally constant at a given altitude

Wavelength dependent

Relative optical depth for CIE-RGB:

R: 0.596x10-5

G: 1.324x10-5

B: 3.310x10-5

Rayleigh Scattering

𝜌 𝜃 =3

16𝜋1 + 𝑐𝑜𝑠2(𝜃)

Page 38: Fast, Flexible, Physically-Based Volumetric Light Scattering

38gameworks.nvidia.comgameworks.nvidia.com

Medium Specification

Mie-Hazy: Light fog

𝜌 𝜃 =1

4𝜋

1

2+

9

2

1 + 𝑐𝑜𝑠 𝜃

2

8

Mie-Lorenz Approximation

Mie-Murky: Dense fog

𝜌 𝜃 =1

4𝜋

1

2+

33

2

1 + 𝑐𝑜𝑠 𝜃

2

32

Page 39: Fast, Flexible, Physically-Based Volumetric Light Scattering

39gameworks.nvidia.comgameworks.nvidia.com

Medium Specification

Tunable phase function with a specified eccentricity g=(-1, 1)

g < 0: back-scattering

g = 0: isotropic scattering

g > 0: forward scattering

Multiple terms can be combined to approximate complex functions

Henyey-Greenstein Function

Page 40: Fast, Flexible, Physically-Based Volumetric Light Scattering

40gameworks.nvidia.comgameworks.nvidia.com

Volume Rendering

Convert light description + shadow map into geometry

Solve Integral at each intersection and add or subtract based on facing

Different solvers based on light type

Directional Light - Analytical Solution

Omnidirectional Light - Look-up Texture

Spot Light – Look-up Texture or Numerical Integration

Overview

Page 41: Fast, Flexible, Physically-Based Volumetric Light Scattering

41gameworks.nvidia.comgameworks.nvidia.com

Volume Rendering

𝐿𝑆′ 𝑑 = 𝐿 𝑑, 𝑙 𝜌𝑚(𝑥𝑙, 𝜔𝑥)1 − 𝑒−𝜏𝑒𝑥𝑑

𝜏𝑒𝑥

With some assumptions we can simplify the integral for directional light

- Constant Direction (parallel light-source)

- Constant Power (Light distance >> medium depth)

Reduces to analytic function evaluated in pixel-shader

Directional Light

Page 42: Fast, Flexible, Physically-Based Volumetric Light Scattering

42gameworks.nvidia.comgameworks.nvidia.com

Volume Rendering

Local lights too complex for analytical solutions

All terms can be expressed in with respect to direction and distance

Create a Look-up texture:

- Map to 2D space

- evaluate differential

- Numerically integrate with CS

Omnidirectional Light

cos−1( 𝑣 ⋅ 𝑙)

𝑑

Page 43: Fast, Flexible, Physically-Based Volumetric Light Scattering

43gameworks.nvidia.comgameworks.nvidia.com

Volume Rendering

Spotlights are worse case than omnidirectional lights

Angular falloff complicates integral

Interval needs to be clamped to cone intersection

Can be simplified

• No Falloff

• Fixed Falloff

• Variable Falloff

Spot Lights

Page 44: Fast, Flexible, Physically-Based Volumetric Light Scattering

44gameworks.nvidia.comgameworks.nvidia.com

Volume Rendering

No Falloff: Treat as point light

Fixed Falloff: Use modified point LUT

For other cases, integrate in the PS

1) Do cone intersection as before

2) Numerically integrate (Newton-Cotes)

3) Use the result as the integral

Numerical Integration

Page 45: Fast, Flexible, Physically-Based Volumetric Light Scattering

45gameworks.nvidia.comgameworks.nvidia.com

Apply Lighting

Use MSAA when down-sampling

• Preserves shading rate savings

• Improves edge quality

Resolve MSAA accumulation buffer before compositing

If temporal sampling, feed resolved accumulation through TAA system

MSAA/Temporal Resolve

Page 46: Fast, Flexible, Physically-Based Volumetric Light Scattering

46gameworks.nvidia.comgameworks.nvidia.com

Apply Lighting

Bilateral upsampling: helpful at ¼-resolution, situational at ½-resolution

Additively blend resolved/filtered output with scene

Use dual-source blending to attenuate based on medium+depth

Composite Results

Page 47: Fast, Flexible, Physically-Based Volumetric Light Scattering

47gameworks.nvidia.com

Integration into Fallout 4

Page 48: Fast, Flexible, Physically-Based Volumetric Light Scattering

48gameworks.nvidia.com

Fallout 4 Integration

Feb: Development/Integration Begins

March: Artists authoring environments

April-June: Console Ports

July-August: Optimization (PC+Console)

Dedicated NVIDIA QA resources

Page 49: Fast, Flexible, Physically-Based Volumetric Light Scattering

49gameworks.nvidia.com

Indoor, Dusty(Final Image)

Page 50: Fast, Flexible, Physically-Based Volumetric Light Scattering

50gameworks.nvidia.com

Indoor, Dusty(In-Scattering Only)

Page 51: Fast, Flexible, Physically-Based Volumetric Light Scattering

51gameworks.nvidia.com

Outdoors, Clear(No Scattering)

Page 52: Fast, Flexible, Physically-Based Volumetric Light Scattering

52gameworks.nvidia.com

Outdoors, Clear(In-Scattering Only)

Page 53: Fast, Flexible, Physically-Based Volumetric Light Scattering

53gameworks.nvidia.com

Outdoors, Clear(Final Image)

Page 54: Fast, Flexible, Physically-Based Volumetric Light Scattering

54gameworks.nvidia.com

Outdoors, Foggy(No Scattering)

Page 55: Fast, Flexible, Physically-Based Volumetric Light Scattering

55gameworks.nvidia.com

Outdoors, Foggy(In-Scattering Only)

Page 56: Fast, Flexible, Physically-Based Volumetric Light Scattering

56gameworks.nvidia.com

Outdoors, Foggy(Final Image)

Page 57: Fast, Flexible, Physically-Based Volumetric Light Scattering

57gameworks.nvidia.com

Outdoors, Dusty(No Scattering)

Page 58: Fast, Flexible, Physically-Based Volumetric Light Scattering

58gameworks.nvidia.com

Outdoors, Dusty(In-Scattering Only)

Page 59: Fast, Flexible, Physically-Based Volumetric Light Scattering

59gameworks.nvidia.com

Outdoors, Dusty(Final Image)

Page 60: Fast, Flexible, Physically-Based Volumetric Light Scattering

60gameworks.nvidia.comgameworks.nvidia.com

Gpu PerformanceConcord, High Quality @ 1080p

BEGIN RENDER VOLUMEFILTER &

COMPOSITETOTAL

GTX 980 Ti 0.037 ms 0.908 ms 0.264 ms 1.209 ms

GTX 970 0.049 ms 1.364 ms 0.389 ms 1.802 ms

Radeon Fury X 0.038 ms 2.581 ms 0.305 ms 2.924 ms

Page 61: Fast, Flexible, Physically-Based Volumetric Light Scattering

61gameworks.nvidia.comgameworks.nvidia.com

Gpu PerformanceConcord, Medium Quality @ 1080p

BEGIN RENDER VOLUMEFILTER &

COMPOSITETOTAL

GTX 980 Ti 0.035 ms 0.415 ms 0.394 ms 0.844 ms

GTX 970 0.049 ms 0.610 ms 0.565 ms 1.224 ms

Radeon Fury X 0.041 ms 1.074 ms 0.636 ms 1.751 ms

Page 62: Fast, Flexible, Physically-Based Volumetric Light Scattering

62gameworks.nvidia.com

INTEGRATIONTIPS

• Maximize Dynamic Range

• Make sure shadow maps are consistent

• Temporal filter low-res effects separately

• Be aware of worst-case scenes

Page 63: Fast, Flexible, Physically-Based Volumetric Light Scattering

63gameworks.nvidia.comgameworks.nvidia.com

Implementation Issues

Problem: Hard to get intense effects without washing out scene

Intensity proportional to light source power

Real-world effects involve 10,000:1 contrast between source and scene!

Baked-in ambient normalizes intensity between bright and dark areas

Simply increasing medium density causes wash-out

Solution: Need HDR with real adaptation between dark and bright

Reduced Dynamic Range Limits Contrast

Page 64: Fast, Flexible, Physically-Based Volumetric Light Scattering

64gameworks.nvidia.comgameworks.nvidia.com

Implementation IssuesShadow Map/Scene Inconsistencies

Problem: Shadow Map inconsistencies become much more noticeable

Page 65: Fast, Flexible, Physically-Based Volumetric Light Scattering

65gameworks.nvidia.comgameworks.nvidia.com

Implementation Issues

Problem: Shadow Map inconsistencies become much more noticeable

“Bug” in art, but not noticeable because surface and shadows not usually visible

May only render front-faces to shadow map, but there may not have consistent geometry/alpha masks on both sides

May not render “distant” occluders to the shadow map

May use a separate, high-detail map for certain occluders

Solution: be consistent with your shadow map contents!

Shadow Map/Scene Inconsistencies

Page 66: Fast, Flexible, Physically-Based Volumetric Light Scattering

66gameworks.nvidia.comgameworks.nvidia.com

Implementation Issues

Problem: Temporal AA jitter causes flickering

Temporal AA jitters to increase effective resolution, then filters to smooth

Library runs at ½ - ¼ resolution to improve performance

A 1 px flicker at full-res could become 4x4 px in the down-sampled buffer!

Full-res temporal filter not designed to smooth artifacts that large

Solution: Added separate TAA resolve to down-sampled buffers

Temporal Jittering Causes Flicker

Page 67: Fast, Flexible, Physically-Based Volumetric Light Scattering

67gameworks.nvidia.com

Implementation Issues

Problem: Poor perf in specific views

Cost proportional to total pixel coverage

Dense occluders are no problem but create overhead at low angles

Ex: Sunset through the woods

Solution: Adjust tessellation factor based on view angle

Solution: Pre-filter shadow map

Perf Drop with High Frequency Occluders

Page 68: Fast, Flexible, Physically-Based Volumetric Light Scattering

68gameworks.nvidia.com

SUMMARY

Gameworks Volumetric Lighting is…

- Fast enough for entire spec range

- Flexible enough for almost any engine

- Compatible with physically-based engines

- Currently available in DirectX 11 (with ports being added according to demand)

http://developer.nvidia.com

Page 69: Fast, Flexible, Physically-Based Volumetric Light Scattering

69gameworks.nvidia.com

Questions?

Page 70: Fast, Flexible, Physically-Based Volumetric Light Scattering

70gameworks.nvidia.com

RELATED READING

Hoffman, N., and A. J. Preetham. 2002. Rendering Outdoor Scattering in Real Time. http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/ATI-LightScattering.pdf

Sun, B., et. al. 2005. A Practical Analytic Single Scattering Model for Real Time Rendering. http://www.cs.columbia.edu/~bosun/sig05.htm

Bouthors, A., Neyret, F., Lefebvre, S. Real-time realistic illumination and shading of stratiform clouds. http://www-evasion.imag.fr/Publications/2006/BNL06/bnl06-elec.pdf

Englehardt, T., Dachsbacher, C. 2010. Epipolar Sampling for Shadows and Crepuscular Rays in Participating Media with Single Scattering. http://gpucomputing.net/sites/default/files/papers/5398/espmss10.pdf

Wronski, B. 2014. Volumetric Fog: Unified, Compute Shader Based Solution to Atmospheric Scattering. http://bartwronski.com/publications/

Hillaire, S. 2015. Physically-based & Unified Volumetric Rendering in Frostbite. http://www.frostbite.com/2015/08/physically-based-unified-volumetric-rendering-in-frostbite/

Page 71: Fast, Flexible, Physically-Based Volumetric Light Scattering