Latest  | Search | Go
Edit this page   |   Attach file 

  Home | Tutorials | Technical Reference | Runtime | API Documentation | SphericalHarmonics  

Precomputed Radiance Transfer & LightMapping

Primary Author: TimJohnson

Using Precomputed Radiance Transfer

There are several forms of complexity present in interesting scenes, including how the lighting environment is modeled (that is, area lighting models versus point/directional ones) and what kind of global effects are modeled (for example, shadows, interreflections, subsurface scattering.) Traditional interactive rendering techniques model a limited amount of this complexity. Precomputed radiance transfer (PRT) enables these effects with some significant restrictions:

  • Objects are assumed to be rigid (that is, no deformations).
  • It is an object-centric approach (unless objects are moved together, these global effects are not maintained between them).
  • Only low-frequency lighting is modeled (resulting in soft shadows.) For high-frequency lights (sharp shadows), traditional techniques would have to be employed.
  • Lights can move, objects can move, but objects influencing each other should not be split apart.

Basic Workflow

  1. Create scene geometry
  2. Set PRT material and quality settings like number of rays, number of bounces, and sub-surface scattering
  3. For each object, specify which other objects will be "blockers" and block incoming light (creating shadows)
  4. Calculate PRT data!

Quick Tutorial

tutorial-map.jpg
In the engine the shadows and subsurface scattering move in realtime with the lights

  1. Start with a box or a plane
  2. Add some other geometry on top of the plane to cast shadows
  3. Apply a shader material to all the items.
  4. Drop in a Directional type light
  5. Go to the Rendering tab in Reality Builder and setup the spherical harmonics properties for each mesh, one by one.
  6. Set the blocker list for each mesh. Unless objects cast on each other, don't add them as blockers. So the most important receiver in this scene is the plane you put all the items on -- it needs everything else in the scene to act as a blocker.
  7. Save your scene!
  8. Go to Build > Build All
  9. When the PRT is done compiling, move around your light to see some stunning real-time world shadowing!

Setting up per-pixel PRT

Per-pixel PRT requires a second mapping channel that follows certain rules regarding spacing and distortion. You can do this automatically in 3dsmax with the following steps.
  • Select your object, go to modifiers tab
  • Add "Unwrap UVW" Modifier
  • Change the "Map Channel" to 2, then click "Edit..."
  • Go to the Mapping Menu and Select "Flatten Mapping..."
  • Leave the defaults as they are, click OK, the new mapping will be generated, and you are done

Known bugs & Workarounds

Multi-selecting
Not so much a bug, but if you multi-select you are applying fresh data, erasing all old attributes for all selected meshes, so be sure this is what you want.

Can't reliably clone meshes with SH data on them (reference and group name will be lost).
This is only with the 3dsmax tools. Be prepared to reapply all data.

Baking Lightmaps

Reality supports per-pixel and per-vertex lightmapping. You can import an external lightmap or convert PRT data to lightmapped data to save memory or performance. To do this go to Modifiers->Bake PRT Lighting. The baked lighting data for PP prt is stored in 8 bit dds texture files in the map's folder, for baked PV prt the lighting data is stored in the mesh's buf file. One important caveat to remember is that if you want to bake a mesh that is using PV PRT then you must make sure that it's texture UVs are in the 0-1 range otherwise the baking process will cuase UVs outside of that range to be clipped thus distorting the look of the mesh.

Parameter Reference

Under main menu, go to Reality->Spherical Harmonics, or in Reality Builder go to "Rendering Tab", then select whichever mesh you wish to alter.

Uses Spherical Harmonics Lighting
Check this to use spherical harmonics on this mesh

Edit Indoor/Outdoor blockers...
Edits the list of meshes which cast shadows on this mesh. Important: To understand why you don't want every mesh in the scene to cast shadows on every other mesh, and what the difference between indoor and outdoor blockers are, please read http://www.ati.com/developer/gdc/Oat-GDC04-SphericalHarmonicLighting.pdf

Order of approximation
This controls the number of spherical harmonic basis functions used. The simulator generates order^2 coefficients per channel. Higher order allows for higher frequency lighting environments which allow for sharper shadows with the tradeoff of more coefficients per vertex that need to be processed by the vertex shader. For convex objects (no shadows), 3rd order has very little approximation error. For more detailed information, see "Spherical Harmonic Lighting: The Gritty Details" by Robin Green, GDC 2003 and "An Efficient Representation of Irradiance Environment Maps" by Ravi Ramamoorthi, and Pat Hanrahan, SIGGRAPH 2001.

Number of bounces
This controls the number of bounces simulated. If this is non-zero then inter-reflections are calculated. Inter-reflections are, for example, when a light shines on a red wall and bounces on a white wall. The white wall even though it contains no red in the material will reflect some red do to the bouncing of the light off the red wall."); break;

Number of rays
This controls the number of rays to shoot at each sample. The more rays the more accurate the final result will be, but it will increase time it takes to precompute the transfer coefficients.

Enable Subsurface Scattering
subsurface.jpg

If checked then subsurface scattering will be done in the simulator. Subsurface scattering is when light penetrates a translucent surface and comes out the other side. For example, a jade sculpture or a flashlight shining through skin exhibits subsurface scattering. The simulator assumes the mesh is made of a homogenous material. If subsurface scattering is not used, then the length scale, the relative index of refraction, the reduced scattering coefficients, and the absorption coefficients are not used.

Length Scale
When subsurface scattering is used the object is mapped to a cube of length scale mm per side. For example, if length scale is 10, then the object is mapped to a 10mm x 10mm x 10mm cube. The smaller the cube the more light penetrates the object.

3 color channels (spectral)
If checked then the simulator will process 3 channels: red, green, and blue and return order^2 spherical harmonic transfer coefficients for each of these channels in a single ID3DXBuffer* buffer. Otherwise it use values of only one channel (the red channel) and return the transfer coefficients for just that single channel. A single channel is useful for lighting environments that don't need to have the whole spectrum of light such as shadows.

Predefined Materials
These are some example materials. Choosing one of these materials with change the all the material values below. The parameters for these materials are from "A Practical Model for Subsurface Light Transport" by Henrik Wann Jensen, Steve R. Marschner, Marc Levoy, Pat Hanrahan, SIGGRAPH 2001. The relative index of refraction is with respect the material immersed in air.

Relative index of refraction
Relative index of refraction is the ratio between two absolute indexes of refraction. An index of refraction is ratio of the sine of the angle of incidence to the sine of the angle of refraction.

Reduced Scattering
The reduced scattering coefficient is a parameter to the volume rendering equation used to model light propagation in a participating medium. For more detail, see "A Practical Model for Subsurface Light Transport" by Henrik Wann Jensen, Steve R. Marschner, Marc Levoy, Pat Hanrahan, SIGGRAPH 2001".

Absorption
The absorption coefficient is a parameter to the volume rendering equation used to model light propagation in a participating medium. For more detail, see "A Practical Model for Subsurface Light Transport" by Henrik Wann Jensen, Steve R. Marschner, Marc Levoy, Pat Hanrahan, SIGGRAPH 2001".

Reflectance
The diffuse reflectance coefficient is the fraction of diffuse light reflected back. This value is typically between 0 and 1.

Adaptive Settings

Robust Mesh Refine
Subdivides faces on a mesh, allowing for conservative adaptive sampling that will not eliminate features on the mesh.

Min Edge Length
Minimum face edge length that will be generated in adaptive sampling. If zero, a reasonable default value will be substituted.

Max Subdivision Level
Maximum level of subdivision of a face that will be used in adaptive sampling. If zero, a default value of 5 will be substituted.

Adaptive Direct Lighting
This generates new vertices and faces on the mesh to more accurately approximate the precomputed radiance transfer signal from direct lighting.

Subdivision Threshold
Threshold on the PRT vector to use for subdividing mesh vertices and faces.

Min Edge Length
Minimum face edge length that will be generated in adaptive sampling. If the method determines that the value is too small, a model-dependent value is specified. If zero, a default value of 4 is specified.

Max Subdivision Level
Maximum level of subdivision of a face that will be used in adaptive sampling.

Adaptive Bounce
This generates new vertices and faces on the mesh to more accurately approximate the precomputed radiance transfer signal from bounces of interreflected light. This will be run for every bounce of light performed.

Subdivision Threshold
Threshold on the PRT vector to use for subdividing mesh vertices and faces.

Min Edge Length
Minimum face edge length that will be generated in adaptive sampling. If the method determines that the value is too small, a model-dependent value is specified. If zero, a default value of 4 is specified.

Max Subdivision Level
Maximum level of subdivision of a face that will be used in adaptive sampling.

Saving and compiling (3ds max)

Once you are done constructing your scene in Max you must move into Reality Builder in order to calculate your PRT data. Save out your scene as described in MaxToolsPlugin and open it in Reality Builder. Go to Build > Build All.

References

Interested in learning more? Great Spherical Harmonics / Precomputed Radiance Transfer references:

http://research.microsoft.com/~ppsloan/

http://home.comcast.net/~tom_forsyth/SH_GDCE_TomF.zip

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Summer_04/directx/graphics/programmingguide/advancedtopics/PRT/PRT.asp

SphericalHarmonics   Edit | Attach | Ref-By | Printable | Diffs | r1.16 | > | r1.15 | > | r1.14 | More