From my understanding, spherical harmonics are sometimes used to approximate certain aspects of lighting (depending on the application).

For example, it seems like you can approximate the diffuse lighting cause by a directional light source on a surface point, or parts of it, by calculating the SH coefficients for all bands you're using (for whatever accuracy you desire) in the direction of the surface normal and scaling it with whatever you need to scale it with (e.g. light colored intensity, dot(n,l),etc.).

What I don't understand yet is what this is supposed to accomplish. What are the actual advantages of doing it this way as opposed to evaluating the diffuse BRDF the normal way. Do you save calculations somewhere? Is there some additional information contained in the SH representation that you can't get out of the scalar results of the normal evaluation?

  • \$\begingroup\$ if you think there is anything you don't like with answer maybe I can elaborate? \$\endgroup\$ – concept3d Nov 4 '13 at 1:49

The reason to use spherical harmonics is to approximate the incoming light distribution around a point—typically indirect light calculated by some global illumination algorithm. Then the BRDF is also approximated with spherical harmonics, to allow efficiently calculating the outgoing light seen by the viewer, by taking the dot product of the incoming light SH coefficients with the BRDF SH coefficients. This approximates the convolution of incoming light with the BRDF, as seen in the rendering equation.

If you only care to receive light from point-sources, you have no need for SH. Point lights are more accurately handled by just evaluating the BRDF directly. Also, if you have a fixed environment (sky etc.) that you want to receive light from, you can generate pre-convolved cubemaps offline (using CubeMapGen for instance) that do a pretty good job of approximating the convolution of the environment map with the BRDF. No need for SH here either.

Where SH really comes in handy is when you have a complex scene and you want indirect lighting, i.e. bounce lighting. In this case the light distribution varies from place to place. In principle, each individual point in the scene has a different lighting environment based on its surroundings. In practice we sample the lighting at discrete points using some global illumination algorithm. There are many ways to do it - you could sample lighting at each vertex of the surfaces, for instance, or at each texel of a lightmap. Or create a volumetric representation using a grid, or a tetrahedral mesh.

The point is, there are a large number of points where lighting is sampled, and so we need a flexible but very compact representation of the lighting around a point, to avoid consuming too much memory. SH fills this role nicely. It also has the handy property that it works well with interpolation, i.e. the SH coefficients can be interpolated from one sample point to another and the lighting in between will behave reasonably. And since it captures the overall angular distribution of incoming light, not just the light from one direction, you can use it with a normal-mapped surface and get pretty good results.

It should be noted, though, that SH is really only useful for diffuse lighting. Unless you use a truly insane number of SH coefficients, it will blur out the angular distribution of incoming light too much. For high-quality specular indirect lighting, something else is needed, such as parallax-corrected cubemaps and/or screen-space raytracing.

  • \$\begingroup\$ >The point is, there are a large number of points where lighting is sampled, and so we need a flexible but very compact representation of the lighting around a point, to avoid consuming too much memory. SH fills this role nicely < This is what's confusing me. It seems to me that you can represent the light around a point (this is irradiance, isn't it?) just as well with a normal intensity representation, and you need less memory for it as well since even just 2 band SH uses 4 coefficients per color whereas intensity is just 3 in total. \$\endgroup\$ – TravisG Nov 4 '13 at 4:52
  • \$\begingroup\$ Well, let's take a specific example: Are you by any chance familiar with the Light Propagation Volume algorithm used in Cryengine 3? I wonder why it isn't practical to represent the lighting in the LPV just as intensities. \$\endgroup\$ – TravisG Nov 4 '13 at 4:57
  • \$\begingroup\$ @TravisG It's not just a single RGB intensity value because different amounts of light come from different directions. The idea is to represent the angular distribution of incoming light, not just the light from one specific direction, or the average over all directions. Consider if you have a green light on the left and a red light on the right. A normal-mapped surface should reflect green where the normals point left, and red where they point right. A single RGB intensity can't represent this situation, but a 2- or 3-band SH basis can. \$\endgroup\$ – Nathan Reed Nov 4 '13 at 5:37
  • \$\begingroup\$ @TravisG Likewise with LPV, you need to keep track of the direction in which light is propagating. It doesn't just spread out in all directions (unless it's scattered by particles in the air or some such); it keeps going in the direction it was emitted. For instance, one node in the LPV could contain red light traveling to the right, and green light traveling to the left, at the same time. So each node needs to keep track of the angular distribution of light passing through it. \$\endgroup\$ – Nathan Reed Nov 4 '13 at 5:42

What I don't understand yet is what this is supposed to accomplish ?

Short answer, more accurate physical light calculations. (with respect to some light surface interaction characteristics).

Why not evaluate everything with the diffuse BRDF the normal way?

Unfortunately the problem lies within the definition of the normal way. The "normal" phong reflection model has been embraced long time ago by the real time rendering community from the beginning and has been the de facto standard because of it's simplicity that makes it appropriate for the use of real time rendering.

The problem though, real life light/material interaction is so complicated that it cannot be actually modeled by a single BRDF.

BRDFs are an abstraction of how the actual light interaction is supposed to happen. phong is just one many other, that has the advantage of simplicity.

But what are the actual advantages ?

In computer graphics there are different BRDFs that fall into two main categories:

  1. Based on physical theory.
  2. Designed to fit specific a class of surface type and are usually used in real time rendering.

Talking about the second category each BRDF tries to accomplish certain characteristics with light surface interaction. The simplest possible BRDF is Lambertian which tries to model subsurface scattering and are often used in computer graphics, The constant reflectance value of a Lambertian BRDF is commonly refered to as the diffuse color.

In real time computer graphics usually BRDFs are manually selected and their parameters set to achieve a desired look (e.g. using Phong with certain values to model a plastic or a chrome surface).

On the other hand, sometimes BRDFs are measured directly from the desired surface (and are not represented by a math equation). This gives us much more physically accurate data about the surface that are otherwise hard to accomplish analytaclly.

One method to fit those captured data is to select an analytical BRDF and fit these data into it. Spherical Harmonics is just a technique used to represent those measured quantities, and fit them into an analytical BRDF model.

The best resource for BRDF theory can be found in real time rendering

  • 7.5 BRDF Theory.
  • On spherical harmonics revise 7.7.2 Representations for Measured BRDFs.
  • \$\begingroup\$ Thanks for the answer, but it's missing a bit what I'm looking for. As far as I understand, you can approximate any function f(x) using spherical harmonics, and for some reason people decide to approximate parts of a lighting model using spherical harmonics (what exactly depends on the application, but e.g. lambertian diffuse term is something that I've come across often). I wonder why that is, it seems to me that spherical harmonics is just a lossy representation that represents the same data but doesn't even have a memory advantage. \$\endgroup\$ – TravisG Nov 4 '13 at 3:02
  • \$\begingroup\$ Well, that depends what you compare it to. If you compare it to an analytic model, it's more involved and expensive. But the analytic model does not take the local environment in account. These days though I mostly see people using cube maps. They achieve similar results and have better hardware support. \$\endgroup\$ – drxzcl Nov 4 '13 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.