How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... ·...

20
How to Render a Real Rainbow How to Render a Real Rainbow Clint Brewer NVIDIA Developer Technology Group

Transcript of How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... ·...

Page 1: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

How to Render a Real RainbowHow to Render a Real RainbowClint Brewer

NVIDIA Developer Technology Group

Page 2: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Overview

DemoWhat causes a rainbowDifferent ways to render the rainbowHow to combine it with the rest of the sceneDemoQuestions

Page 3: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Demo

Page 4: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

What Causes a Rainbow

Scattering of sunlight

Refraction and reflection by spherical water drops

Page 5: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

What Causes a Rainbow

Color of a rainbow at your eye depends on

Angle of deviation (a)

Between view (V) and Sun light (L)

Radius of water droplet (r)

r

a

V

L

Page 6: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

How Can We Render This?

Pre-rendered skybox

Screen-aligned quad + pixel shaderSky dome + texture slices

Page 7: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Pre-Rendered Rainbow Skybox

Just bake the rainbow into your skyboxThe good

Very cheap!The not so good

StaticRequires extra texture storage

Page 8: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

How About a Screen-Aligned Quad

Screen-aligned quad + pixel shaderThe good

Complete control over pixel colorDynamic time of dayNo extra texture storage

The not so goodAdded computation at every pixel

Page 9: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Color on the Quad

Lee DiagramAngle of deviationDroplet radius

MiePlot ( Philip Laven )Can generate Lee Diagramslets you change the scattering model

Mie, Airy, Descartes

r

a

Page 10: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

How to Use the Lee Diagram

Math

Calculate a at each pixel on the screen in a pixel shaderThen actually compute the color with scattering math (Mie, Airy, etc)

Or use a dependent texture read

r

a

a = 1 - Light • View

color = tex2D(r, a)

Page 11: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

An Optimization

Sun aligned sky domeMap 1d slices of a Lee DiagramThe good

Cheap on the pixelsSupports changing sun position No extra texture storage

The not so goodAdded vertex processing

(Not that big a problem really)

Page 12: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

A rendered rainbow is ...

Only as nice as your scene

Things that can helpFogAtmospheric scatteringRainClouds Skybox

Page 13: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Moisture Texture

Render moisture amount to a texture:

FogRainClouds Etc.

Page 14: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

More moisture means more rainbow

*

Page 15: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Combining it with the Scene

Add to scene

+

Page 16: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Demo

Page 17: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

Questions?

[email protected]://developer.nvidia.com

slides are going online daily...http://developer.nvidia.com/object/gdc_2004_presentations.html

Page 18: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

References

MiePlot, http://www.philiplaven.com/Atmospheric Optics, http://www.sundog.clara.co.uk/resource/intro.htmLee, Raymond L, “Mie Theory Airy Theory and the Natural Rainbow”, Applied Optics, Vol. 37, No. 9, 1998

Page 19: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

developer.nvidia.comdeveloper.nvidia.comThe Source for GPU Programming

Latest documentationSDKsCutting-edge tools

Performance analysis toolsContent creation tools

Hundreds of effectsVideo presentations and tutorialsLibraries and utilitiesNews and newsletter archives

EverQuest® content courtesy Sony Online Entertainment Inc.

Page 20: How to Render a Real Rainbow - Nvidiadownload.nvidia.com/developer/presentations/GDC_2004/gdc... · 2017-04-28 · GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time

GPU Gems: Programming Techniques, GPU Gems: Programming Techniques, Tips, and Tricks for RealTips, and Tricks for Real--Time GraphicsTime Graphics

Practical real-time graphics techniques from experts at leading corporations and universities

Great value:Contributions from industry expertsFull color (300+ diagrams and screenshots)Hard cover816 pagesAvailable at GDC 2004

“GPU Gems is a cool toolbox of advanced graphics techniques. Novice programmers and graphics gurus alike will find the gems practical, intriguing, and useful.”Tim SweeneyLead programmer of Unreal at Epic Games

“This collection of articles is particularly impressive for its depth and breadth. The book includes product-oriented case studies, previously unpublished state-of-the-art research, comprehensive tutorials, and extensive code samples and demos throughout.”Eric HainesAuthor of Real-Time Rendering

For more, visit:For more, visit:http://http://developer.nvidia.com/GPUGemsdeveloper.nvidia.com/GPUGems