Spherical Harmonics in Actual Games

Slides:



Advertisements
Similar presentations
Normal Mapping for Precomputed Radiance Transfer
Advertisements

Spherical Harmonic Lighting Jaroslav Křivánek. Overview Function approximation Function approximation Spherical harmonics Spherical harmonics Some other.
Pre-computing Lighting in Games
A Mike Day Paper Exercise
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
ADVANCED SKIN SHADING WITH FACEWORKS Nathan Reed — NVIDIA March 24, 2014.
Computer graphics & visualization Global Illumination Effects.
Week 5 - Friday.  What did we talk about last time?  Quaternions  Vertex blending  Morphing  Projections.
Environment Mapping CSE 781 – Roger Crawfis
Real-Time Rendering Self-Shadowing
Spherical Harmonic Lighting of Wavelength-dependent Phenomena Clifford Lindsay, Emmanuel Agu Worcester Polytechnic Institute (USA)
3D Graphics Rendering and Terrain Modeling
CS 551 / CS 645 Antialiasing. What is a pixel? A pixel is not… –A box –A disk –A teeny tiny little light A pixel is a point –It has no dimension –It occupies.
SE 313 – Computer Graphics Lecture 13: Lighting and Materials Practice Lecturer: Gazihan Alankuş 1.
Rendering with Environment Maps Jaroslav Křivánek, KSVI, MFF UK
Week 9 - Wednesday.  What did we talk about last time?  Fresnel reflection  Snell's Law  Microgeometry effects  Implementing BRDFs  Image based.
Computer graphics & visualization Pre-Computed Radiance Transfer PRT.
School of Computing Science Simon Fraser University
Precomputed Local Radiance Transfer for Real-time Lighting Design Anders Wang Kristensen Tomas Akenine-Moller Henrik Wann Jensen SIGGRAPH ‘05 Presented.
Master Thesis Lighting and materials for real-time game engines
Rendering (彩現 渲染).
An Efficient Representation for Irradiance Environment Maps Ravi Ramamoorthi Pat Hanrahan Stanford University.
IMGD 1001: Illumination by Mark Claypool
(conventional Cartesian reference system)
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
Precomputed Radiance Transfer Harrison McKenzie Chapter.
1 Computer Science 631 Lecture 4: Wavelets Ramin Zabih Computer Science Department CORNELL UNIVERSITY.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CIS 310: Visual Programming, Spring 2006 Western State College 310: Visual Programming Ray Tracing.
SET09115 Intro Graphics Programming
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CS 450: COMPUTER GRAPHICS QUATERNIONS SPRING 2015 DR. MICHAEL J. REALE.
Efficient Irradiance Normal Mapping Ralf Habel, Michael Wimmer Institute of Computer Graphics and Algorithms Vienna University of Technology.
Jonathan M Chye Technical Supervisor : Mr Matthew Bett 2010.
TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain 
CS447/ Realistic Rendering -- Radiosity Methods-- Introduction to 2D and 3D Computer Graphics.
Real-Time Rendering Digital Image Synthesis Yung-Yu Chuang 01/03/2006 with slides by Ravi Ramamoorthi and Robin Green.
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
An Efficient Representation for Irradiance Environment Maps Ravi Ramamoorthi Pat Hanrahan Stanford University SIGGRAPH 2001 Stanford University SIGGRAPH.
Real-Time Relighting Digital Image Synthesis Yung-Yu Chuang 1/10/2008 with slides by Ravi Ramamoorthi, Robin Green and Milos Hasan.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
View-Dependent Precomputed Light Transport Using Nonlinear Gaussian Function Approximations Paul Green 1 Jan Kautz 1 Wojciech Matusik 2 Frédo Durand 1.
CSE 381 – Advanced Game Programming GLSL Lighting.
All-Frequency Shadows Using Non-linear Wavelet Lighting Approximation Ren Ng Stanford Ravi Ramamoorthi Columbia SIGGRAPH 2003 Pat Hanrahan Stanford.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Bitmap and Vector Graphics Bitmap Graphics Pictures are made up of little dots called pixels The colour of each dot is saved –Examples: Binary code representing.
Fast Approximation to Spherical Harmonics Rotation Sumanta Pattanaik University of Central Florida Kadi Bouatouch IRISA / INRIA Rennes Jaroslav Křivánek.
Fast Approximation to Spherical Harmonics Rotation
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
SIGGRAPH 2010 Course: Physically Based Shading Models in Film and Game Production SIGGRAPH 2010 Physically Based Shading Models in Film and Game Production.
Local Illumination and Shading
Advances in Real-Time Rendering in Games. Dynamic lighting in GOW3.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Non-Linear Kernel-Based Precomputed Light Transport Paul Green MIT Jan Kautz MIT Wojciech Matusik MIT Frédo Durand MIT Henrik Wann Jensen UCSD.
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
All-Frequency Shadows Using Non-linear Wavelet Lighting Approximation Ren Ng Stanford Ravi Ramamoorthi Columbia Pat Hanrahan Stanford.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
© University of Wisconsin, CS559 Spring 2004
Photorealistic Rendering vs. Interactive 3D Graphics
Real-time environment map lighting
3D Graphics Rendering PPT By Ricardo Veguilla.
CSC461: Lecture 23 Shading Computation
UMBC Graphics for Games
CS5500 Computer Graphics May 29, 2006
Last Time Presentation of your game and idea Environment mapping
Computer Graphics Material Colours and Lighting
Computer Graphics (Fall 2003)
Presentation transcript:

Spherical Harmonics in Actual Games Tom Forsyth Muckyfoot Productions Ltd tomf@muckyfoot.com

What they are… Representation of an image over a sphere Something like a cube-map Not like a cube-map: Frequency-space representation Spherical equivalent of post-Fourier-transform data A bit like a JPEG, but a 2D sphere, not a 2D plane Continuous, rotationally invariant No sharp edges, no rotational “lumpiness” Easy for vector units to manipulate

What they are not… Not an algorithm Not Precomputed Radiance Transform Just a data representation Not Precomputed Radiance Transform That is an algorithm that happens to use SHs Not actually that complex Just the maths language barrier Read the Ramamoorthi & Hanrahan paper – it makes sense eventually!

The Basics “Looking up a direction in the cube-map” A set of N basis functions – used by all SHs Components of the direction being looked up 1, X, Y, Z, XY, YZ, ZX, X2-Y2, 1-3Z2,… A set of N weights – this stores the data Each weight is usually an RGB colour Multiply each basis function by its weight And sum – result is the looked-up value Number of basis functions goes on for ever, but first 9 is good enough for diffuse lighting Weights are the equivalent of “pixels” – they store the actual image data, but they’re in frequency space.

Features of Harmonics Smooth over the sphere No seams or “hot spots” Easy to reconstruct in vector unit Rotation loses no data, has no aliasing Rotate then convert to SH is identical to convert to SH then rotate Basis functions used are orthonormal To add two SHs, add their weights To multiply two SHs, multiply their weights Explain verbally what “orthonormal” means –integral of any two different basis functions is 0 (“orthogonal”), integral of any basis function squared is 1 (“normal”) , which means during calculations lots of scary maths falls out to 0 or 1 and means that the add and mul Just Works.

Irradiance Concept Ignore SH for now – think of cubemaps Representing incoming distant lights Representing the diffuse cosine response Cosine response = max(0,N.L), summed for all lights Only normals matter, not positions Draw response to single light on cubemap The “picture” of a lit sphere Add together each light’s cubemap To shade any object, look up normal on the resulting cubemap

Irradiance Concept Get some better art! 

Irradiance Concept

Irradiance Concept

Using SH Final cubemap is smooth, low frequency Encode as SH weights Feed weights to vertex unit Vertex unit shades normals with SH 9 RGB values to feed to vertex unit rather than a cubemap 9 weights represents diffuse shading with maximum 6% error Works on hardware without cubemaps, and is faster even on hardware that does.

Using SH Better But wait! Why use a cubemap at all? Go from light description to SH weights Adding two SHs = add weights together So: For each light, find the SH weights Sum weights Feed final weights to vertex unit No cubemaps anywhere!

CPU Code per Object per Light void AddLightToSH ( Colour *sharm, Colour &colour, Vector &dirn ) { sharm[0] += colour * fConst1; sharm[1] += colour * fConst2 * dirn.x; sharm[2] += colour * fConst2 * dirn.y; sharm[3] += colour * fConst2 * dirn.z; sharm[4] += colour * fConst3 * (dirn.x * dirn.z); sharm[5] += colour * fConst3 * (dirn.z * dirn.y); sharm[6] += colour * fConst3 * (dirn.y * dirn.x); sharm[7] += colour * fConst4 * (3.0f * dirn.z * dirn.z - 1.0f); sharm[8] += colour * fConst5 * (dirn.x * dirn.x - dirn.y * dirn.y); }

Vertex Processor Code const Colour sharm[9]; Colour LightNormal ( Vector &dirn ) { Colour colour = sharm[0]; colour += sharm[1] * dirn.x; colour += sharm[2] * dirn.y; colour += sharm[3] * dirn.z; colour += sharm[4] * (dirn.x * dirn.z); colour += sharm[5] * (dirn.z * dirn.y); colour += sharm[6] * (dirn.y * dirn.x); colour += sharm[7] * (3.0f * dirn.z * dirn.z - 1.0f); colour += sharm[8] * (dirn.x * dirn.x - dirn.y * dirn.y); return colour; }

In Practice Find brightest n lights (n=1 to 3 usually) Shade those conventionally Specular, bumpmapped, self-shadowing, etc Rest of lights accumulated into SH Last real light fades between real and SH Provides smooth transition as object moves

Gotchas Only vertex diffuse lighting Only directional lights No bumpmaps (PS2.0 shaders can!) No specular, only diffuse So do brightest 2 lights normally Only directional lights Point lights must be approximated Discontinuities on abutting objects (walls, etc)

Cool Stuff Take (HDR) skybox, convert to SH offline Add to all computed SHs Perfect sunset lighting Artists can tweak by drawing on bitmaps! Presampled “radiosity” Pick some sample points in environment Render cubemaps at those points, convert to SH At runtime, for any object, linearly interpolate between nearest sample point SHs. Gives lighting off walls, through doorways, etc

Demo Compare many real lights to just 2 Too dark – lights are discarded. Compare many real lights to 2 + ambient Too washed out Compare many real lights to just SH Pretty good – slight differences Compare many lights to 2 real + SH Excellent, plus bumpmapping works

Questions

Conclusions SH is excellent for images on a sphere SH irradiance makes lights cheap Standard lighting has per-vertex cost Using SHs converts it to a per-object cost Per-vertex cost is constant Artists can put down far more lights And the game is still faster! (10-20% on PS2)

References Ramamoorthi & Hanrahan Peter-Pike Sloan Robin Green “An Efficient Representation for Irradiance Environment Maps” Peter-Pike Sloan Siggraph 2002 & 2003 papers Robin Green “Spherical Harmonic Lighting: The Gritty Details” Google for “spherical harmonic irradiance” Without “irradiance” you get lots of chemists