PRT Equations
Microsoft DirectX 9.0 SDK Update (October 2004)

PRT Equations


To fully understand a shader that implements precomputed radiance transfer (PRT), it is useful to derive the formula the shader uses to calculate exit radiance.

To start off, the general equation to calculate exit radiance resulting from direct lighting on a diffuse object with arbitrary distant lighting is:

where:

ParameterDescription
RpThe exit radiance at vertex p. Evaluated at every vertex on the mesh.
pdThe albedo of the surface.
piA constant, used as an energy conservation normalization factor.
L(s)The lighting environment (source radiance).
Vp(s)A binary visibility function for point p. It is 1 if the point can see the light, 0 if not.
Hnp(s)The cosine term from Lambert's law. Equal to max((Nps), 0) where Np is the surface normal at point p.
sThe variable that integrates over the sphere.

Using spherical basis functions, such as spherical harmonics (SH), the formula to approximate the lighting environment is:

where:

ParameterDescription
L(s) The lighting environment (source radiance).
iAn integer that sums over the number of basis functions.
OThe order of spherical harmonics.
liA coefficient.
Yi(s)Some basis function over the sphere.

The collection of these coefficients, L', provides the optimal approximation for function L(s) with the basis functions Y(s). Substituting and distributing yields:

The integral of Yi(s)Vp(s)Hnp(s) is a transfer coefficient tpi that the simulator precomputes for every vertex on the mesh. Substituting this yields:

Changing this to vector notation yields the uncompressed formula to calculate exit radiance for each channel:

where:

ParameterDescription
RpThe exit radiance at vertex p.
pdThe albedo of the surface.
L'The vector of li, and is the projection of the source radiance into the SH basis functions. This is an order2 vector of SH coefficients.
TpAn order2 transfer vector for vertex p. The simulator divides the transfer coefficients by p.

Both of these vectors are an order2 vector of SH coefficients, so notice that this is simply a dot product. Depending on the order, the dot can be expensive so compression can be used. An algorithm called Clustered Principal Component Analysis (CPCA) efficiently compresses the data. This enables the use of a higher-order SH approximation which results in sharper shadows.

CPCA provides this approximation for the transfer vector:

where:

ParameterDescription
TpThe transfer vector for vertex p.
MkThe mean for cluster k.
jAn integer that sums over the number of PCA vectors.
NThe number of PCA vectors.
wpjThe jth PCA weight for point p.
BkjThe jth PCA basis vector for cluster k.

A cluster is simply some number of vertices that share the same mean vector. How to get the cluster mean, the PCA weights, the PCA basis vectors, and the cluster identifiers (IDs) for the vertices is discussed below.

Substituting these two equations yields:

Then distributing the dot product yields:

Because both (MkL') and (BkjL') are constant per vertex, the sample calculates these values with the CPU and passes them as constants into the vertex shader; because wpj changes for each vertex, the sample stores this per-vertex data in the vertex buffer.



© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.